Friday, May 10, 2013

Scala Lists Flatten

The flatten method on Scala lists is used to remove one level of nested structure. For example, if we have a list that contains two lists, we can flatten that structure and result in a single one-dimensional list. Here's an example.

val listOfLists = List(List(1, 3, 5), List(2, 4, 6))
listOfLists flatten    //   List(1, 3, 5, 2, 4, 6)


No comments:

Post a Comment