Skip to content

Instantly share code, notes, and snippets.

@mattfield
Created January 27, 2014 09:41

Revisions

  1. mattfield created this gist Jan 27, 2014.
    12 changes: 12 additions & 0 deletions walker.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    (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))))))