Combining streams

Michael Hixson michael.hixson at gmail.com
Thu Jul 25 19:52:52 PDT 2013


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