walker and codewalker can now be late-bound parameterized

This commit is contained in:
Nathan Marz 2015-09-24 11:55:24 -05:00
parent 1f55a0e701
commit 9fcd9e5ed4
3 changed files with 18 additions and 23 deletions

View file

@ -2,6 +2,7 @@
* view can now be late-bound parameterized
* 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
* walker and codewalker can now be late-bound parameterized
## 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.

View file

@ -169,9 +169,21 @@
(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
"Navigates to a view of the current sequence that only contains elements that

View file

@ -407,7 +407,7 @@
(set-last-list l val)
))
(defn- walk-until [pred on-match-fn structure]
(defn walk-until [pred on-match-fn structure]
(if (pred structure)
(on-match-fn structure)
(walk/walk (partial walk-until pred on-match-fn) identity structure)
@ -418,7 +418,7 @@
(instance? clojure.lang.LazySeq f)
(list? f)))
(defn- codewalk-until [pred on-match-fn structure]
(defn codewalk-until [pred on-match-fn structure]
(if (pred structure)
(on-match-fn structure)
(let [ret (walk/walk (partial codewalk-until pred on-match-fn) identity structure)]
@ -455,7 +455,7 @@
(not (not-selected?* compiled-path structure)))
;; returns vector of all results
(defn- walk-select [pred continue-fn structure]
(defn walk-select [pred continue-fn structure]
(let [ret (mutable-cell [])
walker (fn this [structure]
(if (pred structure)
@ -519,24 +519,6 @@
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]
(next-fn (-> structure vec (subvec start end))))