Hi Laurent,
If you want to use transients, since the keyset is unchanged, it
should perform slightly better when using (transient m) instead of
(transient {}) as the seed to reduce.
Christophe
On Dec 17, 3:46 pm, Laurent PETIT <[email protected]> wrote:
> AFAIK, such a function is still not in clojure core because it's not clear
> to Rich whether f should have one argument (the value), or 2 arguments (key
> + value).
>
> Your version seems good, you can maybe improve it a little bit by using
> transients (not tested):
>
> (persistent!
> (reduce (fn [m [k v]]
> (assoc! m k (f v))) (transient {}) m))
>
> HTH,
>
> --
> Laurent
>
> 2009/12/17 C. Florian Ebeling <[email protected]>
>
> > I was just wondering how a #'map for maps could be done most
> > succinctly. Came up with this:
>
> > (defn mapmap
> > "Map values of map m using function f."
> > [f m]
> > (reduce (fn [m [k v]]
> > (assoc m k (f v))) {} m))
>
> > But there is probably a more straightforward way. What do you use?
>
> > Florian
>
> > --
> > Florian Ebeling
> > [email protected]
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to [email protected]
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > [email protected]<clojure%[email protected]>
> > 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en