flatMap() concept
Georgiy Rakov
georgiy.rakov at oracle.com
Wed Nov 14 09:11:03 PST 2012
Hello,
I have some concerns regarding current FlatMapper concept.
Let's consider stream *s* of strings: {"a3", "b1000"}. And FlatMapper
instance *fm* which returns following sequences on each item:
- on "a3" it returns integers 1, 2, 3;
- on "b1000" it returns integers 1, 2,...,1000;
Suppose we have following situations while iterating over elements using
iterator returned by *s.flatMap(fm).iterator()*.
1. We've iterated over first 3 items and then make *hasNext()* call and
quit iteration because we need no more elements.
In this case when *hasNext()* is called all 1000 elements would be
supplied to *sink* passed to *fm* though there no needs for it.
2. We've iterated over first 4 items and then quit iteration because we
need no more elements.
In this case computational and memory resources will be engaged for
handling 999 elements which we have no needs for.
It seems that all these are desired to be avoided.
I'd like to note that previous version of *flatMap* receiving *Mapper<T,
Iterable<U>>* would allow us to avoid such potential waste of resources.
Could you please give your comments.
Thanks,
Georgiy.
More information about the lambda-dev
mailing list