Suggestion: buffer(int size) as the bulk operation

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu Sep 13 03:45:58 PDT 2012


Hi,

Is there a merit for including semi-eager buffering stage in streams?
This will arguably help in some of the corner cases when the stream
generator, or even the ops have the temporal/spatial locality benefits.
Normally we can force users to have eager terminators to compute
everything at once. buffer() acts like a middle ground here, providing
the means to balance the laziness vs. locality benefits.

I.e.:

 list.stream().map(longOperation).buffer(10).iterator()

We have both the benefits of staying within lazy operations, and having
the opportunity to process the operations in bulk, without consuming all
the stream.

BTW, this suggestion really shines if we can then have limited push
traversal in the framework. That means, forEach which would dump not the
entire stream contents, but only the next $limit elements. In this
example we can then do limited forEach(10) pushes to buffer, and the let
buffer provide us "lazy" pulls, doing bulk forEach(10) each time it
drains out.

-Aleksey.


More information about the lambda-dev mailing list