Monoids, Predicates and Sorting Functions!
summary
Live coding shows Swift protocols for Semigroup and Monoid with a concrete monoid identity and a generic can-cat fold, builds an endo monoid of functions (compose and identity), and lifts any Monoid to functions A -> M to make predicates and comparators monoids. An ordering monoid (LT EQ GT) plus a lens-to-comparator glue yields composable multi-key sorters that can be reversed and concatenated, demonstrated on a projects array, and claimed to be used in a real codebase.
AI-written summary · about
