0
val numbers = scala.collection.parallel.mutable.ParTrieMap(
    (1 until 100) zip (1 until 100): _*
  ) map { case (k, v) => (k.toDouble, v.toDouble) }

For the above code I know that (1 until 100) zip (1 until 100) will return something like a Map, but what's the meaning of _* following it?

kiritsuku
  • 52,967
  • 18
  • 114
  • 136
Daniel Wu
  • 5,853
  • 12
  • 42
  • 93
  • 1
    here check this out: http://stackoverflow.com/questions/7938585/what-does-param-mean-in-scala – Gaurav Apr 27 '13 at 13:33
  • you can search SO for character n-grams: http://stackoverflow.com/search?q=scala+%22_%2A%22 – Gene T Apr 27 '13 at 22:21

2 Answers2

5

Programming in Scala Section 8.8 Repeated parameters has a quick explanation with an example: _* notation tells compiler to pass each element as its own argument to ParTrieMap

from section 8.8 : val arr = Array("What's", "up", "doc?") when you call

echo(arr: _*) 

it will print

What's
up
doc?

arr: _* is equivalent to type declaration that tells the compiler to treat "arr" as repeated parameter e.g. vararg

It's explained well on this post as well.

Vikas Pandya
  • 1,998
  • 1
  • 15
  • 32
3

By calling zip method on Range, you are making IndexedSeq structure with of type: IndexedSeq[(Int, Int)]. To pass your (Int, Int) tuples into ParTrieMap you have to make a type ascription( your : _* annotation), cause you can't pass Seq to ParTrieMap (there is no method with apply(seq: Seq[(A, B)]) signature defined in ParTrieMap companion object, but there is a apply(a: (A, B)*) method). Basically you extract all tuples from Seq and passing them into Map.

4lex1v
  • 21,367
  • 6
  • 52
  • 86