gt · gte · lt · lte
Data-first comparisons, as function values instead of operators.
Lecture
gt, gte, lt, and lte
are the four ordering operators packaged as data-first
functions: gt(a, b) == (a > b), with the first argument on
the left, exactly like the operator. That makes them drop-in comparators
wherever an API wants a function instead of an infix operator.
Under the hood they require both values to be mutually
Comparable and — with one exception — the exact same runtime
type: num vs num and String vs
String are allowed to mix (so int can compare
against double), but anything else with mismatched types
throws an ArgumentError rather than silently coercing.
None of the four are curried — there's no gt(5) partial
application. For a reusable unary predicate (say, for filter),
write a small closure that fixes one side:
(b) => gt(b, 5).
Demo 1 · Basics, and the type-mismatch error
Demo 2 · Currying into a filter predicate
Try it yourself
Exercise: keep only the ages that are gte 18 (adults).