This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
Switch
~import std/switchKoru Standard Library: switch — compile-time exact-value dispatch as control
switch.kz · 1 tors · ~[comptime]
Koru Standard Library: switch — compile-time exact-value dispatch as control · 15 more lines
Koru Standard Library: switch — compile-time exact-value dispatch as control
flow. Sibling of std/regex:match: same branch surface, but dispatches on a
single scalar value with a native Zig switch instead of a regex DFA.
std/switch:char(ch)
| `a` c |> got-a(c)
| `b` c |> got-b(c)
| no-match |> other()
The branch head is the opaque backtick string. The transform parses it as:
- single char: `a`
- inclusive range: `a-z`
- set of chars: `aeiou`
and emits a Zig switch on the dispatched value. First matching arm wins;
`no-match` is the optional fallback.
// The event declares the USER surface: any raw-name branch carries the matched
// char (bind or discard with `_`), plus an optional void `no-match` fallback.
// The shape checker enforces this contract; the transform owns pattern parsing
// and code emission.
~[comptime|transform] pub tor char {
expr: Expression,
reporter: std/compiler:*ErrorReporter
}
| * *
| ?no-match