Skip to content

Commit 82783fd

Browse files
authored
Merge pull request #22 from xcoo/fix/deep-merge
Fix deep-merge with nil arguments and values
2 parents 4571b9d + 917fc94 commit 82783fd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/cljc/proton/core.cljc

+4-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@
198198
"Recursively merges maps."
199199
[& maps]
200200
(letfn [(m [& xs]
201-
(if (every? #(and (map? %) (not (record? %))) xs)
202-
(apply merge-with m xs)
203-
(last xs)))]
201+
(let [xs (remove nil? xs)]
202+
(if (every? #(and (map? %) (not (record? %))) xs)
203+
(apply merge-with m xs)
204+
(last xs))))]
204205
(reduce m maps)))

test/proton/core_test.cljc

+8
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@
158158
nil 3 7))
159159

160160
(deftest deep-merge-test
161+
(is (= (core/deep-merge {:foo 1} nil)
162+
{:foo 1}))
163+
(is (= (core/deep-merge nil {:foo 1})
164+
{:foo 1}))
165+
(is (= (core/deep-merge {:foo 1} {:foo nil})
166+
{:foo 1}))
167+
(is (= (core/deep-merge {:foo nil} {:foo 1})
168+
{:foo 1}))
161169
(is (= (core/deep-merge {:foo {:bar 1}} {:foo {:baz 2}})
162170
{:foo {:bar 1 :baz 2}}))
163171
(is (= (core/deep-merge {:foo {:bar 1}} {:baz 2})

0 commit comments

Comments
 (0)