Add toDictionary procedure

This commit is contained in:
Emery Hemingway 2023-04-03 17:03:56 -05:00
parent 1a0cb2be5c
commit ea7225e3b5
2 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "20230401"
version = "20230403"
author = "Emery Hemingway"
description = "data model and serialization format"
license = "Unlicense"

View File

@ -327,6 +327,11 @@ proc initSet*(E = void): Preserve[E] = Preserve[E](kind: pkSet)
proc initDictionary*(E = void): Preserve[E] = Preserve[E](kind: pkDictionary)
## Create a Preserves dictionary value.
proc toDictionary*[E](pairs: openArray[(string, Preserve[E])]): Preserve[E] =
## Create a Preserves dictionary value.
result = Preserve[E](kind: pkDictionary)
for (key, val) in pairs: result[toSymbol(key, E)] = val
proc embed*[E](pr: sink Preserve[E]): Preserve[E] =
## Create a Preserves value that embeds ``e``.
result = pr