Skip to content

Commit 8a4f8d1

Browse files
committed
CLJS-3363: reduce-kv on seq of map entries
1 parent 6aefc73 commit 8a4f8d1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,9 +2624,11 @@ reduces them without incurring seq initialization"
26242624
and f is not called. Note that reduce-kv is supported on vectors,
26252625
where the keys will be the ordinals."
26262626
([f init coll]
2627-
(if-not (nil? coll)
2627+
(if (satisfies? IKVReduce coll)
26282628
(-kv-reduce coll f init)
2629-
init)))
2629+
(reduce (fn [ret me]
2630+
(f ret (-key me) (-val me)))
2631+
init coll))))
26302632

26312633
(defn identity
26322634
"Returns its argument."

src/test/cljs/cljs/core_test.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,12 @@
19751975
{1 1 3 3} (update-keys (array-map 0 1 2 3) inc)
19761976
{1 1 3 3} (update-keys (sorted-map 2 3 0 1) inc))))
19771977

1978+
(deftest test-cljs-3363
1979+
(is (= {}
1980+
(reduce-kv #(assoc %1 %3 %2) {} nil)))
1981+
(is (= {1 :a 2 :b}
1982+
(reduce-kv #(assoc %1 %3 %2) {} (seq {:a 1 :b 2})))))
1983+
19781984
(defn cljs-3386-test-fn
19791985
([x] x) ([_ _ & zs] zs))
19801986

0 commit comments

Comments
 (0)