Re: s/valid? does not tell me if the data is valid as supplied

2018-02-26 Thread Simon Belak
I’m a pretty heavy user of spec including a lot of coercion. The way I’ve always done coercion is to enumerate all accepted shapes first and do coercion last. For your example this would be: (s/def ::foo (s/and (s/or :string string? :kw keyword?)

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-26 Thread Dave Dixon
I've been using the macro below to make "types" in the context of clara-rules, where "type" has a specific semantic. If you're going to do something like this, you definitely should have a very well-defined notion of what "type" means. (defmacro def-derive "Macros to wrap useful pattern

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-26 Thread Alex Miller
Nice! On Monday, February 26, 2018 at 8:47:38 AM UTC-6, Wilker wrote: > > I've written a library that tries to solve this, instead of making > conforms that do coercion, it uses the spec and a separated registry to > conform the value (similar to what spec does to find the generators for a >

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-26 Thread Wilker
I've written a library that tries to solve this, instead of making conforms that do coercion, it uses the spec and a separated registry to conform the value (similar to what spec does to find the generators for a given spec). You can find the library at:

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-22 Thread Didier
> > Map specs are about attribute aggregation, not about types. > I understand the design philosophy. I think that's great. What I meant I guess is that it would be nice to also have a declarative way to relate Types to Specs, for when Specs fall short of types. Then you'd have the best of

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-22 Thread Jan Rychter
On Thursday, February 22, 2018 at 12:58:00 AM UTC+1, Sean Corfield wrote: > > Looking around I see lots of cases where people do use conformers for > coercion. > > > > That doesn’t make them right  > Oh, I agree, I'm just being realistic. The cat is out of the bag. I just googled for

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-21 Thread Alex Miller
On Wednesday, February 21, 2018 at 7:34:00 PM UTC-6, Didier wrote: > > I would actually love it if Spec was extended to have the concept of types. > Map specs are about attribute aggregation, not about types. https://clojure.org/about/spec#_map_specs_should_be_of_keysets_only > Something

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-21 Thread Didier
I would actually love it if Spec was extended to have the concept of types. Something where every spec could be tied to a Type, and types could be constructed to have Hierarchies. Not sure what the syntax would be like, but say: (s/def :String ::name string?) (s/def :String ::address (s/and

RE: s/valid? does not tell me if the data is valid as supplied

2018-02-21 Thread Sean Corfield
Looking around I see lots of cases where people do use conformers for coercion. That doesn’t make them right  At a first glance it seems very natural, and warnings not to do it are not easily found. Every single time coercion comes up anywhere in the context of spec, someone says “don’t do

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-21 Thread Jan Rychter
On Tuesday, February 20, 2018 at 4:53:33 PM UTC+1, Alex Miller wrote: > > This is exactly why we recommend that you not use conformers for coercion. > Conformers were added primarily as a tool for building custom composite > spec types (for example, we used it to build keys* from keys). > I am

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-20 Thread Tommi Reiman
tiistai 20. helmikuuta 2018 19.05.55 UTC+2 Alex Miller kirjoitti: > > > On Tuesday, February 20, 2018 at 10:28:12 AM UTC-6, Erik Assum wrote: >> >> FWIW, I’ve been using https://github.com/metosin/spec-tools >> on a couple of projects lately, which helps nicely with >> conformance and coercion.

RE: s/valid? does not tell me if the data is valid as supplied

2018-02-20 Thread Sean Corfield
Calling s/valid? will tell me if the data is valid *if it has been conformed*. But what if it hasn't? Can I use the data? Is it "valid" according to the spec I wrote? If your spec includes coercions, you have inherently made the “is valid?” question include the coercion. Your ::test-spec

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-20 Thread Alex Miller
On Tuesday, February 20, 2018 at 11:24:19 AM UTC-6, Erik Assum wrote: > > Out of curiosity, are you at liberty to discuss how Cognitect solves the > problem of validating/coercing values at the edges of the application when > you (Cognitect) are doing consulting? I'm not involved with those

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-20 Thread Erik Assum
Out of curiosity, are you at liberty to discuss how Cognitect solves the problem of validating/coercing values at the edges of the application when you (Cognitect) are doing consulting? Erik. -- i farta > 20. feb. 2018 kl. 18:05 skrev Alex Miller : > > I do see the

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-20 Thread Alex Miller
On Tuesday, February 20, 2018 at 10:28:12 AM UTC-6, Erik Assum wrote: > > FWIW, I’ve been using https://github.com/metosin/spec-tools > on a couple of projects lately, which helps nicely with > conformance and coercion. The main devs are very helpful on #ring-swagger > on the Clojurians slack.

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-20 Thread Erik Assum
FWIW, I’ve been using https://github.com/metosin/spec-tools on a couple of projects lately, which helps nicely with conformance and coercion. The main devs are very helpful on #ring-swagger on the Clojurians slack. Alex, how does spec-tools measure up to your thoughts on conformance/coercion?

Re: s/valid? does not tell me if the data is valid as supplied

2018-02-20 Thread Alex Miller
This is exactly why we recommend that you not use conformers for coercion. Conformers were added primarily as a tool for building custom composite spec types (for example, we used it to build keys* from keys). This is a common need though and I would be happier if spec did more to help you

s/valid? does not tell me if the data is valid as supplied

2018-02-20 Thread Jan Rychter
I've been using spec for a while now, in a reasonably large code base (>30k lines of Clojure and ClojureScript) and there is an issue that bit me several times. I use conformers for coercing data that is *almost* what I need, usually when reading from JSON (RethinkDB). Common conformers are