I'm not sure I'd call this more readable, but it's another option - using
clojure.walk

(defn deep-update-vals
  [m f & args]
  (let [f (fn [[k v]] (if (map? v) [k v] [k (apply f v args)]))]
    (clojure.walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))


On Fri, Jul 26, 2013 at 2:06 PM, Jay Fields <j...@jayfields.com> wrote:

> I defined update-vals in jry:
> https://github.com/jaycfields/jry/blob/master/src/clojure/jry.clj#L74-L75
>
> It doesn't traverse nested maps, but I haven't ever needed that ability
> either.
>
> 1) I've never seen a name for that.
> 2) not in core. I'm sure it's been written 50 times in various helper libs.
> 3) I'd probably write it like below, but I'm not convinced it's any better.
>
> (defn deep-update-vals
>   [m f & args]
>   (if (map? m)
>     (reduce-kv #(assoc %1 %2 (apply deep-update-vals %3 f args)) {} m)
>     (apply f m args)))
>
>
> On Fri, Jul 26, 2013 at 1:31 PM, Yoshinori Kohyama <yykohy...@gmail.com>wrote:
>
>> Thank you Gary.
>> There's no reason why this need to be a macro.
>> It has rewritten as a function.
>>
>> And I'd still like to hear any response about the same three questions.
>>
>>
>> (require '[clojure.test :refer (with-test is run-tests)])
>>
>>
>> (with-test
>>   (defn mapf [f m & args]
>>
>>     ((fn g [n]
>>        (if (map? n)
>>
>>            (into {} (map (fn [[k v]] [k (g v)]) n))
>>
>>            (apply 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})))
>>
>>
>>  --
>> --
>> 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.
>>
>>
>>
>
>

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