mirror of
https://github.com/piedar/coalesce
synced 2026-01-02 08:34:45 +00:00
No description
| .gitignore | ||
| coalesce.nim | ||
| coalesce.nimble | ||
| mit-license.txt | ||
| readme.md | ||
coalesce
The coalesce package implements a null coalescing operator ?? for Nim.
examples
The most obvious case is choosing the first non-nil value.
let a: string = nil
let x = a ?? "b"
assert x == "b"
The operator also supports Option[T].
let a: Option[string] = none(string)
let x = a ?? "b"
assert x == "b"
Longer chains work too, and the expression short-circuits if possible.
let result = tryComputeFast(input) ?? tryComputeSlow(input) ?? myDefault
todo
- support for
not nil