RichardWarburton/java-8-lambdas-exercises — pull request #4 by algirdasrascius (2014-09-29 08:38:57+00:00)
Title: Fix answers to advanced exercises of chapter 3

Advanced exercises of chapter 3 asks to use Stream.reduce to implement versions of map and filter methods. Provided answers mutate intermediate lists in accumulator and combiner functions. Mutating arguments in accumulator and combiner functions is not allowed by contract of Stream.reduce method. Doing so results in incorrect behaviour when used with parallel streams.

New implementations of MapUsingReduce and FilterUsingReduce copies argument lists in accumulator and combiner functions. This is very inefficient. Stream.collect method could be used to implement more efficient
mutable reduction, but exercises asks to use reduce method explicitly.

Corresponding unit tests were updated to check functionality of MapUsingReduce and FilterUsingReduce with parallel streams.