> 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 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? > > Thanks in advance Clojure smarties. =)
Your solution looks quite good to me, although I would get rid of the double map by composing the two functions - (defn apply-map-fn [m f & ks] (into m (zipmap ks (map (comp f #(m %)) ks)))) Regards, BG -- 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