Skip to content

piedar/coalesce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A coalesce operator ?? for Nim

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages