Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request clj-commons#27 from jeremyheiler/develop
Allow dissoc-in* to remove false and nil
  • Loading branch information
amalloy committed Oct 10, 2014
2 parents 01bf013 + f690b1d commit 13a594a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/flatland/useful/map.clj
Expand Up @@ -85,12 +85,13 @@
correct if keys is empty."
[m keys]
(if-let [[k & ks] (seq keys)]
(if-let [old (get m k)]
(let [new (dissoc-in* old ks)]
(if (seq new)
(assoc m k new)
(dissoc m k)))
m)
(let [old (get m k ::sentinel)]
(if-not (= old ::sentinel)
(let [new (dissoc-in* old ks)]
(if (seq new)
(assoc m k new)
(dissoc m k)))
m))
{}))

(defn assoc-in*
Expand Down
6 changes: 5 additions & 1 deletion test/flatland/useful/map_test.clj
Expand Up @@ -110,7 +110,11 @@
(is (= {:bam 3}
(dissoc-in* {:foo {:bar 3 :baz 8} :bam 3} [:foo])))
(is (= {}
(dissoc-in* {:foo {:bar 3 :baz 8}} []))))
(dissoc-in* {:foo {:bar 3 :baz 8}} [])))
(is (= {}
(dissoc-in* {:foo {:bar false}} [:foo :bar])))
(is (= {}
(dissoc-in* {:foo {:bar nil}} [:foo :bar]))))

(deftest test-assoc-in*
(is (= {:foo {:bar 1}}
Expand Down

0 comments on commit 13a594a

Please sign in to comment.