Combining streams

Brian Goetz brian.goetz at oracle.com
Fri Jul 26 07:54:04 PDT 2013


1.  The former will be more efficient.  Especially in parallel.  Also the latter will fail if s1 is infinite even for ops like findFirst.  

2.  I would still probably prefer the concat.  

Sent from my iPad

On Jul 25, 2013, at 10:52 PM, Michael Hixson <michael.hixson at gmail.com> wrote:

> I have a couple of questions about combining streams.  Setting aside
> the question of which code is easier to read, I am wondering about
> things like performance or other hidden gotchas.
> 
> 1. To combine two streams, I should do this:
> 
> Stream.concat(s1, s2)
> 
> not this:
> 
> Stream.of(s1, s2).flatMap(x -> x)
> 
> ... right?
> 
> 2. To combine more than two streams, I should do this:
> 
> Stream.of(s1, s2, s3, ...).flatMap(x -> x)
> 
> not this:
> 
> Stream.of(s1, s2, s3, ...).reduce(Stream.empty(), Stream::concat)
> 
> ... right?
> 
> -Michael
> 


More information about the lambda-dev mailing list