Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy
Last active December 20, 2015 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeaholicguy/c4457e94d3db403df084 to your computer and use it in GitHub Desktop.
Save codeaholicguy/c4457e94d3db403df084 to your computer and use it in GitHub Desktop.
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