postwalk

clojure.walk

  • (postwalk f form)
Performs a depth-first, post-order traversal of form. Calls f on
each sub-form, uses f's return value in place of the original.
Recognizes all Clojure data structures. Consumes seqs as with doall.

2 Examples top

  • (use 'clojure.walk)
    (let [counter (atom -1)]
       (postwalk (fn [x]
                    [(swap! counter inc) x])
                  {:a 1 :b 2}))
    
    => [6 {2 [[0 :a] [1 1]], 5 [[3 :b] [4 2]]}] 
  • ;;example of removing namespaces from all keys in a nested data structure
    (def thing {:page/tags [{:tag/category "lslsls"}]})
    (postwalk #(if(keyword? %)(keyword (name %)) %) thing)
    {:tags [{:category "lslsls"}]}
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:50 top

(defn postwalk
  "Performs a depth-first, post-order traversal of form.  Calls f on
  each sub-form, uses f's return value in place of the original.
  Recognizes all Clojure data structures. Consumes seqs as with doall."
  {:added "1.1"}
  [f form]
  (walk (partial postwalk f) f form))
Vars in clojure.walk/postwalk:
Used in 0 other vars

Comments top

No comments for postwalk. Log in to add a comment.