On Tue, Dec 7, 2010 at 12:04 AM, Alex Baranosky
<[email protected]> wrote:
> I think it will be fun to come up with a solution that will work with n
> maps:
> (defn multi-fmap [f &maps]
> ...)
> i.e.
> (multi-fmap #(+ %1 %1 %2 ) {:a 1 :b 2} {:a 3 :b 4}) => {:a 5 :b 8}
> (multi-fmap #(+ %1 %2 %3 ) {:a 1 :b 2} {:a 3 :b 4} {:a 5 :b 6}) => {:a 9 :b
> 12}
(defn multi-fmap [f & maps]
(into {}
(for [k (keys (first maps))]
[k (apply f (map #(get % k) maps))])))
works for your two test-cases. It assumes that the keys you're
interested in are exactly the keys of the first map; if any map is
missing a key the function will get a nil argument in the position
corresponding to that map when computing the result's value for that
key.
--
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