I have the following code:
val xs = List(('a', 1), ('a', 2), ('b', 3), ('b', 4))
I want to convert this to a map. e.g. Map('a' -> Seq(1,2), 'b' -> Seq(3,4)) . Therefore, I move on to the transformation record:
xs.groupBy(_._1) map { case (k, v) => (k, v.map(_._2)) }
Why the bracket after the card should be { . When I started, I suggested that I could do the following:
xs.groupBy(_._1).map(case (k, v) => (k, v.map(_._2)))
But this does not compile.
andyczerwonka
source share