2014-09-11 75 views

回答

2

我已使用clojure.walk/postwalk來完成此操作。

(defn transform-keys 
    "Recursively transforms all map keys in coll with the transform-key fn." 
    [transform-key coll] 
    (letfn [(transform [x] (if (map? x) 
          (into {} (map (fn [[k v]] [(transform-key k) v]) x)) 
          x))] 
    (walk/postwalk transform coll))) 

第一個參數是一個函數,該函數接受現有密鑰並返回新密鑰。在你的情況下,你可以將關鍵字轉換爲字符串,用連字符代替下劃線,並將其轉換回關鍵字。

https://gist.github.com/jeremyheiler/fe9256e540121e771285