change params-reset to backtrack in params-idx by number of needed params of its path, add test that verifies composability

This commit is contained in:
Nathan Marz 2016-01-30 12:41:29 -08:00
parent cf0dae3699
commit b16dbdfdd2
2 changed files with 10 additions and 4 deletions

View file

@ -132,15 +132,16 @@
(defn params-reset [params-path]
;; TODO: error if not paramsneededpath
(let [s (i/params-needed-selector params-path)
t (i/params-needed-transformer params-path)]
t (i/params-needed-transformer params-path)
needed (i/num-needed-params params-path)]
(i/->ParamsNeededPath
(i/->TransformFunctions
i/RichPathExecutor
(fn [params params-idx vals structure next-fn]
(s params 0 vals structure next-fn)
(s params (- params-idx needed) vals structure next-fn)
)
(fn [params params-idx vals structure next-fn]
(t params 0 vals structure next-fn)
(t params (- params-idx needed) vals structure next-fn)
))
0)))
@ -209,7 +210,7 @@
(select* [this structure next-fn]
(next-fn (set/intersection structure aset)))
(transform* [this structure next-fn]
(let [subset (set/intersection structure aset)
(let [subset (set/intersection structure aset)
newset (next-fn subset)]
(-> structure
(set/difference subset)

View file

@ -632,6 +632,11 @@
(s/setval (map-key-walker :b) "X" {:a {:c {:b {:d 1}}}}))
)
(deftest recursive-params-composable-path-test
(let [p (s/comp-paths s/keypath map-key-walker)]
(is (= [1] (s/select (p 1 :a) [{:a 3} {:a 1} {:a 2}])))
))
(deftest all-map-test
(is (= {3 3} (s/transform [s/ALL s/FIRST] inc {2 3})))
(is (= {3 21 4 31} (s/transform [s/ALL s/ALL] inc {2 20 3 30})))