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.

Link to this section Types

Specs

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

Specs

t() :: any()

Link to this section Functions

See Witchcraft.Ord.lesser?/2.

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

See Witchcraft.Ord.greater?/2.

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

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

Specs

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

Determine if two elements are :equal.

Examples

iex> equal?(1, 1.0)
true

iex> equal?(1, 2)
false

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

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