Simplificator3000.Result (Simplificator3000 v0.6.0)
Link to this section Summary
Functions
Calls given fun with provided result only if it is Ok result.
Outcome of the given function is wrapped in Ok result if it is not already a valid result struct
Link to this section Types
@type t() :: Simplificator3000.Result.Ok.t() | Simplificator3000.Result.Error.t()
Link to this section Functions
Link to this function
with_ok(result, fun)
Calls given fun with provided result only if it is Ok result.
Outcome of the given function is wrapped in Ok result if it is not already a valid result struct
examples
Examples
iex> ok = %Elixir.Simplificator3000.Result.Ok{data: 123}
iex> Elixir.Simplificator3000.Result.with_ok(ok, & &1.data * 2)
%Elixir.Simplificator3000.Result.Ok{data: 246}
iex> ok = %Elixir.Simplificator3000.Result.Ok{data: 123}
iex> Elixir.Simplificator3000.Result.with_ok(ok, & %Elixir.Simplificator3000.Result.Ok{data: "Hello #{&1.data}"})
%Elixir.Simplificator3000.Result.Ok{data: "Hello 123"}
iex> ok = %Elixir.Simplificator3000.Result.Ok{data: 123}
iex> Elixir.Simplificator3000.Result.with_ok(ok, fn _ -> %Elixir.Simplificator3000.Result.Error{reason: :just_crashed} end)
%Elixir.Simplificator3000.Result.Error{reason: :just_crashed}
iex> error = %Elixir.Simplificator3000.Result.Error{reason: :nothing}
iex> Elixir.Simplificator3000.Result.with_ok(error, & &1.data * 2)
%Elixir.Simplificator3000.Result.Error{reason: :nothing}