Module

pooka/order

src/pooka/order.pooka

A 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.

Pooka
import pooka/order.{Order}

assert order.from_int(0) == Order.Equal

API reference

enum

Order

src/pooka/order.pooka:17
enum Order

The three possible comparison directions. Equal reverses to itself.

variant

Less

src/pooka/order.pooka:18
Order.Less
variant

Equal

src/pooka/order.pooka:19
Order.Equal
variant

Greater

src/pooka/order.pooka:20
Order.Greater
interface

Comparator

src/pooka/order.pooka:24
interface Comparator(a)

A comparison contract for values with an explicit ordering policy.

method

compare

src/pooka/order.pooka:26
compare(left: a, right: a) -> Order

Compare left to right and return Less, Equal or Greater.

function

reverse

src/pooka/order.pooka:36
reverse(value: Order) -> Order

Turn Less into Greater and Greater into Less. Equal stays where it is.

Pooka
import pooka/order.{Order}

assert order.reverse(Order.Less) == Order.Greater
function

from_int

src/pooka/order.pooka:51
from_int(value: Int) -> Order
INFERREDfn(Int) -> pooka/order.Order

Use only the sign: negative is Less, zero is Equal and positive is Greater.

Pooka
import pooka/order.{Order}

assert order.from_int(0) == Order.Equal