Simplificator3000.Result (Simplificator3000 v0.8.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
Converts classic way of ok/error result into Ok/Error structs for common processing
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}
Link to this function
wrap(result)
@spec wrap( {:ok, any()} | {:ok, any(), any()} | {:error, any()} | {:error, any(), any()} | Result.t() ) :: Result.t()
Converts classic way of ok/error result into Ok/Error structs for common processing