Merge pull request #73 from thomasathorne/biview

Add `parser` path.
This commit is contained in:
Nathan Marz 2016-04-18 14:20:19 -04:00
commit c861756836
2 changed files with 19 additions and 0 deletions

View file

@ -270,6 +270,13 @@
(next-fn (afn structure)) (next-fn (afn structure))
)) ))
(defpath parser [parse-fn unparse-fn]
(select* [this structure next-fn]
(next-fn (parse-fn structure)))
(transform* [this structure next-fn]
(unparse-fn (next-fn (parse-fn structure)))
))
(defn selected? (defn selected?
"Filters the current value based on whether a selector finds anything. "Filters the current value based on whether a selector finds anything.
e.g. (selected? :vals ALL even?) keeps the current element only if an e.g. (selected? :vals ALL even?) keeps the current element only if an

View file

@ -242,6 +242,18 @@
(s/transform (s/view afn) identity i) (s/transform (s/view afn) identity i)
))) )))
(defspec parser-test
(for-all+
[i gen/int
afn (gen/elements [inc dec #(* % 2)])
bfn (gen/elements [inc dec #(* % 2)])
cfn (gen/elements [inc dec #(* % 2)])]
(and (= (first (s/select (s/parser afn bfn) i))
(afn i))
(= (s/transform (s/parser afn bfn) cfn i)
(-> i afn cfn bfn))
)))
(deftest selected?-test (deftest selected?-test
(is (= [[1 3 5] [2 :a] [7 11 4 2 :a] [10 1 :a] []] (is (= [[1 3 5] [2 :a] [7 11 4 2 :a] [10 1 :a] []]
(s/setval [s/ALL (s/selected? s/ALL even?) s/END] (s/setval [s/ALL (s/selected? s/ALL even?) s/END]