Taken from https://gitter.im/scala/contributors?at=5c0981af80986419d54dd08d
Stefan Zeiger @szeiger:
I'll try to give a high-level explanation (with imprecise types):
In order to build something (like the result of 1.to(10).map(identity)
) you use a Builder[E, To]
to which you add elements of type E
and eventually get a result To
.
That way a single implementation of map
can build different result types.
In order to get such a Builder
you need a factory, i.e. a () => Builder[E, To]
.
We call this type CanBuild
and pass an implicit instance of it to map
.
You usually don't care who's doing the building (Range
in this case) but for the sake of finding an implicit CanBuild
you want the source collection to determine the result type To
(e.g. calling map
on a List should build another List
).