View Source Funx.Ord protocol (funx v0.1.0)
The Funx.Ord
protocol defines a set of comparison functions: lt?/2
, le?/2
, gt?/2
, and ge?/2
.
This protocol is intended for types that can be ordered, allowing values to be compared for their relative positions in a total order.
By implementing this protocol, you can provide custom logic for how values of a certain type are compared.
Fallback
The protocol uses @fallback_to_any true
, which means if a specific type does not implement Funx.Ord
,
the default implementation for Any
will be used, which relies on Elixir's built-in comparison operators.
Summary
Functions
Returns true
if a
is greater than or equal to b
, otherwise returns false
.
Returns true
if a
is greater than b
, otherwise returns false
.
Returns true
if a
is less than or equal to b
, otherwise returns false
.
Returns true
if a
is less than b
, otherwise returns false
.
Types
@type t() :: term()
All the types that implement this protocol.
Functions
Returns true
if a
is greater than or equal to b
, otherwise returns false
.
Examples
iex> Funx.Ord.ge?(Funx.Monad.Maybe.just(5), Funx.Monad.Maybe.just(3))
true
iex> Funx.Ord.ge?(Funx.Monad.Maybe.just(5), Funx.Monad.Maybe.just(5))
true
iex> Funx.Ord.ge?(Funx.Monad.Maybe.just(3), Funx.Monad.Maybe.just(5))
false
Returns true
if a
is greater than b
, otherwise returns false
.
Examples
iex> Funx.Ord.gt?(Funx.Monad.Maybe.just(5), Funx.Monad.Maybe.just(3))
true
iex> Funx.Ord.gt?(Funx.Monad.Maybe.just(3), Funx.Monad.Maybe.just(5))
false
iex> Funx.Ord.gt?(Funx.Monad.Maybe.just(3), Funx.Monad.Maybe.nothing())
true
Returns true
if a
is less than or equal to b
, otherwise returns false
.
Examples
iex> Funx.Ord.le?(Funx.Monad.Maybe.just(3), Funx.Monad.Maybe.just(5))
true
iex> Funx.Ord.le?(Funx.Monad.Maybe.just(5), Funx.Monad.Maybe.just(5))
true
iex> Funx.Ord.le?(Funx.Monad.Maybe.just(5), Funx.Monad.Maybe.just(3))
false
Returns true
if a
is less than b
, otherwise returns false
.
Examples
iex> Funx.Ord.lt?(Funx.Monad.Maybe.just(3), Funx.Monad.Maybe.just(5))
true
iex> Funx.Ord.lt?(Funx.Monad.Maybe.just(5), Funx.Monad.Maybe.just(3))
false
iex> Funx.Ord.lt?(Funx.Monad.Maybe.nothing(), Funx.Monad.Maybe.just(3))
true