package com.insightfullogic.java8.answers.chapter3;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

public class FilterUsingReduce {

	public static <I, O> List<O> map(Stream<I> stream, Function<I, O> mapper) {
		return stream.reduce(new ArrayList<O>(), (acc, x) -> {
			
			List<O> newAcc = new ArrayList<>(acc);
			newAcc.add(mapper.apply(x));
			return newAcc;
			
		}, (List<O> left, List<O> right) -> {
			
			List<O> newLeft = new ArrayList<>(left);
			newLeft.addAll(right);
			return newLeft;
			
		});
	}
}

@@ -293,67 +293,276 @@
 %0D%0A%09%09
-return stream.reduce(new ArrayList%3CO%3E(), (acc, x) -%3E %7B%0D%0A%09%09%09
+%0D%0A%09%09// reduce%D0%B1:(List%3CO%3E identity, BiFunction%3CList%3CO%3E, ? super I, List%3CO%3E%3E accumulator, BinaryOperator%3CList%3CO%3E%3E combiner)%0D%0A%09%09return stream.reduce(new ArrayList%3CO%3E(), (acc, x) -%3E %7B%0D%0A%09%09%09// map%DC%B5Lambda%CA%BDFunction%D3%BF%DA%B5%D2%BB%CA%B5%0D%0A%09%09%09// %CB%B4%CD%A8Function%D3%BF%CA%B5%D6%B5%D7%AA,%EF%B5%BD%D0%A7%0D%0A%09%09%09// %C3%BF%D2%BB%CE%B2List%3CO%3EnewAcc%DD%B8combiner%D3%BF
 %0D%0A%09%09
@@ -700,19 +700,126 @@
 ) -%3E %7B%0D%0A
-
 %09%09%09
+// left%CE%AA%CF%B4%CE%BC%E3%B1%A3List%3CO%3E%CA%BC%D6%B5%CE%AAnew ArrayList%3CO%3E()%0D%0A%09%09%09// combiner%D3%BF%DA%BDaccumulator%D8%B5%D6%B5%C8%ABnewLeft%0D%0A%09%09%09// %D6%B1%D3%B5%D4%ADLambda,%D6%B2%DA%BC%C8%B3%CA%B5%CF%B1final%CD%B5
 %0D%0A%09%09%09Lis

add comment for question FilterUsingReduce in chapter3