From 7b33c93132b38ea2ca24da572f8c33e5499fd940 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Sat, 7 May 2016 22:40:21 +0530 Subject: [PATCH 1/2] Added path to navigate to atom value --- src/clj/com/rpl/specter.cljx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index 8a3499e..210356a 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -279,6 +279,17 @@ (assoc structure key (next-fn (get structure key))) )) +(defpath + ^{:doc "Navigates to atom value."} + atompath + [] + (select* [this structure next-fn] + (next-fn @structure)) + (transform* [this structure next-fn] + (do + (reset! structure (next-fn @structure)) + structure))) + (defpath ^{:doc "Navigates to the key only if it exists in the map."} must From c280b40b1291e2ad9ab715ed9cc23daabddabeb2 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Sun, 8 May 2016 23:39:14 +0530 Subject: [PATCH 2/2] renamed atompath to ATOM --- src/clj/com/rpl/specter.cljx | 2 +- test/com/rpl/specter/core_test.cljx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index 210356a..738e24d 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -281,7 +281,7 @@ (defpath ^{:doc "Navigates to atom value."} - atompath + ATOM [] (select* [this structure next-fn] (next-fn @structure)) diff --git a/test/com/rpl/specter/core_test.cljx b/test/com/rpl/specter/core_test.cljx index c9bf24e..88ee545 100644 --- a/test/com/rpl/specter/core_test.cljx +++ b/test/com/rpl/specter/core_test.cljx @@ -235,6 +235,11 @@ (is (= 5 (s/select-one (s/comp-paths :a :b) {:a {:b 5}}))) ) +(deftest atom-test + (let [v (s/transform s/ATOM inc (atom 1))] + (is (instance? clojure.lang.Atom v)) + (is (= 2 (s/select-one s/ATOM v) @v)))) + (defspec view-test (for-all+ [i gen/int