Created
November 3, 2012 17:25
-
-
Save hughfdjackson/4008021 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (require '[clojure.zip :as z]) | |
| ; make a tree using vectors | |
| (def data [1 [2 3]]) ; | |
| data ; => [1 [2 3]] | |
| ; make a zipped version | |
| (def dz (z/vector-zip data)) | |
| dz ; => [[1 [2 3]] nil] (nil for where the cursor data will be; but we haven't traversed anywhere) | |
| ; traverse it! (the -> macro is like an inverse compose) | |
| (-> dz z/down z/right z/down) ; => [2 {:l [], :pnodes [[1 [2 3]] [2 3]], :ppath {:l [1], :pnodes [[1 [2 3]]], :ppath nil, :r nil}, :r (3)}] | |
| ; get the node back out from the point of the cursor | |
| (-> dz z/down z/right z/down z/node) ; => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment