qol_gleam/qol_result

Values

pub fn guard(
  when requirement: Result(a, b),
  otherwise alternative: c,
  return consequence: fn(a) -> c,
) -> c

Run a callback function if the given result is Ok, otherwise return a default value.

With a use expression this function can simulate the early-return pattern found in some other programming languages.

pub fn lazy_guard(
  when requirement: Result(a, b),
  otherwise alternative: fn(b) -> c,
  return consequence: fn(a) -> c,
) -> c

Runs a callback function if the given result is Ok, otherwise runs an alternative callback function.

Useful when further computation should be delayed regardless of the given result’s value.

See guard for more info.

pub fn unwrap_both(result: Result(a, a)) -> a

Extracts the inner value from a result. Both the value and error must be of the same type.

Examples

assert unwrap_both(Error(1)) == 1
assert unwrap_both(Ok(2)) == 2
Search Document