You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now the map-keys function only maps the top keys, i.e:
(map-keys str {:a {:b"c"}})
=> {"a" {:b"c"}}
Can we consider adding something like map-all-keys, map-all-values, etc that will traverse a nested structure? The use case here could be transforming a clojurefied map into a formatted JSON object or vise versa for example.
(defntransform-keys"Recursively transforms all map keys in coll with t."
[t coll]
(let [f (fn [[k v]] [(t k) v])]
(clojure.walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) coll)))
(transform-keys ->kebab-case-keyword {"oneTwo"12"threeFour" {"fiveSix"56}})
=> {:three-four {:five-six56}, :one-two12}
OR
(defntransform-keys"Recursively transforms all map keys in m with f."
[f m]
(letfn [(mapper [[k v]] [(f k) (if (map? v) (map-keys f v) v)])]
(into {} (map mapper m))))
(transform-keys ->kebab-case-keyword {"oneTwo"12"threeFour" {"fiveSix"56}})
=> {:three-four {:five-six56}, :one-two12}
The text was updated successfully, but these errors were encountered:
Right now the map-keys function only maps the top keys, i.e:
Can we consider adding something like map-all-keys, map-all-values, etc that will traverse a nested structure? The use case here could be transforming a clojurefied map into a formatted JSON object or vise versa for example.
OR
The text was updated successfully, but these errors were encountered: