Gond 🔠 · cond for Gleam

Package <a href="https://github.com/inoas/gleam-gond/releases"><img src="https://img.shields.io/github/release/inoas/gleam-gond" alt="GitHub release"></a> Version Erlang-compatible JavaScript Compatible Hex Docs Discord CI Test

gleam add gond@1

Examples

import gleam/int
import gleam/io
import gleam/string
import gond.{
  cond as cond, return as return, run as run, when as when, where as where,
}

pub fn example() {
  cond(
    branches: [
      when(fn() { int.random(3) == 1 }) |> run(fn() { "Heads!" }),
      where(int.random(3) == 2) |> run(fn() { "Tails!" }),
      when(fn() { True }) |> return("This always when!"),
      where(False) |> return("This is never the fact!"),
    ],
    default: fn() { "Lost the coin?" },
  )
}

pub fn main() {
  example() |> string.inspect |> io.println
}

gleam run --module gond/internal/usage_examples

Further documentation can be found at https://hexdocs.pm/gond.

Development

gleam run   # Run the project
gleam test  # Run the tests

Inspiration

Elixir’s cond macro.

Search Document