This is 'map-leaves' in our open-source lib plumbing.map (besides the 
option for additional args):

https://github.com/Prismatic/plumbing/blob/master/src/plumbing/map.clj

Cheers, Jason

On Friday, July 26, 2013 8:49:14 AM UTC-7, Yoshinori Kohyama wrote:
>
> Hello group.
>
> I wrote a tiny macro to apply a function to values in lowest levels in a map 
> with arguments.
> Three questions:
>
>    - Does this abstraction have any existing name?
>    - Is there any existing function/macro to do similar things?
>    - Would anyone improve this implementation?
>
>
> (require '[clojure.test :refer (with-test is are run-tests)])
>  
> (with-test
>   (defmacro mapf [f m & args]
>     `((fn f# [n#]
>         (if (map? n#)
>             (into {} (map (fn [[k# v#]] [k# (f# v#)]) n#))
>             (~f n# ~@args)))
>       ~m))
>  
>   (is (= (mapf #(* % %) {:a {:b 3 :c 4} :d 5})
>          {:a {:b 9 :c 16} :d 25}))
>   (is (= (mapf #(+ (* %1 %1) %2) {:a {:b 3 :c 4} :d 5} 1)
>          {:a {:b 10 :c 17} :d 26})))
>
> https://gist.github.com/kohyama/6089899
>
> Thank you in advance.
>
> Y.Kohyama
>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to