Reputation: 105
I have a scala list
val x = List[(a,b), (c,d), (d,e)]
I want to convert above 2D list into 1D.
expected output val x = List(a,b,c,d,d,e)
I have tried using "x.flatten", but it didn't work.
How can I convert 2D list into 1D.
Upvotes: 2
Views: 541
Reputation: 51683
Do
List((a, b), (c, d), (d, e)).map { case (x, y) => List(x, y) }.flatten
or
List((a, b), (c, d), (d, e)).flatMap { case (x, y) => List(x, y) }
Upvotes: 1