Algebraic law
An algebraic law is a general equation or behavioral property that an operation or implementation is expected to satisfy for applicable values.
Data-Oriented Programming in Java
An algebraic property is a characteristic describing how an operation behaves under operand order, grouping, and relationships between inputs and outputs.
- How it is used
- Defines correctness contracts for domain operations and turns them into tests over all relevant states.
- How deep it goes
- Explains universal assertions, associativity, commutativity, ordering, monotonicity, and exhaustive Java checks; defers no single required implementation.
- Examples
- Uses conflicting RawData merges, subtraction and floating-point addition, generated Optional states, cart invariants, and task lifecycle transitions.
- What you can do after
- Evaluate/understand operations by stating laws precisely and verifying invariants across generated states or external dependencies.
Read how Data-Oriented Programming in Java explains algebraic law →
Functional Programming in Scala, Second Edition
A law is a general equation or behavioral property that operations or their implementations are expected to satisfy.
- How it is used
- Constrain API operations and supply properties for reasoning, algebraic design, and property-based testing.
- How deep it goes
- Develops concrete mapping and flatMap equations, derives identity, and proves associativity for Option through case expansion.
- Examples
- Uses Par mapping, ExecutorService result comparison, Option cases, parser identities, and generated Order values.
- What you can do after
- Evaluate/understand whether alternative implementations preserve stated API behavior and derive reusable operations from lawful primitives.
Read how Functional Programming in Scala, Second Edition explains algebraic law →
Learn Haskell by Example
Property is the QuickCheck type representing a testable property, including properties augmented with conditions or classifications.
- How it is used
- Expresses implementation invariants as generated tests that search for counterexamples.
- How deep it goes
- Defines Bool and Property forms, demonstrates modifiers and shrinking, and defers custom Testable instances.
- Examples
- Uses sorted lists, rot13 symmetry, alphabet closure, and arithmetic properties in test suites.
- What you can do after
- Apply it via QuickCheck to run generated invariant checks and organize prop_-named tests into Stack suites.
Also covered in
What to know first
- parallelismParallelism is the execution of multiple independent tasks or computational operations at the same time rather than sequentially.
- stateState is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
- optionAn option type is a type that represents either a value of a specified type or its absence as distinct alternatives.
- listA list is an ordered collection of elements arranged in a sequence.
Related concepts
- flatmapused by · FlatMap is an operation that maps each element to a sequence or computational context and combines the resulting sequences or contexts into a flattened result.
- monadpart of · A monad is a programming abstraction that provides operations for sequencing computations while encapsulating and preserving their computational context.
- QuickCheckused by · QuickCheck is a property-based testing library, originally developed for Haskell, that generates test cases to check specified properties and can shrink failures to simpler counterexamples.
- property-based testingused by · Property-based testing is a software-testing technique that checks whether specified general properties hold across varied, often automatically generated, inputs.
Questions about algebraic law
What is algebraic law?
An algebraic law is a general equation or behavioral property that an operation or implementation is expected to satisfy for applicable values.
Which Manning books explain algebraic law?
Data-Oriented Programming in Java, Functional Programming in Scala, Second Edition and Learn Haskell by Example.
What should I know before learning algebraic law?
Manning books that teach algebraic law usually introduce parallelism, state, option and list first.
What is algebraic law part of?
Algebraic law is part of monad. A monad is a programming abstraction that provides operations for sequencing computations while encapsulating and preserving their computational context.
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.


