ex_maybe v1.0.0 ExMaybe

This library fills a bunch of important niches. A Maybe can help you with optional arguments, error handling, and records with optional fields.

Link to this section Summary

Functions

Transform a Maybe value with a given function

Provide a default value, turning an optional value into a normal value

Link to this section Types

Link to this type t(value)
t(value) :: value | nil

Link to this section Functions

Link to this function map(maybe, fun)
map(t(a), (a -> b)) :: t(b) when a: var, b: var

Transform a Maybe value with a given function.

Examples

iex> ExMaybe.map(nil, fn(_) -> "TEST" end)
nil

iex> ExMaybe.map(10, fn(val) -> val + 1 end)
11
Link to this function with_default(maybe, default)
with_default(t(a), a) :: a when a: var

Provide a default value, turning an optional value into a normal value.

Examples

iex> ExMaybe.with_default(nil, 10)
10

iex> ExMaybe.with_default(11, 20)
11