Do you remember themap
, from few SKBs ago ?
As a reminder,map
allows you to transform aList[A]
into aList[B]
.
What will happen ifB
is aList
as well ?
flatten
allows you to turn aList[List[A]]
into aList[A]
.
Try to experiment with othercontainerssuch asOption
we 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