patterns: observePattern sugar for integer offsets
This commit is contained in:
parent
b6f7e90b95
commit
85522a4c3c
|
@ -7,7 +7,7 @@
|
|||
"bom-ref": "pkg:nim/syndicate",
|
||||
"name": "syndicate",
|
||||
"description": "Syndicated actors for conversational concurrency",
|
||||
"version": "20240621",
|
||||
"version": "20240623",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Emery Hemingway"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import
|
||||
std/[assertions, options, tables, typetraits],
|
||||
std/[assertions, options, sequtils, tables, typetraits],
|
||||
pkg/preserves,
|
||||
./protocols/[dataspacePatterns, dataspace]
|
||||
|
||||
|
@ -423,6 +423,11 @@ proc observePattern*(pat: Pattern; injects: openarray[(seq[Value], Pattern)]): P
|
|||
metaApply(meta, pat, path, 0)
|
||||
result.group.entries[0.toPreserves] = meta
|
||||
|
||||
proc observePattern*(pat: Pattern; injects: openarray[(int, Pattern)]): Pattern =
|
||||
## Sugar for observing patterns using record field offsets.
|
||||
pat.observePattern injects.map do (pair: (int, Pattern)) -> (seq[Value], Pattern):
|
||||
(@[pair[0].toPreserves], pair[1])
|
||||
|
||||
type
|
||||
Path* = seq[Value]
|
||||
Paths* = seq[Path]
|
||||
|
|
Loading…
Reference in New Issue