开发者

What exactly does this snippet do in scala?

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?


(A=>B) is Function1[A,B]

Those lines are strictly equivalent:

class ForwardingManager(nameServer: NameServer[Shard]) extends (Long => Shard)
class ForwardingManager(nameServer: NameServer[Shard]) extends Function1[Long,Shard]


This snippet defines class ForwardingManager that extends Function1[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 as Function1[Input, ParseResult[T]]. This concrete example is described also in Programming in Scala, 2nd Edition (section 33.6)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜