I remember while writing sql queries we used the sum operation along with the group by clause. In that case we used to consider sum as an aggregate operation, while in java sum is considered as a reduction. Why, the difference?
Campbell Ritchie wrote:Look in the Java™ Tutorials about that sort of question. That section defines what aggregate operations are, and describes filter() and forEach().
Let's look at how the terms "aggregate" and "reduction" are used in that tutorial:
Java Tutorial wrote:with a pipeline that consists of the aggregate operations filter, mapToInt, and average:
The JDK contains many terminal operations such as average that return one value by combining the contents of a stream. These operations are called reduction operations
So which one is average, aggregate or reduction? I think the confusion stems from thinking aggregate operations are separate from reduction operations. They're not; they're just two different ways of describing what operations do. They are not necessarily mutually exclusive.
Intermediate operations and terminal operations are mutually exclusive. The filter operation is an intermediate aggregate operation. It returns another stream. The forEach operation is a terminal aggregate operation. The average operation is a terminal aggregate operation because it processes elements from a stream. It's also a reduction operation because it returns a single value by combining the elements of the stream it processed.
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop