diff --git a/CHANGES.md b/CHANGES.md index 149daa5..8e4379f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/src/com/rpl/specter.cljc b/src/com/rpl/specter.cljc index 04cf692..c781db2 100644 --- a/src/com/rpl/specter.cljc +++ b/src/com/rpl/specter.cljc @@ -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 diff --git a/src/com/rpl/specter/impl.cljc b/src/com/rpl/specter/impl.cljc index da85552..32f4f36 100644 --- a/src/com/rpl/specter/impl.cljc +++ b/src/com/rpl/specter/impl.cljc @@ -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))))