liveBook · Manning

Monotonicity

As explained in Data-Oriented Programming in Java

A monotonic function is a function that preserves the ordering of its inputs, mapping larger inputs to outputs that are not smaller.

Monotonicity describes a function that preserves ordering: larger inputs should produce outputs that are not smaller. In practical terms, operations keep “big” things big and “small” things small. section 7.12 section 7.7.2

Combining ordered domain values

Suppose AuditFinding and Policy values have an impact ordering. Combining two less-favorable inputs must not produce a more-favorable result than combining two greater inputs. Comparing enum values by ordinal rather than name can accidentally move results backward and violate monotonicity. section 7.7.2

How Data-Oriented Programming in Java covers it

How deep it goes
Derives the law, translates it into an exhaustive Java test, and implements it with Comparator and BinaryOperator.maxBy.
Examples
Uses AuditFinding and Policy combinations, enum-comparison bugs, Comparator tests, and BinaryOperator.maxBy refactorings.
What it assumes
Assumes ordered data and Comparator usage while emphasizing that the apparently complex law expresses a simple ordering guarantee.
What you can do after
Diagnose/debug ordering violations with exhaustive Java tests and implement monotonic combinations using Comparator.
How it connects
Connects monotonicity to ordering, Comparator, binary operations, and algebraic properties.

Also explained in

Compare how 2 books explain monotonicity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.