liveBook · Manning

Accumulator

An accumulator is a value, storage location, or combining function that carries or updates an intermediate result as inputs are processed.

How 4 Manning books explain it

Clojure: The Essential Reference

An accumulator is the value representing the result of a reduction after processing some prefix of the input.

How it is used
Carries partial results through Clojure reductions.
How deep it goes
Defines the accumulator and explains update order, initial values, and empty-input behavior.
Examples
Shows running sums of squares, word counts, and a running average with a vector accumulator.
What you can do after
Apply it via Clojure reduce and reductions to compute final or running results.

Read how Clojure: The Essential Reference explains accumulator →

100 Java Mistakes and How to Avoid Them

An accumulator function combines two values during a reduction operation to produce another value.

How it is used
Validates reduction functions used with Java Stream API operations.
How deep it goes
Explains associativity, identity, sequential behavior, and parallel failure, but stops short of general reduction implementation details.
Examples
Uses List.hashCode and a Java reduce expression whose multiplication-based accumulator fails under parallel evaluation.
What you can do after
Evaluate reduction accumulators against identity and associativity requirements before using sequential or parallel streams.

Read how 100 Java Mistakes and How to Avoid Them explains accumulator →

Grokking Simplicity

A function passed to a reduction operation that combines the accumulated result with the current sequence element.

How it is used
Supports reduce operations that combine sequence elements into totals, strings, maps, or other accumulated results.
How deep it goes
Defines the two arguments, return rule, initialization, and iteration behavior, but does not descend into implementation internals beyond a loop.
Examples
Uses purchase counting, string concatenation, numeric sum and product, and minimum or maximum exercises.
What you can do after
Apply it via reduce to build accumulation functions with appropriate initial values.

Read how Grokking Simplicity explains accumulator →

The Well-Grounded Rubyist, Fourth Edition

An accumulator is a value carried across iterations and replaced by each iteration's calculated result.

How it is used
Carries iteration results forward when reducing a collection or collecting block results into a new array.
How deep it goes
Traces initialization, replacement, and final return in inject, then shows accumulator-array construction for map.
Examples
Uses a four-number sum and a name-uppercasing map, including a map block whose puts calls yield nil results.
What you can do after
Build it from scratch by accumulating block results in a my_map method, or apply it with inject to reduce values.

Read how The Well-Grounded Rubyist, Fourth Edition explains accumulator →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.