如何解决如何解决“此Seq的迭代器已在使用中”?
此代码:
sub MAIN(Int $N = 128)
{
my @pascal = ((1,),{ (0,|@^a) Z+ (|@^a,0) } ... *);
my @top = @pascal[^$N];
say "Percentage of odd numbers in the first $N rows: ",(100 × @top».grep(* % 2).sum / @top.sum).fmt('%.12f%%');
}
给我一个错误:
The iterator of this Seq is already in use/consumed by another Seq
(you might solve this by adding .cache on usages of the Seq,or
by assigning the Seq into an array)
in sub MAIN at ./pascal1 line 8
in block <unit> at ./pascal1 line 1
任何想法如何解决?我曾尝试在多个地方添加.cache
,但是没有运气。
解决方法
作为序列一部分的块正在创建Seq。您应该能够像这样缓存它:
{ ( (0,|@^a) Z+ (|@^a,0) ).cache }
func signInGmail() {
let redirectURI = URL(string: gmail_kRedirectURI)!
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let config = GTMAppAuthFetcherAuthorization.configurationForGoogle()
let scopes = [OIDScopeOpenID,OIDScopeProfile,OIDScopeEmail,kGTLRAuthScopeGmailReadonly]
let request = OIDAuthorizationRequest.init(configuration: config,clientId: gmail_kClientID,scopes: scopes,redirectURL: redirectURI,responseType: OIDResponseTypeCode,additionalParameters: nil)
appDelegate.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request,presenting: self,callback: { (authState,error) in
//handleError
if let authState = authState {
let authorizer = GTMAppAuthFetcherAuthorization(authState: authState)
self.pickGmailLabels(authorizer: authorizer)
}
})
}
返回一个Z
当Seq
产生它的下一个值时,它会将前一个值丢弃。
因此,您通常只能从Seq
获取一次值。
您拥有的区块Seq
通过查看它生成的上一个{…}
来工作。所以有一个问题。您要么查看那些Seq
中的内容,要么Seq
运算符查看...
中的内容
问题是,您可能不希望Seq
的结果为Z
,而是希望它为Seq
。
毕竟,您需要使用List
...
从List
序列生成器开始。
(1,)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。