fix multi-path + val collection and minor problem in if-path

This commit is contained in:
Nathan Marz 2016-06-16 09:42:24 -04:00
parent 36f0e63d56
commit 66f555ab73
4 changed files with 46 additions and 24 deletions

View file

@ -672,18 +672,25 @@
"A path that branches on multiple paths. For updates, "A path that branches on multiple paths. For updates,
applies updates to the paths in order." applies updates to the paths in order."
[& paths] [& paths]
(variable-pathed-nav [compiled-paths paths] (let [paths-comp (mapv i/comp-paths* (vec paths))
(select* [this structure next-fn] all-needed (mapv i/num-needed-params paths-comp)
(doseqres NONE [c compiled-paths] idx-deltas (vec (cons 0 (reductions + all-needed)))
(i/compiled-traverse* c next-fn structure) extracted (mapv i/extract-rich-tfns paths-comp)
)) sel-info (mapv vector (mapv first extracted) idx-deltas)
(transform* [this structure next-fn] tran-info (mapv vector (mapv second extracted) idx-deltas)]
(reduce (richnav (reduce + 0 all-needed)
(fn [structure path] (select* [params params-idx vals structure next-fn]
(compiled-transform path next-fn structure)) (doseqres NONE [[s delta] sel-info]
structure (s params (+ params-idx delta) vals structure next-fn)
compiled-paths ))
)))) (transform* [params params-idx vals structure next-fn]
(reduce
(fn [structure [t delta]]
(t params (+ params-idx delta) vals structure next-fn)
)
structure
tran-info
)))))
(defpathedfn stay-then-continue (defpathedfn stay-then-continue
"Navigates to the current element and then navigates via the provided path. "Navigates to the current element and then navigates via the provided path.

View file

@ -1095,7 +1095,7 @@
tran (if test? tran (if test?
then-t then-t
else-t) else-t)
idx (if test? params-idx then-params)] idx (if test? params-idx (+ params-idx then-params))]
(tran params (tran params
idx idx
vals vals
@ -1507,3 +1507,8 @@
[(:selector tfns) (:transformer tfns)] [(:selector tfns) (:transformer tfns)]
)) ))
(defn mk-jump-next-fn [next-fn init-idx total-params]
(let [jumped (+ init-idx total-params)]
(fn [params params-idx vals structure]
(next-fn params jumped vals structure)
)))

View file

@ -130,15 +130,25 @@
the next params index, the collected vals, and finally the next structure. the next params index, the collected vals, and finally the next structure.
This is the lowest level way of making navigators." This is the lowest level way of making navigators."
[num-params impl1 impl2] [num-params impl1 impl2]
(let [[select-impl transform-impl] (determine-params-impls impl1 impl2)] (let [[[s-params & s-body] [t-params & t-body]] (determine-params-impls impl1 impl2)
`(let [tfns# (i/->TransformFunctions s-next-fn-sym (last s-params)
s-pidx-sym (second s-params)
t-next-fn-sym (last t-params)
t-pidx-sym (second t-params)
]
`(let [num-params# ~num-params
tfns# (i/->TransformFunctions
i/RichPathExecutor i/RichPathExecutor
(fn ~@select-impl) (fn ~s-params
(fn ~@transform-impl) (let [~s-next-fn-sym (i/mk-jump-next-fn ~s-next-fn-sym ~s-pidx-sym num-params#)]
~@s-body))
(fn ~t-params
(let [~t-next-fn-sym (i/mk-jump-next-fn ~t-next-fn-sym ~t-pidx-sym num-params#)]
~@t-body))
)] )]
(if (zero? ~num-params) (if (zero? num-params#)
(i/no-params-compiled-path tfns#) (i/no-params-compiled-path tfns#)
(i/->ParamsNeededPath tfns# ~num-params) (i/->ParamsNeededPath tfns# num-params#)
)))) ))))
(defmacro paramsfn [params [structure-sym] & impl] (defmacro paramsfn [params [structure-sym] & impl]

View file

@ -373,11 +373,11 @@
(is (empty? (select (s/if-path odd? (s/view inc)) 2))) (is (empty? (select (s/if-path odd? (s/view inc)) 2)))
(is (= [6 2 10 6 14] (is (= [6 2 10 6 14]
(transform [(s/putval 2) (transform [(s/putval 2)
s/ALL s/ALL
(s/if-path odd? [(s/view inc) (s/view inc)] (s/view dec))] (s/if-path odd? [(s/view inc) (s/view inc)] (s/view dec))]
* *
[1 2 3 4 5] [1 2 3 4 5]
))) )))
(is (= 2 (is (= 2
(transform [(s/putval 2) (transform [(s/putval 2)
(s/if-path odd? (s/view inc))] (s/if-path odd? (s/view inc))]