Alberto Ramón Alberto Ramón - 2 months ago 5x
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)]


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: