An algebraic operation combines values according to an explicit meaning. In code, start with a set of values—such as records, lists, maps, or rules—then define the operation that combines them. The operation belongs to an algebra when its behavior is constrained by laws, not merely by its implementation. section 7.2 section 7.4
For programming use, the useful shape is a deterministic function: data goes in, data comes out, with no side effects or void result. That makes it possible to reason with equations: replace one expression with another when both mean the same thing, then state what combining values must mean independently of loops, mutation, or API details. section 7.2 section 7.1
Properties turn an intended combination into something that can be checked for every valid input:
- Associativity asks whether regrouping preserves the result: a + (b + c) equals (a + b) + c. When it holds, reduction need not depend on one sequential grouping and can support parallel computation. section 7.12 section 7.4
- Commutativity asks whether argument order is irrelevant: a + b equals b + a. It should be claimed only when the domain meaning supports it. section 7.12 section 7.4
- Monotonicity asks whether an operation preserves an ordering of inputs; order itself may require reflexivity, antisymmetry, and transitivity. section 7.12
Merging duplicate records
A duplicate-cleaning routine can hide an operation inside an imperative loop: repeatedly merge one RawData record with the next. Naming that merge as add exposes a binary operation. The same move reveals list concatenation and map combination beneath grouping code, enabling map-and-reduce refactorings while keeping the domain rule—the meaning of a merged record—visible. section 7.3 section 7.2
An operation need not be numeric or even executed immediately. Rules can be represented as data, with Equals, And, Or, and Not forming a closed algebra under one sealed interface. Larger operations such as contains can then be built by repeatedly applying smaller binary operations, while the resulting data remains available for later interpretation or transformation. section 8.4 section 8.4.1 section 8.13
The point is not to force elegant laws onto a bad model. State the semantics first, test the laws that genuinely follow, and prefer clear data meanings over algebraic cleverness. Even a single operation can supply a compact vocabulary for discussing correctness and for recognizing reusable structure in ordinary Java code. section 7.12 section 4.6.3
Figure 7.10 Visualizing common methods as algebraic binary operations

Compare stateful collection updates with the underlying list and map combinations to practice spotting binary operations in routine control flow. section 7.3
