From d9049bf729b37cd6d21022674d966bec31bcb7a7 Mon Sep 17 00:00:00 2001 From: scgilardi Date: Sun, 24 May 2009 00:25:49 +0000 Subject: clojure.contrib.core: add dissoc-in --- src/clojure/contrib/core.clj | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/clojure') diff --git a/src/clojure/contrib/core.clj b/src/clojure/contrib/core.clj index e5fe7c78..55e5e777 100644 --- a/src/clojure/contrib/core.clj +++ b/src/clojure/contrib/core.clj @@ -42,3 +42,22 @@ (.?. nil .toUpperCase (.substring 1)) returns nil " .. .?.) + +;; ---------------------------------------------------------------------- +;; scgilardi at gmail + +(defn dissoc-in + "Dissociates an entry from a nested associative structure returning a new + nested structure. keys is a sequence of keys. Any empty maps that result + will not be present in the new structure." + [m [k & ks :as keys]] + (if ks + (if-let [nextmap (get m k)] + (let [newmap (dissoc-in nextmap ks)] + (if (seq newmap) + (assoc m k newmap) + (dissoc m k))) + m) + (dissoc m k))) + +;; ---------------------------------------------------------------------- -- cgit v1.2.3-18-g5258