Reputation: 23
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?
Upvotes: 2
Views: 243
Reputation: 26566
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:
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)
Upvotes: 1
Reputation: 6114
(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]
Upvotes: 6