added not-selected? and transformed selectors

This commit is contained in:
Nathan Marz 2015-07-02 17:23:18 -04:00
parent e54f18cb1f
commit 051ba3f038
2 changed files with 22 additions and 0 deletions

View file

@ -148,6 +148,19 @@
empty?
not))))
(defn not-selected? [& path]
(complement (selected? (comp-paths* path))))
(defn transformed
"Navigates to a view of the current value by transforming it with the
specified selector and update-fn."
[selector update-fn]
(let [compiled (comp-paths* selector)]
(view
(fn [elem]
(compiled-transform compiled update-fn elem)
))))
(extend-type #?(:clj clojure.lang.Keyword :cljs cljs.core/Keyword)
StructurePath
(select* [kw structure next-fn]

View file

@ -395,3 +395,12 @@
(is (= nil (s/select-one! s/ALL [nil])))
(is (thrown? #?(:clj Exception :cljs js/Error) (s/select-one! s/ALL [])))
)
(defspec transformed-test
(for-all+
[v (gen/vector gen/int)
pred (gen/elements [even? odd?]
op (gen/elements [inc dec]))]
(= (select-one (transformed [ALL pred] op) v)
(transform [ALL pred] op v))
))