patterns: observePattern sugar for integer offsets

This commit is contained in:
Emery Hemingway 2024-06-23 15:26:05 +03:00
parent b6f7e90b95
commit 85522a4c3c
2 changed files with 7 additions and 2 deletions

View File

@ -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"

View File

@ -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]