You're viewing version 1.2.0 of prewalk-replace. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

prewalk-replace

clojure.walk

  • (prewalk-replace smap form)
Recursively transforms form by replacing keys in smap with their
values. Like clojure/replace but works on any data structure. Does
replacement at the root of the tree first.

2 Examples top

  • user=> (clojure.walk/prewalk-replace '{a b} '(c (d a)))
    (c (d b))
  • (use 'clojure.walk)
    
    (prewalk-replace {:a 1 :b 2} [:a :b])
    ;=> [1 2]
    
    (prewalk-replace {:a 1 :b 2} [:a :b :c])
    ;=> [1 2 :c]
    
    (prewalk-replace {:a 1 :b 2} [:a :b [:a :b] :c])
    ;=> [1 2 [1 2] :c]
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/walk.clj:111 top

(defn prewalk-replace
  "Recursively transforms form by replacing keys in smap with their
  values.  Like clojure/replace but works on any data structure.  Does
  replacement at the root of the tree first."
  {:added "1.1"}
  [smap form]
  (prewalk (fn [x] (if (contains? smap x) (smap x) x)) form))
Vars in clojure.walk/prewalk-replace: contains? defn fn
Used in 0 other vars

Comments top

No comments for prewalk-replace. Log in to add a comment.