Skip to content

Instantly share code, notes, and snippets.

@ninjudd
Created April 27, 2012 02:29
Show Gist options
  • Select an option

  • Save ninjudd/2505172 to your computer and use it in GitHub Desktop.

Select an option

Save ninjudd/2505172 to your computer and use it in GitHub Desktop.
(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