ovo_utils v0.1.0 OvoUtils.Utils View Source
Miscellaneous utility functions.
Link to this section Summary
Functions
Applies a function to a value inside an {:ok | :error, value} tuple if atom is :ok, otherwise returns the tuple without applying the function
Link to this section Functions
Link to this function
apply_on_ok(tuple, function) View Source
Applies a function to a value inside an {:ok | :error, value} tuple if atom is :ok, otherwise returns the tuple without applying the function.
Examples
iex> {:ok, 2} |> Utils.apply_on_ok(fn x -> x + 2 end)
{:ok, 4}
iex> {:error, "reason"} |> Utils.apply_on_ok(fn x -> x + 2 end)
{:error, "reason"}
iex> {:ok, 2} |> Utils.apply_on_ok(fn x -> {:ok, x + 2} end)
{:ok, 4}
iex> {:ok, 2} |> Utils.apply_on_ok(fn _ -> {:error, "reason"} end)
{:error, "reason"}