Nimony

The road to Nim 3

opt

nimony/lib/std/opt.nim

opt — an optional value built on Nimony's native sum types.

The sum-type optional (Opt[T]), distinct from a Nim 2-compatible Option[T]. None is the absent (fieldless) case, Some carries a value. none[T]() constructs through result so the fieldless None takes its Opt[T] type from the typed result slot (a bare None() in expression position has nothing to infer T from).

unsafeGet raises BugError on None (a system ErrorCode — calling it without guarding is a programming error); guard with isSome, or use the total get(default).

import std/opt
proc find(k: string): Opt[int] =
  if k == "x": result = some(1)
  else: result = none[int]()
let r = find("x")
if r.isSome: echo r.get(0)