gond

🔠 Multi-branch conditional expressions for Gleam

Types

Represents a branch of a conditional expressions.

pub opaque type Branch(a)

Represents a condition that can be evaluated lazily or eagerly,

pub opaque type Condition

Represents a condition that can be evaluated lazily or eagerly,

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 fact(given condition: Bool) -> Condition

Creates a condition that holds a literal boolean value.

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

Consequence to run if a previous condition evaluates 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 yield(
  on condition: Condition,
  consequence consequence: a,
) -> Branch(a)

Literal consequence to yield if a previous condition evaluates to true.

Search Document