Std.Comparable
View source →use Std.Bool supplies `not` for the derived `<=`/`>=`;
use Std.Equatable provides the Equatable(t) superinterface required by
Comparable(t).
Types
-
type Ordering = LessThan | EqualTo | GreaterThanTotal-ordering interface on a minimal basis.
The sole primitive obligation is
`<`;`<=`,`>`,`>=`and the three-waycompare(returning anOrdering) are derivedrequires Comparable(t)top-level functions, each expressed with`<`alone (a total order is trichotomous in`<`).Comparable(t)requiresEquatable(t), so every comparable type is also equatable.The derived operations are standalone
requires-constrained functions rather than interface defaults: an instance-specialised default re-dispatching a sibling method at a concrete operand cannot be elaborated for every leaf today, whereas arequires-constrained function stays polymorphic and is resolved per call site (the same idiomStd.Equatable.`!=`uses).Examples
use Std.Comparable compare(1, 2) # => LessThan `<`('a', 'b') # => true `<`("ada", "grace") # => trueGroup tag consumed by
Cure.Stdlib.Preload. Three-way ordering result.
Functions
-
# fn <=(a: t, b: t) -> Bool
`<=`derived:a <= biffnot (b < a). -
# fn >(a: t, b: t) -> Bool
`>`derived by flipping the operands:a > biffb < a. -
# fn >=(a: t, b: t) -> Bool
`>=`derived:a >= biffnot (a < b). -
# fn clamp(value: t, lo: t, hi: t) -> t
Clamp
valueinto the inclusive range[lo, hi]. -
# fn compare(a: t, b: t) -> Ordering
Derived tripartite
compare, generated from`<`alone (trichotomy of a total order). Kept present and namedcomparesocompare_op_callandmin/max/clamp(which dispatch tocompare) keep working. -
# fn max(x: t, y: t) -> t
Pointwise maximum under the
Comparableordering. -
# fn min(x: t, y: t) -> t
Pointwise minimum under the
Comparableordering.