Constructing parallel streams (original) (raw)

Paul Sandoz paul.sandoz at oracle.com
Tue Dec 11 08:34:55 PST 2012


On Dec 11, 2012, at 1:05 AM, Remi Forax <forax at univ-mlv.fr> wrote:

On 12/10/2012 05:01 PM, Joe Bowbeer wrote:

I can easily imagine a pipeline that has alternating sequential/parallel/sequential segments. Is there any reason to discourage a programmer from using the parallel/sequential methods to express this? You don't need a method sequential() or parallel() for that, you can use into. parallelStream.into(new ArrayList<>()).stream() is now sequential stream.into(new ArrayList<>()).parallel() is now parallel and into() offer a better control on the intermediary data structure.

That just results in unnecessary copying, the internal representation can be more optimal.

e.g.:

parStream.sequential().forEach(...)

compared to:

parStream.into(new ArrayList<>()).forEach(...)

Paul.



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