Created
April 27, 2012 02:29
-
-
Save ninjudd/2505172 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn dissoc-in | |
| "Associates a value in a nested associative structure, where ks is a sequence of keys and returns | |
| a new nested structure. If any maps that result are empty, they will be removed from the new | |
| structure." | |
| [m [k & ks :as keys]] | |
| (if ks | |
| (if-let [old (get m k)] | |
| (let [new (dissoc-in old ks)] | |
| (if (seq new) | |
| (assoc m k new) | |
| (dissoc m k))) | |
| m) | |
| (if (seq keys) | |
| (dissoc m k) | |
| {}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment