Switching the stream from parallel() to sequential() worked in the initial Stream API design, but caused many problems and finally the implementation was changed, so it just turns the parallel flag on and off for the whole pipeline. The current documentation is indeed vague, but it was improved in Java-9:
The stream pipeline is executed sequentially or in parallel depending on the mode of the stream on which the terminal operation is invoked. The sequential or parallel mode of a stream can be determined with the BaseStream.isParallel() method, and the stream's mode can be modified with the BaseStream.sequential() and BaseStream.parallel() operations. The most recent sequential or parallel mode setting applies to the execution of the entire stream pipeline.
def sample = ['Groovy', 'Gradle', 'Grails', 'Spock'] as String[]
def result = sample.stream() // Use stream() on array objects
.filter { s -> s.startsWith('Gr') }
.map { s -> s.toUpperCase() }
.toList() // toList() added to Stream by Groovy
A. Shukla, T. Sharma, and Y. Simmhan. Workshop on Architectural Support and Middleware for InfoSymbiotics/ Dynamic Data Driven Applications Systems (DDDAS), co-located with High Performance Computing Conference (HiPC)
, page 61. (2015)Extended abstract.
K. Joseph, P. Landwehr, and K. Carley. Social Computing, Behavioral-Cultural Modeling and Prediction
, page 75--83. Cham, Springer International Publishing, (2014)