I have
val a = List((1,2), (1,3), (3,4), (3,5), (4,5))
I am using A.groupBy(_._1) which is groupBy with the first element. Bu
A.groupBy(_._1)
As from Scala 2.13 it would be possible to use groupMap so you'd be able to write just:
Scala 2.13
// val list = List((1, 2), (1, 3), (3, 4), (3, 5), (4, 5)) list.groupMap(_._1)(_._2) // Map(1 -> List(2, 3), 3 -> List(4, 5), 4 -> List(5))