Category v0.1.0 Category.Data.Maybe View Source

Classic sum type Maybe Implements Monad, Functor and Applicative behaviours

Link to this section Summary

Functions

If argument is just(a) then returns a, otherwise returns nil

If argument is just(a) then returns a, otherwise raise exception

  • Accepts any term
  • Returns true if term is value of Category.Data.Maybe λ-type, otherwise returns false

If argument is just(a) then returns true If argument is nothing() then returns false Otherwise raise exception

If argument is nothing() then returns true If argument is just(a) then returns false Otherwise raise exception

First constructor

Second constructor

Link to this section Types

Link to this section Functions

Link to this function

get(it)

View Source
get(t(a())) :: a() | nil

If argument is just(a) then returns a, otherwise returns nil

Examples

iex> j = Maybe.just(1)
iex> n = Maybe.nothing()
iex> Maybe.get(j)
1
iex> Maybe.get(n)
nil
Link to this function

get!(it)

View Source
get!(t(a())) :: a() | no_return()

If argument is just(a) then returns a, otherwise raise exception

Examples

iex> j = Maybe.just(1)
iex> n = Maybe.nothing()
iex> Maybe.get!(j)
1
iex> Maybe.get!(n)
** (RuntimeError) Can't get! from Category.Data.Maybe.nothing
  • Accepts any term
  • Returns true if term is value of Category.Data.Maybe λ-type, otherwise returns false
Link to this function

is_just?(it)

View Source
is_just?(t(a())) :: boolean()

If argument is just(a) then returns true If argument is nothing() then returns false Otherwise raise exception

Examples

iex> j = Maybe.just(1)
iex> n = Maybe.nothing()
iex> Maybe.is_just?(j)
true
iex> Maybe.is_just?(n)
false
Link to this function

is_nothing?(it)

View Source
is_nothing?(t(a())) :: boolean()

If argument is nothing() then returns true If argument is just(a) then returns false Otherwise raise exception

Examples

iex> j = Maybe.just(1)
iex> n = Maybe.nothing()
iex> Maybe.is_nothing?(n)
true
iex> Maybe.is_nothing?(j)
false
Link to this function

just(x)

View Source
just(a()) :: t(a())

First constructor

Examples

iex> x = Maybe.just(1)
iex> Maybe.is_just?(x)
true
Link to this function

nothing()

View Source
nothing() :: t(a())

Second constructor

Examples

iex> x = Maybe.nothing()
iex> Maybe.is_nothing?(x)
true