empty selectors and nil count as identity path now fixing #5, remove IDENTITY-PATH in favor of nil
This commit is contained in:
parent
228a949ac1
commit
50576e447b
3 changed files with 82 additions and 55 deletions
|
|
@ -124,8 +124,6 @@
|
|||
|
||||
(def FIRST (->FirstStructurePath))
|
||||
|
||||
(def IDENTITY-PATH (->IdentityPath))
|
||||
|
||||
(defn srange-dynamic [start-fn end-fn] (->SRangePath start-fn end-fn))
|
||||
|
||||
(defn srange [start end] (srange-dynamic (fn [_] start) (fn [_] end)))
|
||||
|
|
|
|||
|
|
@ -121,6 +121,9 @@
|
|||
(or (fn? obj) (obj-extends? StructurePath obj)))
|
||||
|
||||
(extend-protocol CoerceTransformFunctions
|
||||
nil ; needs its own path because it doesn't count as an Object
|
||||
(coerce-path [this]
|
||||
(coerce-structure-path nil))
|
||||
|
||||
TransformFunctions
|
||||
(coerce-path [this]
|
||||
|
|
@ -145,6 +148,8 @@
|
|||
))
|
||||
|
||||
(defn- combine-same-types [[^TransformFunctions f & _ :as all]]
|
||||
(if (empty? all)
|
||||
(coerce-path nil)
|
||||
(let [^ExecutorFunctions exs (.executors f)
|
||||
|
||||
t (.type exs)
|
||||
|
|
@ -168,7 +173,7 @@
|
|||
(combiner (.selector curr) (.selector next))
|
||||
(combiner (.updater curr) (.updater next))
|
||||
))
|
||||
all)))
|
||||
all))))
|
||||
|
||||
(defn coerce-structure-vals [^TransformFunctions tfns]
|
||||
(if (= (extype tfns) :svalspath)
|
||||
|
|
@ -448,16 +453,6 @@
|
|||
(->> structure ((.view-fn this)) next-fn)
|
||||
))
|
||||
|
||||
(deftype IdentityPath [])
|
||||
|
||||
(extend-protocol StructurePath
|
||||
IdentityPath
|
||||
(select* [this structure next-fn]
|
||||
(next-fn structure))
|
||||
(update* [this structure next-fn]
|
||||
(next-fn structure)
|
||||
))
|
||||
|
||||
(deftype PutValCollector [val])
|
||||
|
||||
(extend-protocol Collector
|
||||
|
|
@ -466,3 +461,11 @@
|
|||
(.val this)
|
||||
))
|
||||
|
||||
|
||||
(extend-protocol StructurePath
|
||||
nil
|
||||
(select* [this structure next-fn]
|
||||
(next-fn structure))
|
||||
(update* [this structure next-fn]
|
||||
(next-fn structure)
|
||||
))
|
||||
|
|
|
|||
|
|
@ -232,8 +232,8 @@
|
|||
(for-all+
|
||||
[i gen/int
|
||||
afn (gen/elements [inc dec])]
|
||||
(and (= [i] (select IDENTITY-PATH i))
|
||||
(= (afn i) (update IDENTITY-PATH afn i)))))
|
||||
(and (= [i] (select nil i))
|
||||
(= (afn i) (update nil afn i)))))
|
||||
|
||||
(defspec putval-test
|
||||
(for-all+
|
||||
|
|
@ -245,3 +245,29 @@
|
|||
(assoc m kw (+ c (get m kw)))
|
||||
)))
|
||||
|
||||
(defspec empty-selector-test
|
||||
(for-all+
|
||||
[v (gen/vector gen/int)]
|
||||
(= [v]
|
||||
(select [] v)
|
||||
(select nil v)
|
||||
(select (comp-paths) v)
|
||||
(select (comp-paths nil) v)
|
||||
(select [nil nil nil] v)
|
||||
)))
|
||||
|
||||
(defspec empty-selector-update-test
|
||||
(for-all+
|
||||
[kw gen/keyword
|
||||
m (max-size 10 (gen-map-with-keys gen/keyword gen/int kw))]
|
||||
(and (= m
|
||||
(update nil identity m)
|
||||
(update [] identity m)
|
||||
(update (comp-paths []) identity m)
|
||||
(update (comp-paths nil nil) identity m)
|
||||
)
|
||||
(= (update kw inc m)
|
||||
(update [nil kw] inc m)
|
||||
(update (comp-paths kw nil) inc m)
|
||||
(update (comp-paths nil kw nil) inc m)
|
||||
))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue