So, if we call flatMap on a List[A] , we get List[A] , and I will not see any point in type That , if it will always be displayed on List[B]
One thing you are missing is that flatMap is not really defined on List[+A] . It is inherited from TraversableLike , which is a feature used by most Scalas collections. Each of these can provide an implicit CanBuildFrom , which can be overridden to provide a different resulting collection.
If you need a little taste of what you can do with a custom CanBuildFrom :
scala> :pa // Entering paste mode (ctrl-D to finish) import scala.collection.generic.CanBuildFrom import scala.collection.immutable._ import scala.collection.mutable import scala.{List, Vector} implicit val listToVectorCBF = new CanBuildFrom[List[Int], Int, Vector[Int]] { override def apply(from: List[Int]): mutable.Builder[Int, Vector[Int]] = this.apply() override def apply(): mutable.Builder[Int, Vector[Int]] = Vector.newBuilder } // Exiting paste mode, now interpreting. scala> List(1,2,3).flatMap(List(_)) res6: Vector[Int] = Vector(1, 2, 3)
source share