mirror of
https://github.com/metagn/knot
synced 2026-01-14 21:31:45 +00:00
No description
| .github | ||
| src | ||
| tests | ||
| .gitignore | ||
| knot.nimble | ||
| README.md | ||
knot
Associate compile-time values with a type under a name.
import knot
type Foo = object
const bar {.tie: Foo.} = 123
assert Foo.pick(bar) == 123
tie Foo:
proc baz(x: int): string = "int " & $x
proc baz(x: float): string = "float " & $x
assert Foo.choice(baz)(123) == "int 123"
assert Foo.choice(baz)(1.23) == "float 1.23"
Foo.tie collection, 1
Foo.tie collection, 2
Foo.tie collection, 3
assert Foo.unravel(collection, []) == [1, 2, 3]
assert Foo.unravel(collection, {}) == {1, 2, 3}