update README
This commit is contained in:
parent
82f591a5d3
commit
6894578569
1 changed files with 21 additions and 1 deletions
22
README.md
22
README.md
|
|
@ -181,7 +181,7 @@ user> (select [ALL AccountPath :funds]
|
||||||
[50 51 1 2]
|
[50 51 1 2]
|
||||||
```
|
```
|
||||||
|
|
||||||
The next example demonstrates recursive navigation. Here's how to double all the even numbers in a tree:
|
The next examples demonstrate recursive navigation. Here's how to double all the even numbers in a tree:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(defprotocolpath TreeWalker [])
|
(defprotocolpath TreeWalker [])
|
||||||
|
|
@ -194,6 +194,26 @@ The next example demonstrates 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:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
(declarepath TreeValues)
|
||||||
|
|
||||||
|
(providepath TreeValues
|
||||||
|
(if-path vector?
|
||||||
|
[ALL TreeValues]
|
||||||
|
STAY
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
(transform (subselect TreeValues even?)
|
||||||
|
reverse
|
||||||
|
[1 2 [3 [[4]] 5] [6 [7 8] 9 [[10]]]]
|
||||||
|
)
|
||||||
|
|
||||||
|
;; => [1 10 [3 [[8]] 5] [6 [7 4] 9 [[2]]]]
|
||||||
|
```
|
||||||
|
|
||||||
You can make `select` and `transform` work much faster by precompiling your selectors using the `comp-paths` function. There's about a 3x speed difference between the following two invocations of transform:
|
You can make `select` and `transform` work much faster by precompiling your selectors using the `comp-paths` function. There's about a 3x speed difference between the following two invocations of transform:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue