fix if-path/selected?/not-selected? so that vals are passed along to condition paths
This commit is contained in:
parent
baf658365e
commit
3dbc775334
4 changed files with 49 additions and 26 deletions
|
|
@ -839,30 +839,34 @@
|
|||
[& path]
|
||||
(if-let [afn (n/extract-basic-filter-fn path)]
|
||||
afn
|
||||
(late-bound-nav [late (late-path path)]
|
||||
(select* [this structure next-fn]
|
||||
(late-bound-richnav [late (late-path path)]
|
||||
(select* [this vals structure next-fn]
|
||||
(i/filter-select
|
||||
#(n/selected?* late %)
|
||||
#(n/selected?* late vals %)
|
||||
vals
|
||||
structure
|
||||
next-fn))
|
||||
(transform* [this structure next-fn]
|
||||
(transform* [this vals structure next-fn]
|
||||
(i/filter-transform
|
||||
#(n/selected?* late %)
|
||||
#(n/selected?* late vals %)
|
||||
vals
|
||||
structure
|
||||
next-fn)))))
|
||||
|
||||
(defdynamicnav not-selected? [& path]
|
||||
(if-let [afn (n/extract-basic-filter-fn path)]
|
||||
(fn [s] (not (afn s)))
|
||||
(late-bound-nav [late (late-path path)]
|
||||
(select* [this structure next-fn]
|
||||
(late-bound-richnav [late (late-path path)]
|
||||
(select* [this vals structure next-fn]
|
||||
(i/filter-select
|
||||
#(n/not-selected?* late %)
|
||||
#(n/not-selected?* late vals %)
|
||||
vals
|
||||
structure
|
||||
next-fn))
|
||||
(transform* [this structure next-fn]
|
||||
(transform* [this vals structure next-fn]
|
||||
(i/filter-transform
|
||||
#(n/not-selected?* late %)
|
||||
#(n/not-selected?* late vals %)
|
||||
vals
|
||||
structure
|
||||
next-fn)))))
|
||||
|
||||
|
|
@ -1039,7 +1043,7 @@
|
|||
vals
|
||||
structure
|
||||
next-fn
|
||||
#(n/selected?* late-cond %)
|
||||
#(n/selected?* late-cond vals %)
|
||||
late-then
|
||||
late-else))
|
||||
(transform* [this vals structure next-fn]
|
||||
|
|
@ -1047,7 +1051,7 @@
|
|||
vals
|
||||
structure
|
||||
next-fn
|
||||
#(n/selected?* late-cond %)
|
||||
#(n/selected?* late-cond vals %)
|
||||
late-then
|
||||
late-else))))))
|
||||
|
||||
|
|
|
|||
|
|
@ -271,10 +271,10 @@
|
|||
|
||||
#?(
|
||||
:clj
|
||||
(defmacro compiled-traverse* [path result-fn structure]
|
||||
(defmacro compiled-traverse-with-vals* [path result-fn vals structure]
|
||||
`(exec-select*
|
||||
~path
|
||||
[]
|
||||
~vals
|
||||
~structure
|
||||
(fn [vals# structure#]
|
||||
(if (identical? vals# [])
|
||||
|
|
@ -282,10 +282,10 @@
|
|||
(~result-fn (conj vals# structure#))))))
|
||||
|
||||
:cljs
|
||||
(defn compiled-traverse* [path result-fn structure]
|
||||
(defn compiled-traverse-with-vals* [path result-fn vals structure]
|
||||
(exec-select*
|
||||
path
|
||||
[]
|
||||
vals
|
||||
structure
|
||||
(fn [vals structure]
|
||||
(if (identical? vals [])
|
||||
|
|
@ -293,6 +293,9 @@
|
|||
(result-fn (conj vals structure)))))))
|
||||
|
||||
|
||||
(defn compiled-traverse* [path result-fn structure]
|
||||
(compiled-traverse-with-vals* path result-fn [] structure))
|
||||
|
||||
(defn do-compiled-traverse* [apath structure]
|
||||
(reify #?(:clj clojure.lang.IReduce :cljs cljs.core/IReduce)
|
||||
(#?(:clj reduce :cljs -reduce)
|
||||
|
|
@ -379,8 +382,10 @@
|
|||
|
||||
|
||||
|
||||
(defn compiled-select-any* [path structure]
|
||||
(unreduced (compiled-traverse* path reduced structure)))
|
||||
(defn compiled-select-any*
|
||||
([path structure] (compiled-select-any* path [] structure))
|
||||
([path vals structure]
|
||||
(unreduced (compiled-traverse-with-vals* path reduced vals structure))))
|
||||
|
||||
(defn compiled-select-first* [path structure]
|
||||
(let [ret (compiled-select-any* path structure)]
|
||||
|
|
@ -461,14 +466,14 @@
|
|||
(.-dynamic? c))
|
||||
|
||||
|
||||
(defn filter-select [afn structure next-fn]
|
||||
(defn filter-select [afn vals structure next-fn]
|
||||
(if (afn structure)
|
||||
(next-fn structure)
|
||||
(next-fn vals structure)
|
||||
NONE))
|
||||
|
||||
(defn filter-transform [afn structure next-fn]
|
||||
(defn filter-transform [afn vals structure next-fn]
|
||||
(if (afn structure)
|
||||
(next-fn structure)
|
||||
(next-fn vals structure)
|
||||
structure))
|
||||
|
||||
(defn ^:direct-nav pred* [afn]
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@
|
|||
|
||||
|
||||
(defn not-selected?*
|
||||
[compiled-path structure]
|
||||
[compiled-path vals structure]
|
||||
(->> structure
|
||||
(i/compiled-select-any* compiled-path)
|
||||
(i/compiled-select-any* compiled-path vals)
|
||||
(identical? i/NONE)))
|
||||
|
||||
(defn selected?*
|
||||
[compiled-path structure]
|
||||
(not (not-selected?* compiled-path structure)))
|
||||
[compiled-path vals structure]
|
||||
(not (not-selected?* compiled-path vals structure)))
|
||||
|
||||
(defn walk-select [pred continue-fn structure]
|
||||
(let [ret (i/mutable-cell i/NONE)
|
||||
|
|
|
|||
|
|
@ -1394,3 +1394,17 @@
|
|||
|
||||
(deftest select-any-vals-test
|
||||
(is (= [1 1] (select-any s/VAL 1))))
|
||||
|
||||
(deftest conditional-vals-test
|
||||
(is (= 2 (select-any (s/with-fresh-collected
|
||||
(s/collect-one (s/keypath 0))
|
||||
(s/if-path (collected? [n] (even? n))
|
||||
(s/keypath 1)
|
||||
(s/keypath 2)))
|
||||
[4 2 3])))
|
||||
(is (= [4 2 3]
|
||||
(select-any (s/with-fresh-collected
|
||||
(s/collect-one (s/keypath 0))
|
||||
(s/selected? (collected? [n] (even? n))))
|
||||
[4 2 3])))
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue