add vtransform
This commit is contained in:
parent
9515582a19
commit
0ceda21151
4 changed files with 19 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
## 1.0.6-SNAPSHOT
|
## 1.0.6-SNAPSHOT
|
||||||
|
|
||||||
* Add `vterminal` that takes in collected vals as vector in first argument rather than spliced into full argument list.
|
* Add `vtransform` variant of `transform` that takes in collected values as a vector in the first argument rather than spliced into argument list.
|
||||||
|
* Add `vterminal` that takes in collected vals as vector in first argument rather than spliced into argument list.
|
||||||
|
|
||||||
## 1.0.5
|
## 1.0.5
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -349,6 +349,12 @@
|
||||||
[apath transform-fn structure]
|
[apath transform-fn structure]
|
||||||
`(i/compiled-transform* (path ~apath) ~transform-fn ~structure))
|
`(i/compiled-transform* (path ~apath) ~transform-fn ~structure))
|
||||||
|
|
||||||
|
(defmacro vtransform
|
||||||
|
"Navigates to each value specified by the path and replaces it by the result of running
|
||||||
|
the transform-fn on two arguments: the collected values as a vector, and the navigated value."
|
||||||
|
[apath transform-fn structure]
|
||||||
|
`(i/compiled-vtransform* (path ~apath) ~transform-fn ~structure))
|
||||||
|
|
||||||
(defmacro multi-transform
|
(defmacro multi-transform
|
||||||
"Just like `transform` but expects transform functions to be specified
|
"Just like `transform` but expects transform functions to be specified
|
||||||
inline in the path using `terminal` or `vterminal`. Error is thrown if navigation finishes
|
inline in the path using `terminal` or `vterminal`. Error is thrown if navigation finishes
|
||||||
|
|
@ -552,6 +558,10 @@
|
||||||
(def ^{:doc "Version of transform that takes in a path precompiled with comp-paths"}
|
(def ^{:doc "Version of transform that takes in a path precompiled with comp-paths"}
|
||||||
compiled-transform i/compiled-transform*)
|
compiled-transform i/compiled-transform*)
|
||||||
|
|
||||||
|
(def ^{:doc "Version of vtransform that takes in a path precompiled with comp-paths"}
|
||||||
|
compiled-vtransform i/compiled-vtransform*)
|
||||||
|
|
||||||
|
|
||||||
(defn transform*
|
(defn transform*
|
||||||
"Navigates to each value specified by the path and replaces it by the result of running
|
"Navigates to each value specified by the path and replaces it by the result of running
|
||||||
the transform-fn on it"
|
the transform-fn on it"
|
||||||
|
|
|
||||||
|
|
@ -412,6 +412,9 @@
|
||||||
(fn [vals structure]
|
(fn [vals structure]
|
||||||
(terminal* transform-fn vals structure))))
|
(terminal* transform-fn vals structure))))
|
||||||
|
|
||||||
|
(defn compiled-vtransform* [nav transform-fn structure]
|
||||||
|
(exec-transform* nav [] structure transform-fn))
|
||||||
|
|
||||||
(defn fn-invocation? [f]
|
(defn fn-invocation? [f]
|
||||||
(or #?(:clj (instance? clojure.lang.Cons f))
|
(or #?(:clj (instance? clojure.lang.Cons f))
|
||||||
#?(:clj (instance? clojure.lang.LazySeq f))
|
#?(:clj (instance? clojure.lang.LazySeq f))
|
||||||
|
|
|
||||||
|
|
@ -1656,6 +1656,10 @@
|
||||||
{:a {:b 3}})))
|
{:a {:b 3}})))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(deftest vtransform-test
|
||||||
|
(is (= {:a 6} (vtransform [:a (s/putval 2) (s/putval 3)] (fn [vs v] (+ v (reduce + vs))) {:a 1})))
|
||||||
|
)
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(do
|
(do
|
||||||
(defprotocolpath FooPP)
|
(defprotocolpath FooPP)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue