Witha v0.1.1 Witha.Nilable View Source

Maybe monad chain.

Typespec of maybe is term | nil.

iex> witha Witha.Nilable, x1 <- 1, do: x1 + 1
2

iex> witha Witha.Nilable, x1 <- nil, do: x1 + 1
nil

Just term can chain.

iex> witha Witha.Nilable, [
iex>   x1 <- 1,
iex>   x2 <- x1 + 1,
iex> ], do: x1 + x2
3

nil & raise stops the chain.

iex> witha Witha.Nilable, [
iex>   x1 <- nil,
iex>   x2 <- x1 + 1,
iex> ], do: x1 + x2
nil

iex> witha Witha.Nilable, [
iex>   x1 <- raise("駄目"),
iex>   x2 <- {:ok, x1 + 1},
iex> ], do: x1 + x2
nil

Link to this section Summary

Functions

Callback implementation for c:Witha.Aspect.flat_map/2

Callback implementation for c:Witha.Aspect.handle_error/1

Callback implementation for c:Witha.Aspect.new/1

Link to this section Functions

Callback implementation for c:Witha.Aspect.flat_map/2.

Callback implementation for c:Witha.Aspect.handle_error/1.

Callback implementation for c:Witha.Aspect.new/1.