Patterns sugar
This commit is contained in:
parent
8fc9608199
commit
9c5e26e8f1
|
@ -31,6 +31,9 @@ proc `?`*(typ: static typedesc): Pattern {.inline.} =
|
|||
proc `?`*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern {.inline.} =
|
||||
patterns.grab(typ, bindings)
|
||||
|
||||
proc `?`*(typ: static typedesc; bindings: sink openArray[(Assertion, Pattern)]): Pattern {.inline.} =
|
||||
patterns.grab(typ, bindings)
|
||||
|
||||
proc `??`*(pat: Pattern; bindings: openArray[(int, Pattern)]): Pattern {.inline.} =
|
||||
patterns.inject(pat, bindings)
|
||||
|
||||
|
|
|
@ -286,6 +286,11 @@ proc grabRecord*(label: Preserve[Cap], fields: varargs[Pattern]): Pattern =
|
|||
"""<rec Says [<bind <_>> <bind <_>>]>"""
|
||||
DCompoundRec(label: label, fields: fields.toSeq).toPattern
|
||||
|
||||
proc grabRecord*(label: string, fields: varargs[Pattern]): Pattern =
|
||||
## Sugar for creating record patterns.
|
||||
## `label` is converted to a symbol value.
|
||||
grabRecord(label.toSymbol(Cap), fields)
|
||||
|
||||
proc grabDictionary*(bindings: sink openArray[(Value, Pattern)]): Pattern =
|
||||
## Construct a pattern that grabs some dictionary pairs.
|
||||
DCompoundDict(entries: bindings.toTable).toPattern
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "20230725"
|
||||
version = "20230726"
|
||||
author = "Emery Hemingway"
|
||||
description = "Syndicated actors for conversational concurrency"
|
||||
license = "Unlicense"
|
||||
|
|
Loading…
Reference in New Issue