Do you remember the map
, from few SKBs ago ?
As a reminder, map
allows you to transform a List[A]
into a List[B]
.
What will happen if B
is a List
as well ?
flatten
allows you to turn a List[List[A]]
into a List[A]
.
Try to experiment with other containers such as Option
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