Created
February 23, 2013 08:14
-
-
Save shark8me/5018930 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
| ;the root of the tree. | |
| ;each node has a :self key, the value of which is its own value, and a vector | |
| ;that contains children. | |
| (def mroot {:self 20 :cren [ | |
| {:self 10 :cren [{:self 11} {:self 12}]} | |
| {:self 30 :cren [{:self 31} {:self 32}]} | |
| ]}) | |
| ;create a zipper from the mroot tree. | |
| (defn mzipper [root] | |
| (zip/zipper | |
| #(:cren %) ;branch? | |
| #(:cren %) ;children | |
| (fn [node children] | |
| (with-meta {:self (:self node) :cren (vec children)} (meta node))) | |
| root)) | |
| ;only leaf nodes are listed, the parent nodes 20, 10 ,30 are not. | |
| (is (= '(11 12 31 32) (map :self (map zip/node (leafnodes (mzipper mroot)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment