chris
chris

Reputation: 2513

Meaning of additional colon in Scala class parametrization

What does [A : Manifest : WireFormat] mean in the following code? It's from com.nicta.scoobi.TextInput (available on github). It doesn't seem to be any of the usual type bounds.

  def fromDelimitedTextFile[A : Manifest : WireFormat]
      (path: String, sep: String = "\t")
      (extractFn: PartialFunction[List[String], A])
    : DList[A] = {

    val lines = fromTextFile(path)
    lines.flatMap { line =>
      val fields = line.split(sep).toList
      if (extractFn.isDefinedAt(fields)) List(extractFn(fields)) else Nil
    }
  }

Where can I find more information about this topic?

Upvotes: 48

Views: 6652

Answers (1)

kiritsuku
kiritsuku

Reputation: 53358

This is called a context bound. They are syntactic sugar for an implicit parameter list:

def meth[A : ContextBound1 : ContextBoundN](a: A)

// ==>

def meth[A](a: A)(implicit evidence: ContextBound1[A], ContextBoundN[A])

If there are multiple context bounds from 1 to N, they are all translated into the same parameter list. See this question for a more detailed explanation about how they work and for what they are useful.

To find such symbols it is useful to read the StackOverflow Scala Tutorial.

Upvotes: 60

Related Questions