Re: Is there a standard function transforming a map's vals

2009-10-12 Thread Christophe Grand
Note that if you're only interested in using the resulting map as a function, (comp f map) works well (you can throw memoize in for good measure). On Sun, Oct 11, 2009 at 2:40 AM, samppi wrote: > > Is there a function in the standard libraries that's equivalent to > this: > > (defn transform-ma

Re: Is there a standard function transforming a map's vals

2009-10-11 Thread John Harrop
On Sun, Oct 11, 2009 at 3:17 PM, Daniel Werner < daniel.d.wer...@googlemail.com> wrote: > On Oct 11, 6:02 am, samppi wrote: > > Oops, you're right; I was thinking about something else. And I have > > another mistake in my function too—I meant: > > > > (defn transform-map [f a-map] > > (into

Re: Is there a standard function transforming a map's vals

2009-10-11 Thread Stuart Sierra
On Oct 10, 8:40 pm, samppi wrote: > (defn transform-map [f a-map] > (into {} (map #(vector (key %) (f (val %))) a-map))) I always find map transformations easier to write with reduce: (defn transform-map [f mm] (reduce (fn [m [k v]] (assoc m k (f v))) {} mm)) -SS --~--~-~--~---

Re: Is there a standard function transforming a map's vals

2009-10-11 Thread Daniel Werner
On Oct 11, 6:02 am, samppi wrote: > Oops, you're right; I was thinking about something else. And I have > another mistake in my function too—I meant: > > (defn transform-map [f a-map] > (into {} (map #(vector (key %) (f (val %))) a-map))) > > It's unfortunate that it's not in any standard l

Re: Is there a standard function transforming a map's vals

2009-10-10 Thread samppi
Oops, you're right; I was thinking about something else. And I have another mistake in my function too—I meant: (defn transform-map [f a-map] (into {} (map #(vector (key %) (f (val %))) a-map))) It's unfortunate that it's not in any standard library yet. I've used this function in every si

Re: Is there a standard function transforming a map's vals

2009-10-10 Thread Sean Devlin
The short answer is no. This came up on the dev list here: http://groups.google.com/group/clojure-dev/browse_thread/thread/4b20e40d83095c67# Oh, and I'd write the function slightly differently (defn transform-map [f a-map] ...) The f implies a mapping operation. pred implies a filter operati

Is there a standard function transforming a map's vals

2009-10-10 Thread samppi
Is there a function in the standard libraries that's equivalent to this: (defn transform-map [pred a-map] (into {} (map (comp pred val) a-map))) (is (= {:a 4, :b 3} (transform-map inc {:a 3, :b 2}))) It's not like I can't write this myself; I use this a lot, though, and I'm w