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.

Search Document