On 21 April 2010 19:02, Base <basselh...@gmail.com> wrote: > I am having a hard time destructuring a nested data structure. > > I am starting out with: > > {:tag :column, > :attrs nil, > :content > [{:tag :name, :attrs nil, :content ["agecat"]} > {:tag :value, :attrs nil, :content ["nil"]} > {:tag :threshold, :attrs nil, :content ["0.05"]}]} > > and am looking to get: > > {:column "agecat", :value "nil", :threshold "0.05"}
If I understand correctly, you want to take the :tag from the top-level map, then reach into the :content vector and extract the maps with either :name or :threshold bound to the :tag key and get something out of their content, right? If so, then you probably don't want to use destructuring, because you don't want to depend on the order in which the submaps occur in the :content of the top-level map. If you can depend on the ordering, then the following would produce your desired result (with your example map previously bound to #'test-map): (let [{tag :tag [{[tag-val] :content} {[value] :content} {t :tag [t-val] :content}] :content} test-map] {tag tag-val :value value t t-val}) This attempts to be somewhat smart in that it figures out that the final key to be put in the result map is :threshold based on the :tag extracted from the last sub-map. So, with consistent structure, that's possible with destructuring -- but it is a bit tedious and fragile. Best to reserve it for the simpler cases, where the exact format of data is likely to remain fixed. (Actually that last part is a must with destructuring.) All in all, I agree with Sean's opinion that an extractor function would be a better fit. Sincerely, Michał -- 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