http://anhinga-travel.livejournal.com/ ([identity profile] anhinga-travel.livejournal.com) wrote in [personal profile] dmm 2016-11-06 08:45 pm (UTC)

a civilized version of the same function

(defn rec-map-mult [n M]
  (reduce (fn [M [k v]]
            (let [new-v
                   (cond
                     (map? v) (rec-map-mult n v)
                     (number? v) (* n v)
                     :else 0)]
               (if (or (= new-v {}) (and (number? new-v) (zero? new-v)))
                   M
                   (assoc M k new-v))))
          {} M))
#'user/rec-map-mult

user=> (rec-map-mult  3 { :a 3 :b {:c 7 :d 9} })
{:b {:d 27, :c 21}, :a 9}

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting