Skip to content

Commit

Permalink
CLJS-3363: reduce-kv on seq of map entries
Browse files Browse the repository at this point in the history
  • Loading branch information
mfikes committed Aug 7, 2023
1 parent 6aefc73 commit 8a4f8d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2624,9 +2624,11 @@ reduces them without incurring seq initialization"
and f is not called. Note that reduce-kv is supported on vectors,
where the keys will be the ordinals."
([f init coll]
(if-not (nil? coll)
(if (satisfies? IKVReduce coll)
(-kv-reduce coll f init)
init)))
(reduce (fn [ret me]
(f ret (-key me) (-val me)))
init coll))))

(defn identity
"Returns its argument."
Expand Down
6 changes: 6 additions & 0 deletions src/test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,12 @@
{1 1 3 3} (update-keys (array-map 0 1 2 3) inc)
{1 1 3 3} (update-keys (sorted-map 2 3 0 1) inc))))

(deftest test-cljs-3363
(is (= {}
(reduce-kv #(assoc %1 %3 %2) {} nil)))
(is (= {1 :a 2 :b}
(reduce-kv #(assoc %1 %3 %2) {} (seq {:a 1 :b 2})))))

(defn cljs-3386-test-fn
([x] x) ([_ _ & zs] zs))

Expand Down

0 comments on commit 8a4f8d1

Please sign in to comment.