Aikido

Small composable helpers for working with {:ok, value} | {:error, reason} result tuples in pipelines. The function names are borrowed from aikido techniques — they describe the shape of the transformation.

Installation

Add aikido to your list of dependencies in mix.exs:

def deps do
  [
    {:aikido, "~> 0.1.0"}
  ]
end

Usage

{:ok, 2}
|> Aikido.blend(fn n -> {:ok, n * 5} end)
|> Aikido.blend(fn n -> if n > 5, do: {:error, :too_big}, else: {:ok, n} end)
|> Aikido.redirect(fn _ -> {:ok, 0} end)
|> Aikido.unwrap_or(-1)
# => 0

Functions

Full docs at https://hexdocs.pm/aikido.

License

MIT