clojure.walk/prewalk¶ View this page on ClojureDocs Type: function Added: Clojure 1.1 Examples: 3 Runnable: 0 ([f form]) Like postwalk, but does pre-order traversal. Examples¶ by srid on 2011-11-16 . May have evaluation errors. ▶ ;; From http://stackoverflow.com/questions/8089074/idiomatically-iterating-over-a-2-or-higher-dimensional-sequence-in-clojure/8091544#8091544 (def matrix [[1 2 3] [4 5 6] [7 8 9]]) (use 'clojure.walk :only [prewalk]) (prewalk #(if (number? %) (inc %) %) matrix) => [[2 3 4] [5 6 7] [8 9 10]] by cljlc on 2018-02-19 . May have evaluation errors. ▶ ;; an example to show the differences between postwalk and prewalk ;; (see the counterpart at postwalk) (let [counter (atom 0) print-touch (fn [x] (print (swap! counter inc) ":" (pr-str x) "→ ")) change-type (fn [x] (let [new-x (if (vector? x) (apply list x) (str x))] (prn new-x) new-x))] (clojure.walk/prewalk (fn [x] (print-touch x) (change-type x)) [:a [:ba :bb] :c])) ;; printed output: 1 : [:a [:ba :bb] :c] → (:a [:ba :bb] :c) 2 : :a → ":a" 3 : [:ba :bb] → (:ba :bb) 4 : :ba → ":ba" 5 : :bb → ":bb" 6 : :c → ":c" ;; returned value: => (":a" (":ba" ":bb") ":c") by dan-f on 2018-12-07 . May have evaluation errors. ▶ ;; A simpler illustration of the difference between postwalk and prewalk… (defn walking-fn [x] (cond (number? x) (* 10 x) (vector? x) (map inc x))) (walk/postwalk walking-fn [1 2 3]) ;; => (11 21 31) (walk/prewalk walking-fn [1 2 3]) ;; => (20 30 40) See also¶ clojure.walk/postwalk (1) clojure.walk/prewalk-demo clojure.walk/prewalk-replace Content from the matching ClojureDocs page, with authors credited on each contribution.