How do I use spec and deftype together?

2018-07-04 Thread markus . agwin
The same question was asked on https://clojurians-log.clojureverse.org/clojure-spec/2018-01-19 but I did not find an answer. An example, where defrecord works fine but deftype fails: (do (require '[clojure.spec.alpha :as s]) (defprotocol Foo (foo [this])) (defrecord Bar [bar] Foo (foo [this

Re: How do I use spec and deftype together?

2018-07-04 Thread markus . agwin
So is it best practice to implement map in the deftype to make it spec-able? Are there examples somewhere that show how to do this in a canonical way? On Wednesday, July 4, 2018 at 12:51:29 PM UTC+2, Leon Grapenthin wrote: > > Spec doesn't check object fields. The defrecord case works because >

Re: How do I use spec and deftype together?

2018-07-04 Thread markus . agwin
So is it best practice to implement map in the deftype to make it spec-able? Are there examples somewhere that show how to do this in a canonical way? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googl

Re: How do I use spec and deftype together?

2018-07-05 Thread markus . agwin
Just in case someone stumbles over this post, I found a simple solution which works for me: (do (require '[clojure.spec.alpha :as s]) (import '(clojure.lang ISeq)) (defprotocol Foo (foo [this])) (defrecord Bar [bar] Foo (foo [this] (.bar this))) (deftype Baz [bar] Foo (foo [this]

s/valid returns false, but s/explain prints "Success!"

2019-09-26 Thread Markus Agwin
Consider the following cloure.spec-alpha2 example: (def v [0]) (s/def ::thevec vector?) (s/def ::data (s/coll-of number? :kind ::thevec)) (s/valid? ::data v) ;;=> returns false, my expectation is that it should return true (s/explain ::data v) ;;=> prints "Success!", which inconsistent to s/va

Re: s/valid returns false, but s/explain prints "Success!"

2019-09-26 Thread Markus Agwin
PM UTC+2, Alex Miller wrote: > > > > On Thursday, September 26, 2019 at 7:41:20 AM UTC-5, Markus Agwin wrote: >> >> Consider the following cloure.spec-alpha2 example: >> >> (def v [0]) >> (s/def ::thevec vector?) >> (s/def ::data (s/coll-of numb