Hello, Is the hierarchy always done with the same key ? If so, you can use zippers. Of course, without indexation of the position of your map, you may well end up walking the tree in O(n) more than necessary, which could or could not become the perf. bottleneck of your application, depending on how central this map of map.
This could look something like this: => (def a {:id 1 :c [{:id 2} {:id 3 :c [{:id 4}]}]}) #'user/a => (def make-zipper (partial zip/zipper (constantly true) :c #(assoc %1 :c (vec %2)))) #'user/make-zipper => (defn rmv [a k] (let [z (make-zipper a) n-seq (take-while (complement zip/end?) (iterate zip/next z))] (if-let [loc (first (drop-while #(not= k (:id (zip/node %))) n-seq))] (when (not= a (zip/node loc)) (zip/root (zip/remove loc))) a))) #'user/rmv => (rmv a 1) nil => (rmv a 4) {:id 1, :c [{:id 2} {:id 3, :c []}]} => (rmv a 3) {:id 1, :c [{:id 2}]} 2011/7/28 semperos <daniel.l.grego...@gmail.com> > Darn tabbing...apologies for the previous post. > > Here's my full question: > > I have a map of maps, arbitrarily nested. Every individual map has a > key/value entry that acts as a unique identifier for that map. I need to be > able to write a function that, given the whole map of maps and the value of > that unique ID, can dissoc the map with that unique ID. > > I feel like I'm missing something basic. I'm aware of things like assoc-in > and update-in for dealing with nested structures, but those require knowing > the structure ahead of time. I need to be able to pass in a unique ID which > could be at any level of maps within the map and dissoc it once it's > "found." > > My question: Is there a method or approach using plain Clojure maps that's > eluding me? If not and this requires some kind of searching, is there a > better data structure to use? > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en