On 12/31/2012 04:52 AM, clojure@googlegroups.com wrote:
2) Is there a good way of doing this with nested maps? An example:

{ :user { :first "John" :last "Doe" :dob { :month 12 :day 30 :year 2012
:garbage "asdf" } } }

I would want to make sure :dob only contains keys :month, :day, :year.

Hi there,

Disclaimer - I'm very much a beginner with functional programming, Lisp and Clojure. If I understand what you want, I was facing a similar situation and came up with a working solution (I think). I'm pretty sure this is a naïve solution but it kept me be going so far. I'd be happy to hear about other solutions myself.

I did it by walking the data structure using postwalk.

(require '[clojure.walk :as w])

(def data {:user {:first "John" :last "Doe" :dob {:month 12 :day 30 :year 2012 :garbage "asdf" }}})

(w/postwalk #(if (vector? %) (when (or (= :user (first %)) (= :first (first %)) (= :last (first %)) (= :dob (first %)) (= :year (first %)) (= :month (first %)) (= :day (first %)) ) %) %) data)

Or in your case, since you have less keys/values you want to remove you could do.

(w/postwalk #(if (vector? %) (when-not (= :garbage (first %)) %) %) data)

Unfortunately, I have to hard-wire the keys at the moment. Hope this will give you something to work with if you have not got anything yet.

--
GH<www.ghachey.info>

--
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

Reply via email to