### Gond Conditional Expression Example Source: https://hexdocs.pm/gond/2.0.3/index Demonstrates the usage of Gond's `cond`, `when`, `fact`, and `run` functions to create a multi-branch conditional logic. It includes examples of random number generation and different ways to specify branches. ```gleam import gleam/int import gond.{cond, fact, run, when, yield} fn example() { cond( branches: [ when(fn() { int.random(3) == 1 }) |> run(fn() { "Heads!" }), fact(int.random(3) == 2) |> run(fn() { "Tails!" }), when(fn() { True }) |> yield("This always occurs!"), fact(False) |> yield("This is never the fact!"), ], default: fn() { "Lost the coin?" }, ) } pub fn main() { echo example() } ``` -------------------------------- ### Gond Installation Source: https://hexdocs.pm/gond/2.0.3/index Provides the command to add the Gond library to a Gleam project using the `gleam add` command. ```gleam gleam add gond@2 ``` -------------------------------- ### Gond Development Commands Source: https://hexdocs.pm/gond/2.0.3/index Lists the standard Gleam commands for running the project and executing tests for the Gond library. ```gleam gleam run # Run the project gleam test # Run the tests ``` -------------------------------- ### Gond Values - cond, fact, run, when, yield Source: https://hexdocs.pm/gond/2.0.3/gond Provides functions for constructing and executing multi-branch conditional expressions. 'cond' executes branches, 'fact' creates literal conditions, 'run' associates a consequence with a condition, 'when' creates function-based conditions, and 'yield' provides literal consequences. ```APIDOC cond(branches: List(Branch(a)), 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. fact(given: Bool) -> Condition: Creates a condition that holds a literal boolean value. run(on: Condition, consequence_fun: fn() -> a) -> Branch(a): Consequence to run if a previous condition evaluates to true. when(given_fun: fn() -> Bool) -> Condition: Creates a condition that evaluates to true if the given function returns true. yield(on: Condition, consequence: a) -> Branch(a): Literal consequence to yield if a previous condition evaluates to true. ``` -------------------------------- ### Gond Types Source: https://hexdocs.pm/gond/2.0.3/gond Defines the opaque types used in Gond for representing branches, conditions, and consequences within conditional expressions. ```APIDOC Branch(a): Represents a branch of a conditional expressions. opaque type Branch(a) Condition: Represents a condition that can be evaluated lazily or eagerly. opaque type Condition Consequence(a): Represents a condition that can be evaluated lazily or eagerly. opaque type Consequence(a) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.