Skip to content

Instantly share code, notes, and snippets.

@mattfield
Created January 27, 2014 09:41
Show Gist options
  • Save mattfield/8645759 to your computer and use it in GitHub Desktop.
Save mattfield/8645759 to your computer and use it in GitHub Desktop.
Clojure tree walker
(defn tree-searcher
"Parse through every node in a tree and check against
give matcher function. If a match succeeds, return the node.
If no match is found after all recursions, just return the tree.
Also see clojure.walk"
[zipper matcher]
(loop [loc zipper]
(if (zip/end? loc)
(zip/root loc)
(if-let [matcher-result (matcher (zip/node loc))]
(matcher-result)
(recur (zip/next loc))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment