Blocks :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
The Collector API, as initially specified, allows mutable reduction operations to be expressed in terms of three functions: - create new result container - incorporate one new data element into a result container - merge two result containers This is suitable for many summarization operations, such as simple reductions (e.g., sum, min, max), group-by, partition-by, etc. However, it is constraining that the intermediate type used for accumulation and the final result type must be the same; some problems, such as averaging, require a different internal type than final result type. (When averaging, a sensible intermediate representation is a holder for two mutable accumulators, sum and count, but the user almost always wants a double as the final result.) Additionally, it may be the case that there are invariants that the Collector would like to impose on its result (e.g., immutability, or tree balancing) that cannot be done efficiently by the accumulator.