patterns: grabRecord, grabDictionary
This commit is contained in:
parent
ce8e800187
commit
8fc9608199
|
@ -277,15 +277,26 @@ proc inject*(pat: Pattern; bindings: openArray[(Preserve[Cap], Pattern)]): Patte
|
||||||
for (key, val) in bindings:
|
for (key, val) in bindings:
|
||||||
result.dcompound.dict.entries[key] = val
|
result.dcompound.dict.entries[key] = val
|
||||||
|
|
||||||
proc recordPattern*(label: Preserve[Cap], fields: varargs[Pattern]): Pattern =
|
proc grabRecord*(label: Preserve[Cap], fields: varargs[Pattern]): Pattern =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
from std/unittest import check
|
from std/unittest import check
|
||||||
import syndicate/actors, preserves
|
import syndicate/actors, preserves
|
||||||
check:
|
check:
|
||||||
$recordPattern("Says".toSymbol(Cap), grab(), grab()) ==
|
$grabRecord("Says".toSymbol(Cap), grab(), grab()) ==
|
||||||
"""<rec Says [<bind <_>> <bind <_>>]>"""
|
"""<rec Says [<bind <_>> <bind <_>>]>"""
|
||||||
DCompoundRec(label: label, fields: fields.toSeq).toPattern
|
DCompoundRec(label: label, fields: fields.toSeq).toPattern
|
||||||
|
|
||||||
|
proc grabDictionary*(bindings: sink openArray[(Value, Pattern)]): Pattern =
|
||||||
|
## Construct a pattern that grabs some dictionary pairs.
|
||||||
|
DCompoundDict(entries: bindings.toTable).toPattern
|
||||||
|
|
||||||
|
proc grabDictionary*(bindings: sink openArray[(string, Pattern)]): Pattern =
|
||||||
|
## Construct a pattern that grabs some dictionary pairs.
|
||||||
|
## Keys are converted from strings to symbols.
|
||||||
|
result = DCompoundDict().toPattern
|
||||||
|
for (key, val) in bindings.items:
|
||||||
|
result.dcompound.dict.entries[key.toSymbol(Cap)] = val
|
||||||
|
|
||||||
type
|
type
|
||||||
Path* = seq[Value]
|
Path* = seq[Value]
|
||||||
Paths* = seq[Path]
|
Paths* = seq[Path]
|
||||||
|
|
Loading…
Reference in New Issue