given

This library attempts to make guards:

Functions

pub fn error_in(
  result result: Result(a, b),
  else_return consequence: fn(a) -> c,
  otherwise alternative: fn(b) -> c,
) -> c

Examples

use error_value <- given_error_in(result, else_return: fn(ok_value) { "Ok" })
// …handle Error value here…
"Error"
pub fn given(
  requirement: Bool,
  return consequence: fn() -> a,
  otherwise alternative: fn() -> a,
) -> a

Examples

let user_understood = case int.random(1) {
  1 -> True
  _ -> False
}

use <- given(user_understood, return: fn() { "Great!" })
// …else handle case where user did not understand here…
"Woof!"
pub fn none_in(
  option option: Option(a),
  else_return consequence: fn(a) -> b,
  otherwise alternative: fn() -> b,
) -> b

Examples

use none_value <- given_none_in(option, else_return: fn(some_value) { "Some value" })
// …handle None value here…
"None"
pub fn not_given(
  requirement: Bool,
  return consequence: fn() -> a,
  otherwise alternative: fn() -> a,
) -> a

Examples

let user_understood = case int.random(1) {
  1 -> True
  _ -> False
}

use <- not_given(user_understood, return: fn() { "Woof!" })
// …else handle case where user understood here…
"Great!"
pub fn ok_in(
  result result: Result(a, b),
  else_return alternative: fn(a) -> c,
  otherwise consequence: fn(b) -> c,
) -> c

Examples

use ok_value <- given_ok_in(result, else_return: fn(error_value) { "Error" })
// …handle Ok value here…
"Ok"
pub fn some_in(
  option option: Option(a),
  else_return consequence: fn() -> b,
  otherwise alternative: fn(a) -> b,
) -> b

Examples

use some_value <- given_some_in(option, else_return: fn() { "None" })
// …handle Some value here…
"Some value"
Search Document