Hi all,
I studied the new collection classes and wondered if it is possible to
have the Stream.map and Stream.flatMethod methods to return custom
implemented non-strict collections.
The Stream.map/flatMap method does not use the implicit BuilderFactory.
If something other than a Stream is required as the result then the
TraversableLike.flatMap method is used. This method uses the implicit
BuilderFactory but processes the whole collection. Yet, this is suitable
for strict collections only!
Could the concept of the BuilderFactory be extended to usable for
non-strict collections too? Would it be possible to have the
BuilderFactory not only to create a builder but to build the result
collection completely. Then the builder factory would have a method:
buildCollection[t: Traversable, f: A => Traversable[B]
The default implementation could be taken from TraversableLike:
val b = bf(repr)
for (x <- t) b ++= f(x)
b.result
Now BuilderFactories of non-strict collections would have a chance to
return their non-strict collections. Now the former "BuilderFactory"
should better be named "CollectionBuilder".
Thanks for your attention,
--Stefan