Java 8 streams reduce function tutorial

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Thank you! I had some problems understanding how reduce works

christianontiveros
Автор

More elegant way, actually, would be to use another reduce() method version, that takes in an identity, accumulator and combiner:
Integer sum = products
.stream()

.reduce(0,
(subSum, nextElem) -> subSum + nextElem.getQuantity(),
Integer::sum);
This way we can avoid pre-mapping phase, as our ProductInfo objects are mapped to quantities directly inside the reduce method.

mateosan
Автор

A lot of setup for very little explanation. You kind of explained it with itself.
Also: When explaining concepts, don't use "a" and "b" for variables, but use names that represent what they actually mean.

raiseer
Автор

at 2:32, why is the accumulator zero?

lisanneweidmann
visit shbcf.ru