Uptight.Result (Uptight v0.2.6-rc)

Alternative Either. Differences from Alage Either:

  1. Overloaded new that takes a nullary function, runs it and if it raises an error, it returns Err holding Uptight.Trace, it returns Ok otherwise.
  2. As data, not biased neither towrards Ok nor Err, whereas Algae version is biased towards Right: https://github.com/witchcrafters/algae/blob/067e2b0a02c5c0c4183051807dfa733e2ee43fe4/lib/algae/either.ex#L140.
  3. As operation, biased neither towards Ok nor Err (unlike Algae version, which is biased towards Left). Thus, Result instances adhere to all the typeclass laws.

Link to this section Summary

Functions

Run failable function, capturing return value into Ok and a runtime error into Err.

Link to this section Types

Link to this section Functions

Specs

cont(t(), (any() -> any())) :: t()

Specs

cont_end(t()) :: t()

Specs

from_ok(t()) :: any()

Specs

is_err?(t()) :: boolean()

Specs

is_ok?(t()) :: boolean()

Specs

new() :: t()

Specs

new((() -> any())) :: t()

Run failable function, capturing return value into Ok and a runtime error into Err.

Examples

iex> Uptight.Result.new(fn () -> :erlang.system_flag(:backtrace_depth, 0); raise "oopsie" end) |> Uptight.Result.is_err?()
true

iex> Uptight.Result.new(fn () -> :erlang.system_flag(:backtrace_depth, 20); raise "is_err!" end) |> Uptight.Result.is_err?()
true

iex> Uptight.Result.new(fn () -> 42 end)
%Uptight.Result.Ok{ok: 42}

iex> Uptight.Result.new(fn () -> 42 end) |> Uptight.Result.is_ok?()
true

iex> Uptight.Result.new(fn () -> 42 end) |> Uptight.Result.is_err?()
false

Specs

new_ok() :: Uptight.Result.Ok.t()