# Witchcraft.Ord(Witchcraft v1.0.4) View Source

`Ord` describes how to order elements of a data type.

This is a total order, so all elements are either `:equal`, `:greater`, or `:lesser` than each other.

## Type Class

An instance of `Witchcraft.Ord` must also implement `Witchcraft.Setoid`, and define `Witchcraft.Ord.compare/2`.

``````Setoid  [equivalent?/2]
↓
Ord    [compare/2]``````

# Link to this section Summary

## Functions

Determine if an element is `:lesser` or `:equal` to another.

Determine if an element is `:greater` or `:equal` to another.

Get the ordering relationship between two elements.

Determine if two elements are `:equal`.

Determine if an element is `:greater` than another.

Determine if an element is `:lesser` than another.

# ordering()

View Source

## Specs

`ordering() :: :lesser | :equal | :greater`

# t()

View Source

## Specs

`t() :: any()`

View Source

# a <= b

View Source

## Specs

`t() <= t() :: boolean()`

Determine if an element is `:lesser` or `:equal` to another.

## Examples

``````iex> use Witchcraft.Ord
...> 1 <= 2
true
...> [] <= [1, 2, 3]
false
...> [1] <= [1, 2, 3]
true
...> [4] <= [1, 2, 3]
false``````

View Source

# a >= b

View Source

## Specs

`t() >= t() :: boolean()`

Determine if an element is `:greater` or `:equal` to another.

## Examples

``````iex> use Witchcraft.Ord
...> 2 >= 1
true
...> [1, 2, 3] >= []
true
...> [1, 2, 3] >= [1]
true
...> [1, 2, 3] >= [4]
false``````

# compare(ord_a, ord_b)

View Source

## Specs

`compare(t(), t()) :: ordering()`

Get the ordering relationship between two elements.

Possible results are `:lesser`, `:equal`, and `:greater`

## Examples

``````iex> compare(1, 1)
:equal

iex> compare([1], [2])
:lesser

iex> compare([1, 2], [3])
:lesser

iex> compare([3, 2, 1], [1, 2, 3, 4, 5])
:greater``````

# equal?(a, b)

View Source

## Specs

`equal?(t(), t()) :: boolean()`

Determine if two elements are `:equal`.

## Examples

``````iex> equal?(1, 1.0)
true

iex> equal?(1, 2)
false``````

# greater?(a, b)

View Source

## Specs

`greater?(t(), t()) :: boolean()`

Determine if an element is `:greater` than another.

## Examples

``````iex> greater?(1, 1)
false

iex> greater?(1.1, 1)
true``````

# lesser?(a, b)

View Source

## Specs

`lesser?(t(), t()) :: boolean()`

Determine if an element is `:lesser` than another.

## Examples

``````iex> lesser?(1, 1)
false

iex> lesser?(1, 1.1)
true``````