isRecord: add variant with a label
This commit is contained in:
parent
7125eadd49
commit
b4756b13ae
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "20221025"
|
||||
version = "20221027"
|
||||
author = "Emery Hemingway"
|
||||
description = "data model and serialization format"
|
||||
license = "Unlicense"
|
||||
|
|
|
@ -391,9 +391,23 @@ func isSymbol*(pr: Preserve; sym: string|Symbol): bool {.inline.} =
|
|||
## Check if ``pr`` is a Preserves symbol of ``sym``.
|
||||
(pr.kind == pkSymbol) and (pr.symbol == Symbol(sym))
|
||||
|
||||
proc label*(pr: Preserve): Preserve {.inline.} =
|
||||
## Return the label of record value.
|
||||
pr.record[pr.record.high]
|
||||
|
||||
proc arity*(pr: Preserve): int {.inline.} =
|
||||
## Return the number of fields in record `pr`.
|
||||
pred(pr.record.len)
|
||||
|
||||
func isRecord*(pr: Preserve): bool {.inline.} = (pr.kind == pkRecord) and (pr.record.len > 0)
|
||||
## Check if ``pr`` is a Preserves record.
|
||||
|
||||
func isRecord*(pr: Preserve; label: string): bool {.inline.} =
|
||||
## Check if ``pr`` is a Preserves record with the given label symbol.
|
||||
pr.kind == pkRecord and
|
||||
pr.record.len > 0 and
|
||||
pr.label.isSymbol(label)
|
||||
|
||||
proc isSequence*(pr: Preserve): bool {.inline.} = pr.kind == pkSequence
|
||||
## Check if ``pr`` is a Preserves sequence.
|
||||
|
||||
|
@ -408,14 +422,6 @@ func isEmbedded*[E](pr: Preserve[E]): bool {.inline.} =
|
|||
when E is void: pr.embedded # embedded Preserves
|
||||
else: pr.kind == pkEmbedded # embedded Nim
|
||||
|
||||
proc label*(pr: Preserve): Preserve {.inline.} =
|
||||
## Return the label of record value.
|
||||
pr.record[pr.record.high]
|
||||
|
||||
proc arity*(pr: Preserve): int {.inline.} =
|
||||
## Return the number of fields in record `pr`.
|
||||
pred(pr.record.len)
|
||||
|
||||
proc fields*(pr: Preserve): seq[Preserve] {.inline.} =
|
||||
## Return the fields of a record value.
|
||||
pr.record[0..pr.record.high.pred]
|
||||
|
|
Loading…
Reference in New Issue