Algae.Maybe (Algae v1.3.1) View Source

The sum of Algae.Maybe.Just and Algae.Maybe.Nothing. Maybe represents the presence or absence of something.

Please note that nil is actually a value, as it can be passed to functions! nil is not bottom!

Examples

iex> [1,2,3]
...> |> List.first()
...> |> case do
...>      nil  -> new()
...>      head -> new(head)
...>    end
%Algae.Maybe.Just{just: 1}

iex> []
...> |> List.first()
...> |> case do
...>      nil  -> new()
...>      head -> new(head)
...>    end
%Algae.Maybe.Nothing{}

Link to this section Summary

Functions

Extract a value from a Maybe, falling back to a set value in the Nothing case.

Alias for new(value, nothing: nil).

Put no value into the Maybe context (ie: make it a Nothing)

Put a value into the Maybe context (ie: make it a Just)

Link to this section Types

Link to this section Functions

Specs

from_maybe(t(), any()) :: any()

Extract a value from a Maybe, falling back to a set value in the Nothing case.

Examples

iex> from_maybe(%Algae.Maybe.Nothing{}, else: 42)
42

iex> %Algae.Maybe.Just{just: 1955} |> from_maybe(else: 42)
1955

Specs

from_nillable(any()) :: Algae.Maybe.Just.t()

Alias for new(value, nothing: nil).

Examples

iex> from_nillable(9)
%Algae.Maybe.Just{just: 9}

iex> from_nillable(nil)
%Algae.Maybe.Nothing{}

Specs

new() :: t()
new() :: Algae.Maybe.Nothing.t()

Put no value into the Maybe context (ie: make it a Nothing)

Examples

iex> new()
%Algae.Maybe.Nothing{}

Specs

new(any()) :: Algae.Maybe.Just.t()
Link to this function

new(nothing_value, arg2)

View Source

Specs

new(any(), [{:nothing, any()}]) ::
  Algae.Maybe.Just.t() | Algae.Maybe.Nothing.t()

Put a value into the Maybe context (ie: make it a Just)

Examples

iex> new(9)
%Algae.Maybe.Just{just: 9}

iex> new(nil)
%Algae.Maybe.Just{just: nil}

iex> new(nil, nothing: nil)
%Algae.Maybe.Nothing{}

iex> new(9, nothing: 9)
%Algae.Maybe.Nothing{}

iex> new(9, nothing: 1)
%Algae.Maybe.Just{just: 9}