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 shorter is necessarily better here, but maps are functions, so (defn apply-map-fn [m f & ks] (into m (zipmap ks (map f (map m ks))))) Which, to be fair, doesn't support nil m, but the original didn't support non-keyword keys, so you're not much worse off. Now I want to make it longer. Maps with pure functions can always be combined: (defn apply-map-fn [m f & ks] (into m (zipmap ks (map (comp f m) ks)))) zipmap needlessly builds a map, so (defn apply-map-fn [m f & ks] (into m (map vector ks (map (comp f m) ks)))) Then that other map can fall away: (defn apply-map-fn [m f & ks] (into m (map (juxt identity (comp f m)) ks))) Perhaps not what you were looking for, but hope this helps anyway. More broadly, you might also want to think about what it means if one of ks isn't in m. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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