Skip to content

Commit

Permalink
Merge pull request #1241 from primo-ppcg/keys-values-pairs
Browse files Browse the repository at this point in the history
Rework `keys`, `values`, `pairs`
  • Loading branch information
bakpakin authored Aug 6, 2023
2 parents ecc4d80 + 7417e82 commit 06eea74
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -1566,31 +1566,31 @@
(defn keys
"Get the keys of an associative data structure."
[x]
(def arr @[])
(var k (next x nil))
(while (not= nil k)
(array/push arr k)
(set k (next x k)))
(def arr (array/new-filled (length x)))
(var i 0)
(eachk k x
(put arr i k)
(++ i))
arr)

(defn values
"Get the values of an associative data structure."
[x]
(def arr @[])
(var k (next x nil))
(while (not= nil k)
(array/push arr (in x k))
(set k (next x k)))
(def arr (array/new-filled (length x)))
(var i 0)
(each v x
(put arr i v)
(++ i))
arr)

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

(defn frequencies
Expand Down

0 comments on commit 06eea74

Please sign in to comment.