given

This library attempts to make guards:

Functions

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

Examples

import given
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,
  else_return alternative: fn() -> a,
) -> a

Examples

import given.{given}
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 optn: Option(a),
  else_return alternative: fn(a) -> b,
  return consequence: fn() -> b,
) -> b

Examples

import given
use <- given.none_in(option, else_return: fn(some_value) { some_value })
// …handle None here…
"None"
pub fn not_given(
  requirement: Bool,
  return consequence: fn() -> a,
  else_return alternative: fn() -> a,
) -> a

Examples

import given.{not_given}
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 rslt: Result(a, b),
  else_return consequence: fn(a) -> c,
  return alternative: fn(b) -> c,
) -> c

Examples

import given
use ok_value <- given.ok_in(result, else_return: fn(error_value) { "Error" })
// …handle Ok value here…
"Ok"
pub fn some_in(
  option optn: Option(a),
  else_return alternative: fn() -> b,
  return consequence: fn(a) -> b,
) -> b

Examples

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