A question to highlight is:
Is there a way to make sure that a stream is NOT parallel, and make this evident in the code?
As in:
stream
.assertNotParallel()
.map(x -> foo(x))...
The idea would be to make it clear to the next developer who comes along what NOT to try and to raise a runtime exception because some lambdas may not take kindly to a parallel stream.
There is also a warning about this scenarioin in Chapter 12, page 206, in “Avoid side-effects in functional pipelines”. Not every pipeline should or may be able to be parallelized.