1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-22 21:23:16 +00:00

Merge pull request #1241 from primo-ppcg/keys-values-pairs

Rework `keys`, `values`, `pairs`
This commit is contained in:
Calvin Rose 2023-08-06 08:10:43 -05:00 committed by GitHub
commit 06eea74b98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1566,31 +1566,31 @@
(defn keys (defn keys
"Get the keys of an associative data structure." "Get the keys of an associative data structure."
[x] [x]
(def arr @[]) (def arr (array/new-filled (length x)))
(var k (next x nil)) (var i 0)
(while (not= nil k) (eachk k x
(array/push arr k) (put arr i k)
(set k (next x k))) (++ i))
arr) arr)
(defn values (defn values
"Get the values of an associative data structure." "Get the values of an associative data structure."
[x] [x]
(def arr @[]) (def arr (array/new-filled (length x)))
(var k (next x nil)) (var i 0)
(while (not= nil k) (each v x
(array/push arr (in x k)) (put arr i v)
(set k (next x k))) (++ i))
arr) arr)
(defn pairs (defn pairs
"Get the key-value pairs of an associative data structure." "Get the key-value pairs of an associative data structure."
[x] [x]
(def arr @[]) (def arr (array/new-filled (length x)))
(var k (next x nil)) (var i 0)
(while (not= nil k) (eachp p x
(array/push arr (tuple k (in x k))) (put arr i p)
(set k (next x k))) (++ i))
arr) arr)
(defn frequencies (defn frequencies