Re: updating some values in map

2011-10-23 Thread Mike
Hey thanks Stephen and BG, and Jonas! Cool tricks I hadn't thought of. I'm especially going to study this one; I had thought update-in might be applicable but I wasn't sure how (still learning it). I appreciate it! Mike On Oct 23, 2:10 am, Jonas wrote: > Another way to do it > > (defn apply-m

Re: updating some values in map

2011-10-22 Thread Jonas
Another way to do it (defn apply-map-fn [m f & ks] (reduce #(update-in %1 [%2] f) m ks)) -- 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 -

Re: updating some values in map

2011-10-22 Thread Baishampayan Ghose
> Hey, I've got a case where I want to apply a function to *some* values > in a map but not all.  For instance: > > (def m { :a 1 :b 1 :c 1 :d 1 }) > > (defn apply-map-fn [m f & ks] >     (into m (zipmap ks (map f (map #(% m) ks) > > (apply-map-fn m inc :a :c) > > => { :a 2 :b 1 :c 2 :d 1 } > >

Re: updating some values in map

2011-10-22 Thread Stephen Compall
On Sat, 2011-10-22 at 12:55 -0700, Mike wrote: > (defn apply-map-fn [m f & ks] > (into m (zipmap ks (map f (map #(% m) ks) > > Is there a more idiomatic way to do this? Something shorter than > apply-map-fn I wrote? I.e. something where I don't have to use apply- > map-fn? I'm not sure

updating some values in map

2011-10-22 Thread Mike
Hey, I've got a case where I want to apply a function to *some* values in a map but not all. For instance: (def m { :a 1 :b 1 :c 1 :d 1 }) (defn apply-map-fn [m f & ks] (into m (zipmap ks (map f (map #(% m) ks) (apply-map-fn m inc :a :c) => { :a 2 :b 1 :c 2 :d 1 } Is there a more id