package com.insightfullogic.java8.answers.chapter3;

public class FilterUsingReduce {

}

@@ -52,42 +52,562 @@
 %0D%0A%0D%0A
-public class FilterUsingReduce %7B%0D%0A
+import java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0Aimport java.util.function.Function;%0D%0Aimport java.util.stream.Stream;%0D%0A%0D%0Apublic class FilterUsingReduce %7B%0D%0A%0D%0A%09public static %3CI, O%3E List%3CO%3E map(Stream%3CI%3E stream, Function%3CI, O%3E mapper) %7B%0D%0A%09%09return stream.reduce(new ArrayList%3CO%3E(), (acc, x) -%3E %7B%0D%0A%09%09%09%0D%0A%09%09%09List%3CO%3E newAcc = new ArrayList%3C%3E(acc);%0D%0A%09%09%09newAcc.add(mapper.apply(x));%0D%0A%09%09%09return newAcc;%0D%0A%09%09%09%0D%0A%09%09%7D, (List%3CO%3E left, List%3CO%3E right) -%3E %7B%0D%0A%09%09%09%0D%0A%09%09%09List%3CO%3E newLeft = new ArrayList%3C%3E(left);%0D%0A%09%09%09newLeft.addAll(right);%0D%0A%09%09%09return newLeft;%0D%0A%09%09%09%0D%0A%09%09%7D);%0D%0A%09%7D
 %0D%0A%7D%0D

add answer FilterUsingReduce for chapter3