Scala List Flatten

Do you remember themap, from few SKBs ago ?

As a reminder,mapallows you to transform aList[A]into aList[B].

What will happen ifBis aListas well ?

flattenallows you to turn aList[List[A]]into aList[A].

Try to experiment with othercontainerssuch asOptionwe saw in the past.

What happen if you do

val a: Option[Int] = Some(12)

val aa: Option[Option[Int]] = a.map(x => Some(x))

val flattenA: Option[Int] = aa.flatten

Reveal more information and clues
Load Exercise