Hawk66 Hawk66 - 7 months ago 53
Scala Question

What type is expeced for (elems: (A, B)*) in GenMapFactory

The GenMapFactory class has an apply function, with the following signature

def apply[A, B](elems: (A, B)*): CC[A, B] = (newBuilder[A, B] ++= elems).result()

What kind of collection I'm supposed to use here ? I thought I could just use a sequence but that does not seem to work


The * indicates a variable length argument list (also known as varargs).

In the case of a Map you would use it like this:

val newMap: Map[A, B] = Map((a0, b0), (a1, b1), (a2, b2))

There is also a neater way to express the (key, value) syntax, like this:

val newMap: Map[A, B] = Map(a0 -> b0, a1 -> b1, a2 -> b2)