Seeing several threads about semantic comparison recently motivated me to release this project I’ve been working on:
Instead of the built-in comparison operator,
Enum.max/1… which are based on structural comparison and would happily compare/sort anything,
Cmp will make sure these types are compatible and compare them semantically:
iex> Cmp.gt?(~D[2020-03-02], ~D[2019-06-06]) true iex> Cmp.sort([~D[2019-01-01], ~D[2020-03-02], ~D[2019-06-06]]) [~D[2019-01-01], ~D[2019-06-06], ~D[2020-03-02]] iex> Cmp.lte?(2, "1") ** (Cmp.TypeError) Failed to compare incompatible types - left: 2, right: "1"
- Fast and well-optimized - the overhead should be quite small over built-in equivalents. See the
benchmarks/folder for more details.
- No need to require macros, plain functions
- Easily extensible through the
- Robust and well-tested (both unit and property-based)