Skip to content

Commit 43bcbca

Browse files
kierdavisoprypin
authored andcommitted
Add items and pairs iterators for vkList Values (#20)
1 parent 200d091 commit 43bcbca

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/private/value.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ proc `[]`*(v: Value, i: int): string =
5858
## It is an error to use it on other kinds of Values.
5959
v.list_v[i]
6060

61+
iterator items*(v: Value): string =
62+
## Iterate over the seq of a vkList Value.
63+
## It is an error to use it on other kinds of Values.
64+
for val in v.list_v:
65+
yield val
66+
67+
iterator pairs*(v: Value): tuple[key: int, val: string] =
68+
## Iterate over the seq of a vkList Value, yielding ``(index, v[index])``
69+
## pairs.
70+
## It is an error to use it on other kinds of Values.
71+
for key, val in v.list_v:
72+
yield (key: key, val: val)
6173

6274
proc str(s: string): string =
6375
if s.is_nil: "nil"

0 commit comments

Comments
 (0)