The f function passed in flatMap here:
Vector(Some(1), Some(2), Some(3), None).flatMap{ n => n }
It is a function of A => GenTraversableOnce[B] , as described in the implementation of flatMap :
def flatMap[B, That](f : scala.Function1[A, GenTraversableOnce[B]]) (implicit bf : CanBuildFrom[Repr, B, That]) : That = ???
The function implemented in your example n => n :
(n: Option[Int]) => n
Where A is Option[Int] and B is Int .
Because CanBuildFrom defined as trait CanBuildFrom[-From, -Elem, +To] :
From Repr , in which case VectorElem B , therefore Int
The result is flatMap , therefore, Vector[Int]
source share