(defn mapmap [fn m] (into {} (map #(vector (first %) (fn (second %))) m)))
On Sun, Mar 22, 2009 at 1:10 PM, Jon Nadal <jon.na...@gmail.com> wrote: > > I often need to map a function over the values of a map while > preserving keys--something like: > > [code] > (defn mapmap [fn m] > (let [k (keys m) > v (map fn (vals m))] > (zipmap k v))) > > (mapmap inc {:a 0, :b 1}) > [/code] > > Is there a more concise way to do this in Clojure? If not, is this > something that might be worth putting in the contrib? > > -Jon > > > > -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---