No description
Find a file
2017-07-26 18:36:41 -04:00
.gitignore use templates for short-circuit 2017-07-17 00:28:11 -04:00
coalesce.nim add documentation 2017-07-26 18:36:41 -04:00
coalesce.nimble improve non-nilable detection 2017-07-26 18:24:07 -04:00
mit-license.txt coalesce nils and options with ?? 2017-07-16 16:53:45 -04:00
readme.md use templates for short-circuit 2017-07-17 00:28:11 -04:00

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