StreamBuilder

Brian Goetz brian.goetz at oracle.com
Fri Apr 12 14:22:22 PDT 2013


In the wake of taking away flatMap(FlatMapper), we had to provide a way 
for people to build streams by generation.  For object-valued streams, 
they could just use an ArrayList, but for primitive-valued streams, 
there's no easy buffering tool.  (Hopefully also we can make 
StreamBuffer more efficient that ArrayList (at least it doesn't have to 
copy elements on resize)).

What we've got now is:

interface StreamBuilder<T> extends Consumer<T> {
     Stream<T> build();
}

with nested specializations for OfInt, OfLong, OfDouble.

and factories in Streams to get one:

     static<T> StreamBuilder<T> builder();

Someone commented that it wasn't obvious that StreamBuilder is just a 
buffer, and the Stream class itself is a sort of builder for streams 
(you add stages one by one), so maybe a better name might be 
StreamBuffer?  And I guess the corresponding factories are 
Streams.makeBuffer()?  .newBuffer()?



More information about the lambda-libs-spec-observers mailing list