向 FoldRight 传递额外参数
有没有办法将一些额外的参数传递给 Scala 的 List.foldRight 提供的函数?
一些示例代码:
def createActorPool[T](implicit actor: Manifest[T], poolSize: Int): List[Supervise] = {
(1 to poolSize).foldRight(List[Supervise]()) {
(idx, list) => { Supervise(actorOf[actor], Permanent) :: list }
}
}
我感兴趣的对象是actor,但是在用于构造Supervise 时它是不可见的。
PS:我对 Scala 还很陌生,所以如果这是一个常见问题解答,请接受我的歉意(尽管大量谷歌搜索没有任何适用的点击)。
Is there a way to pass some extra parameter to the function that is provided to Scala's List.foldRight?
Some example code:
def createActorPool[T](implicit actor: Manifest[T], poolSize: Int): List[Supervise] = {
(1 to poolSize).foldRight(List[Supervise]()) {
(idx, list) => { Supervise(actorOf[actor], Permanent) :: list }
}
}
The object I am interested in is actor
, which is however not visible when being used to construct Supervise.
P.S.: I'm pretty new to Scala, so please accept my apologies if this is a FAQ (despite extensive googling without any applicable hits).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的不明白你的问题。
传递给 FoldRight 的函数可以自由引用和使用范围内的任何其他内容。
这还不够吗?
I don't really get your problem.
The function passed to foldRight is free to reference and use anything else you have in scope.
Isn't that enough ?
在 Scala 中,字符
[
和]
仅用于类型。在您提供的代码示例中,actor
是一个对象,而不是类型。也许这会起作用:In Scala, the characters
[
and]
are only used for types. In the code sample you provided,actor
is an object, not a type. Perhaps this will work: