Why is there no function Stream.flatMap()? [closed

2019-01-25 19:51发布

问题:

Why is there no function Stream.flatMap() (without any parameters) to flatten a Stream<Stream<T>>?

It would simply be implemented as Stream.flatMap(o -> o).

In my opinion, this is by far the most common use of flatMap(Function mapper).

回答1:

I would imagine because it's trivial to use

import static java.util.function.Function.identity;
...  
streamOfStreams.flatMap(identity())