FunFunc v0.2.0 FunFunc.Nilable
Functions for Nilable valeu.
Link to this section Summary
Functions
Gets the first argument if it is not nil. Otherwise returns the default value
Gets the first argument if it is not nil. Otherwise returns the result of the function
Maps if the first argument is not nil. Otherwise returns nil
Maps the first argument if it is not nil. Otherwise returns the default value
Maps the first argument if it is not nil. Otherwise returns the result of the function
and
or
Link to this section Types
Link to this section Functions
Gets the first argument if it is not nil. Otherwise returns the default value.
Examples
iex> FunFunc.Nilable.get_or(1, 2)
1
iex> FunFunc.Nilable.get_or(nil, 2)
2
Gets the first argument if it is not nil. Otherwise returns the result of the function.
Examples
iex> FunFunc.Nilable.get_or_else(1, fn -> 2 end)
1
iex> FunFunc.Nilable.get_or_else(nil, fn -> 2 end)
2
Maps if the first argument is not nil. Otherwise returns nil.
Examples
iex> FunFunc.Nilable.map(1, &Integer.to_string/1)
"1"
iex> FunFunc.Nilable.map(nil, &Integer.to_string/1)
nil
Maps the first argument if it is not nil. Otherwise returns the default value.
Examples
iex> FunFunc.Nilable.maybe(1, &Integer.to_string/1, "default")
"1"
iex> FunFunc.Nilable.maybe(nil, &Integer.to_string/1, "default")
"default"
maybe_else(nilable(), (... -> any()), (... -> any())) :: any()
Maps the first argument if it is not nil. Otherwise returns the result of the function.
Examples
iex> FunFunc.Nilable.maybe_else(1, &Integer.to_string/1, fn -> "default" end)
"1"
iex> FunFunc.Nilable.maybe_else(nil, &Integer.to_string/1, fn -> "default" end)
"default"
and
If the first argument is nil
, nil
is returned. Otherwise, the second argument is returned.
Examples
iex> FunFunc.Nilable.nil_and(nil, 2)
nil
iex> FunFunc.Nilable.nil_and(1, nil)
nil
iex> FunFunc.Nilable.nil_and(1, 2)
2