update readme examples

This commit is contained in:
Nathan Marz 2016-09-04 15:00:54 -04:00
parent 18d7cc0f3d
commit e33daed812

View file

@ -283,7 +283,7 @@ user> (select [ALL AccountPath :funds]
[50 51 1 2] [50 51 1 2]
``` ```
The next examples demonstrate recursive navigation. Here's how to double all the even numbers in a tree: The next examples demonstrate recursive navigation. Here's one way to double all the even numbers in a tree:
```clojure ```clojure
(defprotocolpath TreeWalker []) (defprotocolpath TreeWalker [])
@ -296,23 +296,21 @@ The next examples demonstrate recursive navigation. Here's how to double all the
;; => [:a 1 [4 [[[3]]] :e] [8 5 [12 7]]] ;; => [:a 1 [4 [[[3]]] :e] [8 5 [12 7]]]
``` ```
Here's how to reverse the positions of all even numbers in a tree (with order based on a depth first search). This example uses conditional navigation instead of protocol paths to do the walk and is much more efficient than using `walker`: Here's how to reverse the positions of all even numbers in a tree (with order based on a depth first search). This example uses conditional navigation instead of protocol paths to do the walk:
```clojure ```clojure
(declarepath TreeValues) (def TreeValues
(recursive-path [] p
(providepath TreeValues
(if-path vector? (if-path vector?
[ALL TreeValues] [ALL p]
STAY STAY
)) )))
(transform (subselect TreeValues even?) (transform (subselect TreeValues even?)
reverse reverse
[1 2 [3 [[4]] 5] [6 [7 8] 9 [[10]]]] [1 2 [3 [[4]] 5] [6 [7 8] 9 [[10]]]]
) )
;; => [1 10 [3 [[8]] 5] [6 [7 4] 9 [[2]]]] ;; => [1 10 [3 [[8]] 5] [6 [7 4] 9 [[2]]]]
``` ```