Scala List of tuples to flat list

Try:

val tt = List(("John","Paul"),("George","Ringo"))
tt.flatMap{ case (a,b) => List(a,b) }

This results in:

List(John, Paul, George, Ringo)


Well, you can always use flatMap as in:

list flatMap (x => List(x._1, x._2))

Although your question is a little vague.


Some of the options might be: concatenate:

list.map(t => t._1 + t._2)

one after the other interleaved (after your comment it seems you were asking for this):

list.flatMap(t => List(t._1, t._2))

split and append them:

list.map(_._1) ++ list.map(_._2)

Tags:

Scala