Skip to content

Commit c61a235

Browse files
committed
CLJS-2943: Update merge-with to use key / val
1 parent 9da36c6 commit c61a235

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9018,7 +9018,7 @@ reduces them without incurring seq initialization"
90189018
[f & maps]
90199019
(when (some identity maps)
90209020
(let [merge-entry (fn [m e]
9021-
(let [k (first e) v (second e)]
9021+
(let [k (key e) v (val e)]
90229022
(if (contains? m k)
90239023
(assoc m k (f (get m k) v))
90249024
(assoc m k v))))

src/test/cljs/cljs/core_test.cljs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,3 +1625,15 @@
16251625
(is (false? ((comp not empty?) "")))
16261626
(is (thrown? js/Error ((not empty?) "foo")))
16271627
(is (thrown? js/Error ((not empty?) ""))))
1628+
1629+
(deftest test-cljs-2943
1630+
(let [m1 {:a 2, :b 3, :c 5}
1631+
m2 {:a 7, :b 11, :d 13, :e 17}
1632+
m3 {:a 19, :d 23, :f 29}
1633+
m4 {:a 28, :b 14, :c 5, :d 36, :e 17, :f 29}
1634+
sorted (fn [m] (into (sorted-map) m))]
1635+
(is (= m4 (merge-with + m1 m2 m3)))
1636+
(is (= m4 (merge-with + (sorted m1) m2 m3)))
1637+
(is (= m4 (merge-with + (sorted m1) (sorted m2) m3)))
1638+
(is (= m4 (merge-with + m1 (sorted m2) m3)))
1639+
(is (= m4 (merge-with + m1 (sorted m2) (sorted m3))))))

0 commit comments

Comments
 (0)