walk is good but it's not lazy. If you want to preserve laziness you can do:

(defn map-vals
  "transform a map by mapping it's keys to different values."
  [f m]
  (into {} (map (fn [[key val]] [key (f val)]) m)))

This is also nice because you can then write functions whose arguments
are [val] instead of [key val] and ignoring the key.

--Robert McIntyre

On Mon, Sep 6, 2010 at 12:06 PM, Sunil S Nandihalli
<sunil.nandiha...@gmail.com> wrote:
>  (clojure.walk/walk (fn [[key val]] [key (* 2 val)]) identity {:a 1 :b 2})
>
> On Mon, Sep 6, 2010 at 9:26 PM, Sunil S Nandihalli
> <sunil.nandiha...@gmail.com> wrote:
>>
>> Nicolas
>> I am not sure of the performance characteristics.. but you may want to
>> look at
>> (clojure.walk/walk #(do (println "inner : " %) %) #(do (println "outer : "
>> %) %) {:a 1 :b 2})
>>
>> Best regards,
>> Sunil.
>> On Mon, Sep 6, 2010 at 9:10 PM, Nicolas Oury <nicolas.o...@gmail.com>
>> wrote:
>>>
>>> Dear all,
>>>
>>> is there a function to map a function to all values in a map, keeping
>>> the same keys?
>>> Reducing from the seqed map seems a bit slower that what could be done
>>> directly...
>>>
>>> Best,
>>>
>>> Nicolas.
>>>
>>> --
>>> 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
>
> --
> 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

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