clojure.walk/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.
Examples¶
Note by pesterhazy¶
As of 1.9.0, postwalk passes the k/v pairs of a map to f not, as one might expect, as type clojure.lang.MapEntry but as clojure.lang.PersistentVector (JIRA). As a result, f cannot distinguish k/v pairs from other two-element vectors.
Note by finalfantasia¶
Alex Miller's article "Tree visitors in Clojure" might be helpful in understanding general tree traversal and the usage of clojure.walk/postwalk.
Note by leo-ppp¶
As of 1.9.0, postwalk passes the k/v pairs of a map to f not, as one might expect, as type clojure.lang.MapEntry but as clojure.lang.PersistentVector (JIRA). As a result, f cannot distinguish k/v pairs from other two-element vectors.
This was fixed in 1.10.0, and one can use (map-entry? v) to distinguish a k/v pair from a vector when walking.
Note by jeff303¶
Updated link to "Tree visitors in Clojure", mentioned above (PDF):
https://insideclojure.org/images/j-treevisit-pdf.pdf
See also¶
Content from the matching ClojureDocs page, with authors credited on each contribution.