I just looked at the List.flatMap
declaration and was kind of surprised by this.
final override def flatMap[B, That](f: A => GenTraversableOnce[B])
(implicit bf: CanBuildFrom[List[A], B, That]): That
Where object List
defines:
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, List[A]] =
ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
So, if we invoke flatMap
on a List
we will get the List
and I don't see any point in That
type if it will always be deduced to List[B]
(because of the implicit
).
implicit
can be overridden with a more local one, that builds to, let's say, aVector
, or explicitly passed as a parameter – LopearedThat
being a different type compared to the original collection – Byercollection.breakout
with flatMap or Map... that is one example of overriding this implicit. – Dulciana