diff --git a/CHANGES.md b/CHANGES.md index 62f0aac..5622666 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## 1.0.1-SNAPSHOT +* Add `satisfies-protpath?` * Inline cache vars are marked private so as not to interfere with tooling * Bug fix: Using `pred` no longer inserts unecessary `coerce-nav` call at callsite * Bug fix: Dynamic navs in argument position to another nav now properly expanded and compiled diff --git a/src/clj/com/rpl/specter.cljc b/src/clj/com/rpl/specter.cljc index 2146f51..c258b34 100644 --- a/src/clj/com/rpl/specter.cljc +++ b/src/clj/com/rpl/specter.cljc @@ -430,6 +430,9 @@ (let [inav# ~retrieve] (i/exec-transform* inav# ~@rargs)))))))) + (defmacro satisfies-protpath? [protpath o] + `(satisfies? ~(protpath-sym protpath) ~o)) + (defn extend-protocolpath* [protpath-prot extensions] (let [m (-> protpath-prot :sigs keys first) params (-> protpath-prot :sigs first last :arglists first)] diff --git a/test/com/rpl/specter/core_test.cljc b/test/com/rpl/specter/core_test.cljc index 29382fb..89e3b8f 100644 --- a/test/com/rpl/specter/core_test.cljc +++ b/test/com/rpl/specter/core_test.cljc @@ -10,7 +10,7 @@ select-first transform setval replace-in select-any selected-any? collected? traverse multi-transform path dynamicnav recursive-path - defdynamicnav traverse-all]])) + defdynamicnav traverse-all satisfies-protpath?]])) (:use #?(:clj [clojure.test :only [deftest is]]) #?(:clj [clojure.test.check.clojure-test :only [defspec]]) @@ -21,7 +21,7 @@ select-first transform setval replace-in select-any selected-any? collected? traverse multi-transform path dynamicnav recursive-path - defdynamicnav traverse-all]])) + defdynamicnav traverse-all satisfies-protpath?]])) @@ -1513,3 +1513,11 @@ (is (= [1] (foo 1))) (is (= [10] (foo 10))) )) + +(defprotocolpath FooPP) +(extend-protocolpath FooPP String s/STAY) + +(deftest satisfies-protpath-test + (is (satisfies-protpath? FooPP "a")) + (is (not (satisfies-protpath? FooPP 1))) + )