Last active
August 29, 2015 14:16
-
-
Save adreyer/184d11209955f4c0ccbf to your computer and use it in GitHub Desktop.
Is there a clojure function to do this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn walk-leaves | |
| "Walks a map applying a function to all non-map nodes(or leaves)" | |
| [m f] | |
| (let [handle-map (fn [[k v]] (if (map? v) [k v] [k (f v)]))] | |
| (postwalk (fn [x] (if (map? x) (into {} (map handle-map x)) x)) m))) | |
| (defn walk-leaves2 | |
| "Explicitly recursive with kitchsink/mapvals" | |
| [m f] | |
| (mapvals #(if (map? %) (map-leaves2 % f) (f %)) m)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment