Module
pooka/order
src/pooka/order.pookaA comparison needs three signposts, not an arbitrary magic number.
Represent Less, Equal and Greater, and define the Comparator interface used by object-based comparisons. from_int uses only the sign of its input.
import pooka/order.{Order}
assert order.from_int(0) == Order.Equal
API reference
enum Order
The three possible comparison directions. Equal reverses to itself.
Order.Less
Order.Equal
Order.Greater
interface Comparator(a)
A comparison contract for values with an explicit ordering policy.
compare(left: a, right: a) -> Order
Compare left to right and return Less, Equal or Greater.
reverse(value: Order) -> Order
INFERRED
fn(pooka/order.Order) -> pooka/order.OrderTurn Less into Greater and Greater into Less. Equal stays where it is.
import pooka/order.{Order}
assert order.reverse(Order.Less) == Order.Greater
from_int(value: Int) -> Order
INFERRED
fn(Int) -> pooka/order.OrderUse only the sign: negative is Less, zero is Equal and positive is Greater.
import pooka/order.{Order}
assert order.from_int(0) == Order.Equal