View Source Rail (rail v0.2.0)
Link to this section Summary
Functions
Apply a function or pipe to a function call when value is not {:error, _} or :error
Apply a function when value is not {:error, _} or :error
Link to this section Functions
Apply a function or pipe to a function call when value is not {:error, _} or :error
examples
Examples
iex> 1 >>> fn v -> Integer.to_string(v) end
"1"
iex> {:ok, 1} >>> fn v -> Integer.to_string(v) end
"1"
iex> {:ok, 1} >>> Integer.to_string()
"1"
iex> :error >>> Integer.to_string()
:error
iex> {:error, :div_by_zero} >>> Integer.to_string()
{:error, :div_by_zero}
Apply a function when value is not {:error, _} or :error
examples
Examples
iex> 1 |> Rail.chain(fn v -> v + 10 end)
11
iex> {:ok, 1} |> Rail.chain(fn v -> v + 10 end)
11
iex> :error |> Rail.chain(fn v -> v + 10 end)
:error
iex> {:error, :noent} |> Rail.chain(fn v -> v + 10 end)
{:error, :noent}