What i know
I am familiar with clojure.walk / prewalk and clojure.walk / postwalk
What I want
I need something like clojure.walk / prewalk and clojure.walk / postwalk - but I also want the path to be reached in node, while prewalk / postwalk only gives me nodes, without the actual path.
Example
So, if we had a structure
[ {:cat "Garfield", :dog "DogeCoin"} [:a :b {:site "so"}]]
then I want my function to be called with args:
[] [ {:cat "Garfield", :dog "DogeCoin"} [:a :b {:site "so"}]] [0] {:cat "Garfield", :dog "DogeCoin"} [1] [:a :b {:site "so"}] [0 :cat] "Garfield" ...
Question:
Is there a built in for the above? where does the processing function get both the node and the path (from the root of the node) to node)?
Thanks!
Possible Solution
(based on what fl00r suggested)
(defn pathwalk [f cur-path node] (let [f1 #(pathwalk f (conj cur-path %1) %2)] (f cur-path node) (cond (map? node) (map #(apply f1 %) node) (or (vector? node) (list? node)) (keep-indexed f1 node))))
source share