This is a generic solution using clojure.walk, the problem can be
solved in many other ways...

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

(defn remove-sour
  "Remove all :sour foods from the table."
  [table]
  (let [xform (fn [[k v]] (when-not (= k :sour) [k v]))]
    (walk/postwalk (fn [x] (if (map? x) (into {} (keep xform x)) x)) table)))

Hope this helps.

Regards,
BG

On Mon, May 28, 2012 at 1:25 PM, Z.A <zahmed...@gmail.com> wrote:
> Thanks BG . But can we do it without hard wiring the structure of hash
> map in our function. Can't we just take in any hash map and look for
> any :sour key anywhere and remove it. I want to learn a generic hash
> map processing technique.
>
> On May 28, 3:46 am, Baishampayan Ghose <b.gh...@gmail.com> wrote:
>> This is the trivial solution, by the way -
>>
>> (update-in dining-table [:eatables :fruits] #(dissoc % :sour))
>>
>> Regards,
>> BG
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Mon, May 28, 2012 at 1:11 PM, Z.A <zahmed...@gmail.com> wrote:
>> > Hi
>> > I am trying to create a function to remove all :sour eatables from my
>> > dining table but so far only getting sour results.
>>
>> > (def dining-table {:drinks {:cold "coke", :hot "tea"}, :eatables
>> > {:fruits {:sour "lemon", :sweet "mango"}}})
>>
>> > (the-function-i-want   dining-table)  should give the following output
>>
>> > {:drinks {:cold "coke", :hot "tea"}, :eatables {:fruits { :sweet
>> > "mango"}}}
>>
>> > thank you all.
>> > Zubair
>>
>> > --
>> > 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
>>
>> --
>> Baishampayan Ghose
>> b.ghose at gmail.com
>
> --
> 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



-- 
Baishampayan Ghose
b.ghose at gmail.com

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