Try this
val input = Seq((1,0),(2,0),(2,0),(1,1),(1,1),(2,1))
input.groupBy(_._2).collect{
case e => e._2.map(_._1)
}
//res3: scala.collection.immutable.Iterable[Seq[Int]] = List(List(1, 1, 2), List(1, 2, 2))
0
solved How to group a Seq[Array[(Int, Int)]]) by the second value of array