writing Clojure snippets
Sep. 25th, 2016 11:51 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
(defn rec-map-mult [scalar rec-map-of-ns] (if (map? rec-map-of-ns) (into {} (map #(vector (first %1) (rec-map-mult scalar (second %1)) ) rec-map-of-ns ) ) (if (number? rec-map-of-ns) (* scalar rec-map-of-ns) 0 ) ) ) user=> (rec-map-mult 3 { :a 3 :b {:c 7 :d 9} }) {:a 9, :b {:c 21, :d 27}}
a civilized version of the same function
Date: 2016-11-06 08:45 pm (UTC)