Alberto Ramón Alberto Ramón - 1 year ago 140
Scala Question

scala and groupby: value Unzip is not a member

val numbers = List(1,4,5,1,6,5,6)
numbers.groupBy(x=>x) // Run OK
numbers.groupBy(_) // ERROR

only by curiosity: somebody know why the second doesn't run ¿?

ERROR:Error:(8, 4) value Unzip is not a member of scala.collection.immutable.IndexedSeq[(Char, Int)]

Answer Source

The compiler interprets numbers.groupBy(_) as x => numbers.groupBy(x), which is clearly not what you intended. If you dislike the redundant x => x, you can use the predefined identity function:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download