gond

🔠 Multi-branch conditional expressions for Gleam

Types

Represents a condition that can be evaluated lazily or eagerly, or a mere fact where the consequence is already known.

pub opaque type Branch(a)
pub opaque type Condition
pub opaque type Consequence(a)

Functions

pub fn cond(
  branches branches: List(Branch(a)),
  default alternative_fun: fn() -> a,
) -> a

Executes a list of branches and returns the consequence of the first branch that evaluates to true.

If no branch evaluates to true, the default alternative function is executed.

pub fn return(
  on condition: Condition,
  consequence consequence: a,
) -> Branch(a)

Sets a literal consequence to return if a previous condition evaludated to true.

pub fn run(
  on condition: Condition,
  consequence consequence_fun: fn() -> a,
) -> Branch(a)

Sets a consequence to run if a previous condition evaludated to true.

pub fn when(given condition_fun: fn() -> Bool) -> Condition

Creates a condition that evaluates to true if the given function returns true.

pub fn where(given condition: Bool) -> Condition

Creates a condition that holds a literal boolean value.

Search Document