Witchcraft v1.0.0-beta Witchcraft.Ord 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

Link to this type ordering() View Source
ordering() :: :lesser | :equal | :greater

Link to this section Functions

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

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

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

Determine if two elements are :equal

Examples

iex> equal?(1, 1.0)
true

iex> equal?(1, 2)
false

Determine if an element is :greater than another

Examples

iex> greater?(1, 1)
false

iex> greater?(1.1, 1)
true

Determine if an element is :lesser than another

Examples

iex> lesser?(1, 1)
false

iex> lesser?(1, 1.1)
true