I have a stream that I create like this:
StreamEx.generate(new MySupplier<List<Entity>>())
.flatMap(List::stream)
.map(Entity::getName)
.map(name -> ...)
.. // more stuff
I can change this to work in parallel by just adding parallel
:
StreamEx.generate(new MySupplier<List<Entity>>())
.flatMap(List::stream)
.map(Entity::getName)
.map(name -> ...)
.parallel()
.. // more stuff
But I also want to add a takeWhile
condition to make the stream stop:
StreamEx.generate(new MySupplier<List<Entity>>())
.takeWhile(not(List::isEmpty))
.flatMap(List::stream)
.map(Entity::getName)
.map(name -> ...)
.parallel()
.. // more stuff
But as soon as I add the takeWhile
the stream seems to become sequential (at least it's only processed by one thread). According to the javadoc of takeWhile
, if I understand it correctly, should work with parallel streams. Am I doing something wrong or is this according to design?