No description
Find a file
2023-08-28 11:53:57 +03:00
.github initial 2023-08-27 20:58:35 +03:00
src pick, fixes, examples & tests 2023-08-28 11:53:57 +03:00
tests pick, fixes, examples & tests 2023-08-28 11:53:57 +03:00
.gitignore initial 2023-08-27 20:58:35 +03:00
knot.nimble pick, fixes, examples & tests 2023-08-28 11:53:57 +03:00
README.md pick, fixes, examples & tests 2023-08-28 11:53:57 +03:00

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}