这段代码在 scala 中到底做了什么?
我试图理解 twitter gizzard 示例 rowz,但我无法弄清楚这个小片段在 scala 中的作用:
package com.twitter.rowz
import com.twitter.gizzard.nameserver.{Forwarding, NameServer}
import com.twitter.gizzard.shards.ShardException
class ForwardingManager(nameServer: NameServer[Shard]) extends (Long => Shard) {
def apply(id: Long) = nameServer.findCurrentForwarding(0, id)
}
类到底扩展了什么?
I'm trying to understand the twitter gizzard example rowz, and I can't figure out what this little snippet does in scala:
package com.twitter.rowz
import com.twitter.gizzard.nameserver.{Forwarding, NameServer}
import com.twitter.gizzard.shards.ShardException
class ForwardingManager(nameServer: NameServer[Shard]) extends (Long => Shard) {
def apply(id: Long) = nameServer.findCurrentForwarding(0, id)
}
what exactly is the class extending?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(A=>B)
是Function1[A,B]
这些行是严格等效的:
(A=>B)
isFunction1[A,B]
Those lines are strictly equivalent:
此代码段定义了扩展
Function1[Long, Shard]
的类ForwardingManager
(Long => Shard
只是缩写形式)。作为另一个示例,您可以查看 Scala 库中的
Parser
类:https://github.com/scala/scala/blob/master/src/library/scala/util/parsing/combinator/Parsers.scala#L190< /a>
在这种情况下
(Input => ParseResult[T])
与Function1[Input, ParseResult[T]]
相同。 Programming in Scala, 2nd Edition(第 33.6 节)中也描述了这个具体示例This snippet defines class
ForwardingManager
that extendsFunction1[Long, Shard]
(Long => Shard
is just short form).As another example, you can look at
Parser
class from Scala library:https://github.com/scala/scala/blob/master/src/library/scala/util/parsing/combinator/Parsers.scala#L190
In ths case
(Input => ParseResult[T])
is the same asFunction1[Input, ParseResult[T]]
. This concrete example is described also in Programming in Scala, 2nd Edition (section 33.6)