September 2019
Intermediate to advanced
816 pages
18h 47m
English
sum(), max(), and min() are known as special cases of reduction. By reduction, we mean an abstraction based on two main statements:
Reductions can be accomplished via a terminal operation named reduce(), which follows this abstraction and defines two signatures (the second one doesn't use an initial value):
With that being said, we can rely on the reduce() terminal operation to compute the sum of the elements, as follows (the initial value is 0, and the lambda is (m1, m2) -> m1 + m2)):
int total = melons.stream() .map(Melon::getWeight) ...