Algae v1.1.0 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

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

Link to this function from_maybe(arg1, arg2) View Source
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

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

Examples

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

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

Examples

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