qol_gleam/qol_option

Values

pub fn guard(
  when requirement: option.Option(a),
  return consequence: fn(a) -> b,
  otherwise alternative: b,
) -> b

Run a callback function if the given result is Some, 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: option.Option(a),
  return consequence: fn(a) -> b,
  otherwise alternative: fn() -> b,
) -> b

Runs a callback function if the given result is Some, 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