Step with mulitple indexes
This commit is contained in:
parent
6e0834316f
commit
ca5d44ed32
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20231026"
|
version = "20231028"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "data model and serialization format"
|
description = "data model and serialization format"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
|
|
@ -94,7 +94,7 @@ type
|
||||||
|
|
||||||
DictEntry[E] = tuple[key: Preserve[E], val: Preserve[E]]
|
DictEntry[E] = tuple[key: Preserve[E], val: Preserve[E]]
|
||||||
|
|
||||||
proc `==`*[A, B](x: Preserve[A]; y: Preserve[B]): bool =
|
func `==`*[A, B](x: Preserve[A]; y: Preserve[B]): bool =
|
||||||
## Check `x` and `y` for equivalence.
|
## Check `x` and `y` for equivalence.
|
||||||
if x.kind == y.kind and x.embedded == y.embedded:
|
if x.kind == y.kind and x.embedded == y.embedded:
|
||||||
case x.kind
|
case x.kind
|
||||||
|
@ -329,6 +329,13 @@ func step*(pr, idx: Preserve): Option[Preserve] =
|
||||||
if i < pr.len:
|
if i < pr.len:
|
||||||
result = some(pr[i])
|
result = some(pr[i])
|
||||||
|
|
||||||
|
func step*(pr: Preserve; path: varargs[Preserve]): Option[Preserve] =
|
||||||
|
## Step into `pr` by indexes at `path`.
|
||||||
|
result = some(pr)
|
||||||
|
for index in path:
|
||||||
|
if result.isSome:
|
||||||
|
result = step(result.get, index)
|
||||||
|
|
||||||
func step*[E](pr: Preserve[E]; key: Symbol): Option[Preserve[E]] =
|
func step*[E](pr: Preserve[E]; key: Symbol): Option[Preserve[E]] =
|
||||||
## Step into dictionary by a `Symbol` key.
|
## Step into dictionary by a `Symbol` key.
|
||||||
if pr.isDictionary:
|
if pr.isDictionary:
|
||||||
|
|
Loading…
Reference in New Issue