acca/ordering

Functions

compare(left: Ordering, right: Ordering) -> Ordering

Left biased resolution of comparing two orderings.

aordering.compare(Less, Greater) == Less
aordering.compare(Equal, Less) == Less
aordering.compare(Equal, Equal) == Equal
aordering.compare(Equal, Greather) == Greather
aordering.compare(Greather, Less) == Greather

compare_option(
  left: Option<Ordering>,
  right: Option<Ordering>,
) -> Option<Ordering>

Left biased resolution of comparing two orderings.

aordering.compare(Less, Greater) == Less
aordering.compare(Equal, Less) == Less
aordering.compare(Equal, Equal) == Equal
aordering.compare(Equal, Greather) == Greather
aordering.compare(Greather, Less) == Greather

compare_tuple(
  left: (a, b),
  right: (a, b),
  first_compare: fn(a, a) -> Ordering,
  second_compare: fn(b, b) -> Ordering,
) -> Ordering

Compares two tuples with a given compare functions for both left and right side of the tuple.

aordering.compare_tuple((1, 2), (1, 2)) == Equal
aordering.compare_tuple((0, 1), (1, 2)) == Less
aordering.compare_tuple((2, 1), (1, 2)) == Greater
aordering.compare_tuple((1, @"a"), (1, @"a")) == Equal
aordering.compare_tuple((1, @"a"), (1, @"b")) == Less

compare_tuple_left(
  left: (a, b),
  right: (a, b),
  first_compare: fn(a, a) -> Ordering,
) -> Ordering

Compares two tuples with a given compare functions for both left and right side of the tuple. This function will only look at left side of the tuple.

aordering.compare_tuple_left((1, 2), (1, 2)) == Equal
aordering.compare_tuple_left((0, 1), (1, 2)) == Less
aordering.compare_tuple_left((2, 1), (1, 2)) == Greater
aordering.compare_tuple_left((1, @"a"), (1, @"b")) == Equal

force_reduce(self: List<Ordering>) -> Ordering

Reduces a List into one single Ordering. Note that reduction is left biased and function returns Equal for an empty list.

aordering.force_reduce([]) == Equal
aordering.force_reduce([Less, Greater, Less]) == Less
aordering.force_reduce([Equal, Less, Greater]) == Less
aordering.force_reduce([Equal, Equal, Equal]) == Equal
aordering.force_reduce([Equal, Equal, Equal, Greater]) == Greater

reduce(self: List<Ordering>) -> Option<Ordering>

Reduces a List into one single Ordering. Note that reduction is left biased.

aordering.reduce([]) == None
aordering.reduce([Less, Greater, Less]) == Some(Less)
aordering.reduce([Equal, Less, Greater]) == Some(Less)
aordering.reduce([Equal, Equal, Equal]) == Some(Equal)
aordering.reduce([Equal, Equal, Equal, Greater]) == Some(Greater)

to_string(ord: Ordering) -> String

Serialises ordering to string

aordering.to_string(Less) == @"Less"
aordering.to_string(Equal) == @"Equal"
aordering.to_string(Greater) == @"Greater"
Search Document