3 ms·
Comparators are not composed by ordinary function composition, but by pointwise composition in the domain. If you can read Haskell instance Monoid a => Mon
by alipang 10y ago
Comparators are not composed by ordinary function composition, but by pointwise composition in the domain. If you can read Haskell
instance Monoid a => Monoid (b -> a) where
f <> g = \x -> f x <> g x
Here they type a is the set `{ EQ, LESS, GREATER }` which is in turn composed in a left-biased way with `EQ` as an identity.
If you have two comparators, `lastNameComparator` and `firstNameComparator` and compose them into a comparator that compares first by firstName, then by lastName, surely that is a closed operation. It is also associative, and comparators do have an identity, so, yes they are also monoids.