mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-09 09:13:07 +00:00
26 lines
648 B
Nim
26 lines
648 B
Nim
import std/options
|
|
import std/macros
|
|
|
|
proc option[T](option: Option[T]): Option[T] =
|
|
option
|
|
|
|
template bindLet(name, expression): bool =
|
|
let option = expression.option
|
|
template name: auto {.used.} = option.unsafeGet()
|
|
option.isSome
|
|
|
|
template bindVar(name, expression): bool =
|
|
let option = expression.option
|
|
var name : typeof(option.unsafeGet())
|
|
if option.isSome:
|
|
name = option.unsafeGet()
|
|
option.isSome
|
|
|
|
macro `=?`*(name, expression): bool =
|
|
name.expectKind({nnkIdent, nnkVarTy})
|
|
if name.kind == nnkIdent:
|
|
quote do: bindLet(`name`, `expression`)
|
|
else:
|
|
let name = name[0]
|
|
quote do: bindVar(`name`, `expression`)
|