From c34e9004276c2eafa15aabe5a5cf0b9d9426111b Mon Sep 17 00:00:00 2001 From: Thomas Athorne Date: Sat, 16 Apr 2016 17:16:23 +0100 Subject: [PATCH 1/4] Add `biview` path. --- VERSION | 2 +- src/clj/com/rpl/specter.cljx | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 965065d..87b8891 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.3 +0.9.4-SNAPSHOT diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index d1b403e..12bb528 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -270,6 +270,13 @@ (next-fn (afn structure)) )) +(defpath biview [afn bfn] + (select* [this structure next-fn] + (next-fn (afn structure))) + (transform* [this structure next-fn] + (bfn (next-fn (afn structure))) + )) + (defn selected? "Filters the current value based on whether a selector finds anything. e.g. (selected? :vals ALL even?) keeps the current element only if an From 60bf33ffab4cc248296d2c1dcd4065da07ac4dda Mon Sep 17 00:00:00 2001 From: Thomas Athorne Date: Sun, 17 Apr 2016 16:04:22 +0100 Subject: [PATCH 2/4] Change name; add a test spec. --- src/clj/com/rpl/specter.cljx | 6 +++--- test/com/rpl/specter/core_test.cljx | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index 12bb528..a10eaf3 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -270,11 +270,11 @@ (next-fn (afn structure)) )) -(defpath biview [afn bfn] +(defpath parser [parse unparse] (select* [this structure next-fn] - (next-fn (afn structure))) + (next-fn (parse structure))) (transform* [this structure next-fn] - (bfn (next-fn (afn structure))) + (unparse (next-fn (parse structure))) )) (defn selected? diff --git a/test/com/rpl/specter/core_test.cljx b/test/com/rpl/specter/core_test.cljx index 442d7a4..e150c87 100644 --- a/test/com/rpl/specter/core_test.cljx +++ b/test/com/rpl/specter/core_test.cljx @@ -242,6 +242,16 @@ (s/transform (s/view afn) identity i) ))) +(defspec parser-test + (for-all+ + [i gen/int + j gen/int] + (and (= (first (s/select (s/parser #(+ % j) #(- % j)) i)) + (+ j i)) + (= (s/transform (s/parser #(+ % j) #(- % j)) identity i) + i) + ))) + (deftest selected?-test (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] From 39b08bd9d53039f64acac749fc90c6fdec3f57a9 Mon Sep 17 00:00:00 2001 From: Thomas Athorne Date: Sun, 17 Apr 2016 16:12:43 +0100 Subject: [PATCH 3/4] Make the test a bit more thorough. --- test/com/rpl/specter/core_test.cljx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/com/rpl/specter/core_test.cljx b/test/com/rpl/specter/core_test.cljx index e150c87..0370fe5 100644 --- a/test/com/rpl/specter/core_test.cljx +++ b/test/com/rpl/specter/core_test.cljx @@ -245,11 +245,13 @@ (defspec parser-test (for-all+ [i gen/int - j gen/int] - (and (= (first (s/select (s/parser #(+ % j) #(- % j)) i)) - (+ j i)) - (= (s/transform (s/parser #(+ % j) #(- % j)) identity i) - i) + 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 From 1ddd8c22f6d4b432054ca11dd4151976c8d3f69e Mon Sep 17 00:00:00 2001 From: Thomas Athorne Date: Mon, 18 Apr 2016 16:21:33 +0000 Subject: [PATCH 4/4] Clearer names for arguments that are functions. --- src/clj/com/rpl/specter.cljx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index a10eaf3..c0802bf 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -270,11 +270,11 @@ (next-fn (afn structure)) )) -(defpath parser [parse unparse] +(defpath parser [parse-fn unparse-fn] (select* [this structure next-fn] - (next-fn (parse structure))) + (next-fn (parse-fn structure))) (transform* [this structure next-fn] - (unparse (next-fn (parse structure))) + (unparse-fn (next-fn (parse-fn structure))) )) (defn selected?