crow/compare.crow (source)
Functions for comparison.
If you want a type to be comparable, just define == and <=>.
Use the signatures defined in the compare spec.
Other functions like != are defined here, derived from those.
comparison enum
lessequalgreater
Result of comparison.
If a <=> b is equal, then any function on a should return ths same result as a on b.
equal[t] spec
==bool(at,bt)
compare[t] spec t equal
equal<=>comparison(at,bt)
When defined for mutable values, this should compare their content without regard to mutablility;
so it may consider values equal that may not be equal in the future.
- comparison(a comparison) bare
Opposite comparison
!=[t] bool(a t, b t) bare, t equal
equalTrue iff !(a == b).
<[t] bool(a t, b t) bare, t compare
compareTrue iff (a <=> b) == less.
<=[t] bool(a t, b t) bare, t compare
compareTrue iff (a <=> b) != greater.
>[t] bool(a t, b t) bare, t compare
compareTrue iff (a <=> b) == greater.
>=[t] bool(a t, b t) bare, t compare
compareTrue iff (a <=> b) != less.
min[t] t(a t, b t) bare, t compare
compareReturns the lesser argument.
Returns b if they are equal.
max[t] t(a t, b t) bare, t compare
compareReturns the greater argument.
Returns b if they are equal.
compare-reverse[t] record nominal
innert
Wraps a value and reverses comparison (so less becomes greater and vice versa)
==[t] bool(a t compare-reverse, b t compare-reverse) bare, t equal
equal<=>[t] comparison(a t compare-reverse, b t compare-reverse) bare, t compare
compare