walker and codewalker can now be late-bound parameterized
This commit is contained in:
parent
1f55a0e701
commit
9fcd9e5ed4
3 changed files with 18 additions and 23 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
* view can now be late-bound parameterized
|
* view can now be late-bound parameterized
|
||||||
* Added a late-bound parameterized version of using a function as a selector called "pred"
|
* Added a late-bound parameterized version of using a function as a selector called "pred"
|
||||||
* Added paramsfn helper macro for defining filter functions that take late-bound parameters
|
* Added paramsfn helper macro for defining filter functions that take late-bound parameters
|
||||||
|
* walker and codewalker can now be late-bound parameterized
|
||||||
|
|
||||||
## 0.7.0
|
## 0.7.0
|
||||||
* Added late-bound parameterization feauture: allows selectors that require params to be precompiled without the parameters, and the parameters are supplied later in bulk. This effectively enables Specter to be used in any situation with very high performance.
|
* Added late-bound parameterization feauture: allows selectors that require params to be precompiled without the parameters, and the parameters are supplied later in bulk. This effectively enables Specter to be used in any situation with very high performance.
|
||||||
|
|
|
||||||
|
|
@ -169,9 +169,21 @@
|
||||||
|
|
||||||
(def END (srange-dynamic count count))
|
(def END (srange-dynamic count count))
|
||||||
|
|
||||||
(defn walker [afn] (i/->WalkerStructurePath afn))
|
(defparamspath
|
||||||
|
walker
|
||||||
|
[afn]
|
||||||
|
(select* [this structure next-fn]
|
||||||
|
(i/walk-select afn next-fn structure))
|
||||||
|
(transform* [this structure next-fn]
|
||||||
|
(i/walk-until afn next-fn structure)))
|
||||||
|
|
||||||
(defn codewalker [afn] (i/->CodeWalkerStructurePath afn))
|
(defparamspath
|
||||||
|
codewalker
|
||||||
|
[afn]
|
||||||
|
(select* [this structure next-fn]
|
||||||
|
(i/walk-select afn next-fn structure))
|
||||||
|
(transform* [this structure next-fn]
|
||||||
|
(i/codewalk-until afn next-fn structure)))
|
||||||
|
|
||||||
(defn filterer
|
(defn filterer
|
||||||
"Navigates to a view of the current sequence that only contains elements that
|
"Navigates to a view of the current sequence that only contains elements that
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,7 @@
|
||||||
(set-last-list l val)
|
(set-last-list l val)
|
||||||
))
|
))
|
||||||
|
|
||||||
(defn- walk-until [pred on-match-fn structure]
|
(defn walk-until [pred on-match-fn structure]
|
||||||
(if (pred structure)
|
(if (pred structure)
|
||||||
(on-match-fn structure)
|
(on-match-fn structure)
|
||||||
(walk/walk (partial walk-until pred on-match-fn) identity structure)
|
(walk/walk (partial walk-until pred on-match-fn) identity structure)
|
||||||
|
|
@ -418,7 +418,7 @@
|
||||||
(instance? clojure.lang.LazySeq f)
|
(instance? clojure.lang.LazySeq f)
|
||||||
(list? f)))
|
(list? f)))
|
||||||
|
|
||||||
(defn- codewalk-until [pred on-match-fn structure]
|
(defn codewalk-until [pred on-match-fn structure]
|
||||||
(if (pred structure)
|
(if (pred structure)
|
||||||
(on-match-fn structure)
|
(on-match-fn structure)
|
||||||
(let [ret (walk/walk (partial codewalk-until pred on-match-fn) identity structure)]
|
(let [ret (walk/walk (partial codewalk-until pred on-match-fn) identity structure)]
|
||||||
|
|
@ -455,7 +455,7 @@
|
||||||
(not (not-selected?* compiled-path structure)))
|
(not (not-selected?* compiled-path structure)))
|
||||||
|
|
||||||
;; returns vector of all results
|
;; returns vector of all results
|
||||||
(defn- walk-select [pred continue-fn structure]
|
(defn walk-select [pred continue-fn structure]
|
||||||
(let [ret (mutable-cell [])
|
(let [ret (mutable-cell [])
|
||||||
walker (fn this [structure]
|
walker (fn this [structure]
|
||||||
(if (pred structure)
|
(if (pred structure)
|
||||||
|
|
@ -519,24 +519,6 @@
|
||||||
structure
|
structure
|
||||||
((.-setter this) structure (next-fn ((.-getter this) structure))))))
|
((.-setter this) structure (next-fn ((.-getter this) structure))))))
|
||||||
|
|
||||||
(deftype WalkerStructurePath [afn])
|
|
||||||
|
|
||||||
(extend-protocol p/StructurePath
|
|
||||||
WalkerStructurePath
|
|
||||||
(select* [^WalkerStructurePath this structure next-fn]
|
|
||||||
(walk-select (.-afn this) next-fn structure))
|
|
||||||
(transform* [^WalkerStructurePath this structure next-fn]
|
|
||||||
(walk-until (.-afn this) next-fn structure)))
|
|
||||||
|
|
||||||
(deftype CodeWalkerStructurePath [afn])
|
|
||||||
|
|
||||||
(extend-protocol p/StructurePath
|
|
||||||
CodeWalkerStructurePath
|
|
||||||
(select* [^CodeWalkerStructurePath this structure next-fn]
|
|
||||||
(walk-select (.-afn this) next-fn structure))
|
|
||||||
(transform* [^CodeWalkerStructurePath this structure next-fn]
|
|
||||||
(codewalk-until (.-afn this) next-fn structure)))
|
|
||||||
|
|
||||||
(defn srange-select [structure start end next-fn]
|
(defn srange-select [structure start end next-fn]
|
||||||
(next-fn (-> structure vec (subvec start end))))
|
(next-fn (-> structure vec (subvec start end))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue