2024年Clojure调查!中分享你的想法。

欢迎!请查看关于页面以了解更多关于其工作方式的信息。

0
Collections
已关闭

很简单。就这样

> clojure.walk/walk:
(outer (reduce (fn [r x] (conj r (inner x))) form form))
=> (outer (into form (map inner) form))
(outer (into (empty form) (map inner form)))
=> (outer (into (empty form) (map inner) form))
> clojure.walk/keywordize-keys:
(postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)
=> (postwalk (fn [x] (if (map? x) (into {} (map f) x) x)) m)
> clojure.walk/strigify-keys:
(postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)
=> (postwalk (fn [x] (if (map? x) (into {} (map f) x) x)) m)
我甚至认为这应该用`reduce-kv`替代`keywordize-keys`和`stringify-keys`

    (let [f (fn [[k v]] (if (string? k) [(keyword k) v] [k v]))]
      ;; 仅应用于映射
      (postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m))
...