liveBook · Manning

Associativity

As explained in Clojure: The Essential Reference

Associativity is the property that the grouping of operands does not affect the result of repeatedly applying a binary operation.

Associativity determines whether a reducing operation can preserve its sequential meaning when work is split across parallel chunks. Operations whose grouping changes state or order are not safely parallelizable without redesigned semantics. section 7.1.2

Sequential versus chunked dropping

Dropping ten elements sequentially produces a stable sum: `(->> (vec (range 1600)) (partition 200) (mapcat #(drop 10 %)) (reduce +))` returns `1222840`. A stateful parallel drop can produce varying results such as `1279155` or `1271155`, because each chunk applies state independently.

In `clojure.core.reducers`, foldable transformations such as mapping, filtering, and concatenation can participate in parallel reduction, while operations such as `take`, `take-while`, and `drop` are marked non-foldable. section 7.1.2

How Clojure: The Essential Reference covers it

How deep it goes
Explains semantic failures through chunked dropping and marks several reducers as non-foldable, without developing a general algebraic definition.
Examples
Uses sequential and parallel dropping examples whose sums differ across repeated executions.
What it assumes
Assumes familiarity with reducers, transducers, collection reduction, and parallel folding.
What you can do after
Diagnose whether a stateful reducer preserves sequential semantics when executed through parallel folding.
How it connects
Connects associativity with reducers, transducers, parallelism, folding, and stateful reducers.

Also explained in

Compare how 5 books explain associativity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.