Skip to content

Instantly share code, notes, and snippets.

@nathanmarz
Created January 11, 2016 18:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanmarz/40f14d693da3d7fa6faf to your computer and use it in GitHub Desktop.
Save nathanmarz/40f14d693da3d7fa6faf to your computer and use it in GitHub Desktop.
Recursive navigation with Specter
(use 'com.rpl.specter)
(use 'com.rpl.specter.macros)
(defprotocolpath TreeWalker [])
(extend-protocolpath TreeWalker
Object nil
clojure.lang.PersistentVector [ALL TreeWalker])
(select [TreeWalker number?] [:a 1 [2 [[[3]]] :e] [4 5 [6 7]]])
;; => [1 2 3 4 5 6 7]
(transform [TreeWalker number?] inc [:a 1 [2 [[[3]]] :e] [4 5 [6 7]]])
;; => [:a 2 [3 [[[4]]] :e] [5 6 [7 8]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment