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

  • less
  • equal
  • greater

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

compare[t] spec t equal

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

True iff !(a == b).

<[t] bool(a t, b t) bare, t compare

True iff (a <=> b) == less.

<=[t] bool(a t, b t) bare, t compare

True iff (a <=> b) != greater.

>[t] bool(a t, b t) bare, t compare

True iff (a <=> b) == greater.

>=[t] bool(a t, b t) bare, t compare

True iff (a <=> b) != less.

min[t] t(a t, b t) bare, t compare

Returns the lesser argument.

Returns b if they are equal.

max[t] t(a t, b t) bare, t compare

Returns the greater argument.

Returns b if they are equal.

compare-reverse[t] record nominal

  • inner t

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

<=>[t] comparison(a t compare-reverse, b t compare-reverse) bare, t compare