Skip to content

Commit

Permalink
fix: deep-merge with nil args or values
Browse files Browse the repository at this point in the history
  • Loading branch information
federkasten committed Apr 24, 2024
1 parent 4571b9d commit 917fc94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cljc/proton/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@
"Recursively merges maps."
[& maps]
(letfn [(m [& xs]
(if (every? #(and (map? %) (not (record? %))) xs)
(apply merge-with m xs)
(last xs)))]
(let [xs (remove nil? xs)]
(if (every? #(and (map? %) (not (record? %))) xs)
(apply merge-with m xs)
(last xs))))]
(reduce m maps)))
8 changes: 8 additions & 0 deletions test/proton/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@
nil 3 7))

(deftest deep-merge-test
(is (= (core/deep-merge {:foo 1} nil)
{:foo 1}))
(is (= (core/deep-merge nil {:foo 1})
{:foo 1}))
(is (= (core/deep-merge {:foo 1} {:foo nil})
{:foo 1}))
(is (= (core/deep-merge {:foo nil} {:foo 1})
{:foo 1}))
(is (= (core/deep-merge {:foo {:bar 1}} {:foo {:baz 2}})
{:foo {:bar 1 :baz 2}}))
(is (= (core/deep-merge {:foo {:bar 1}} {:baz 2})
Expand Down

0 comments on commit 917fc94

Please sign in to comment.