Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy

codeaholicguy/reduce.java

Last active Dec 20, 2015
Embed
What would you like to do?
List<Integer> list1 = Arrays.asList(10, 10);
Stream<Integer> stream1 = list1.stream();
BinaryOperation<Integer> sum = (i1, i2) -> i1 + i2;
Integer id1 = 0;
Integer reduce1 = stream1.reduce(id1, sum);
Stream<Integer> stream2 = Stream.empty();
// result is 0
Integer reduce2 = stream2.reduce(id1, sum);
Integer id2 = 100;
// result is 120
Integer reduce3 = stream1.reduce(id2, sum);
Integer id3 = 0;
List<Integer> list2 = Arrays.asList(10);
// resut is 10
Integer reduce4 = list2.stream.reduce(id3, Integer::max);
Integer id4 = 0;
List<Integer> list3 = Arrays.asList(-10);
// resut is 0
Integer reduce5 = list3.stream.reduce(id4, Integer::max);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.