1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-03 17:13:10 +00:00

Allow iterating over generators with pairs, keys, and values.

This commit is contained in:
Calvin Rose
2023-08-22 19:24:44 -05:00
parent 70a467d469
commit d9605c2856
3 changed files with 12 additions and 6 deletions

View File

@@ -1584,7 +1584,7 @@
(defn keys
"Get the keys of an associative data structure."
[x]
(def arr (array/new-filled (length x)))
(def arr @[])
(var i 0)
(eachk k x
(put arr i k)
@@ -1594,7 +1594,7 @@
(defn values
"Get the values of an associative data structure."
[x]
(def arr (array/new-filled (length x)))
(def arr @[])
(var i 0)
(each v x
(put arr i v)
@@ -1604,7 +1604,7 @@
(defn pairs
"Get the key-value pairs of an associative data structure."
[x]
(def arr (array/new-filled (length x)))
(def arr @[])
(var i 0)
(eachp p x
(put arr i p)