Uptight.Result (Uptight v0.2.2-rc)
Alternative Either. Differences from Alage Either:
- 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.
- 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.
- 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
Specs
t() :: Uptight.Result.Ok.t() | Uptight.Result.Err.t()
Link to this section Functions
Link to this function
cont(e, f)
Specs
Link to this function
cont_end(res)
Specs
Link to this function
from_ok(err)
Specs
Link to this function
is_err?(_)
Specs
Link to this function
is_ok?(_)
Specs
Link to this function
new()
Specs
new() :: t()
Link to this function
new(f)
Specs
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
Link to this function
new_ok()
Specs
new_ok() :: Uptight.Result.Ok.t()