Algae v1.2.3 Algae.Maybe 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 type
t()
View Source
t()
View Source
t() :: Algae.Maybe.Just.t() | Algae.Maybe.Nothing.t()
t() :: Algae.Maybe.Just.t() | Algae.Maybe.Nothing.t()
Link to this section Functions
Link to this function
from_maybe(arg1, arg2) View Source
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
Link to this function
from_nillable(value)
View Source
from_nillable(value)
View Source
from_nillable(any()) :: Algae.Maybe.Just.t()
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{}
Link to this function
new()
View Source
new()
View Source
new() :: t()
new() :: Algae.Maybe.Nothing.t()
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{}
Link to this function
new(value)
View Source
new(value)
View Source
new(any()) :: Algae.Maybe.Just.t()
new(any()) :: Algae.Maybe.Just.t()
Link to this function
new(nothing_value, arg2)
View Source
new(nothing_value, arg2)
View Source
new(any(), [{:nothing, any()}]) ::
Algae.Maybe.Just.t() | Algae.Maybe.Nothing.t()
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}