Earlier quoted context omitted.
Thanks for the feedback! Actually, schema can express arbitrary constraints. Your example translates to schema as: {String {(s/required-key "product") [String] (s/required-key "type") (s/enum "type1" "type2") s/Any s/Any}} ;; allow any other k-v pairs
Interesting! Is the enum automatically a vector/sequence, or is that just an omission in the example? Looks like I'll be using this library sooner than I thought, thanks!
Schema for Clojure(Script) Data Shape Declaration and Validation
51–58 of 58 posts
Re: Schema for Clojure(Script) Data Shape Declaration and Validation
#52core.typed author here. It might be easy to consider Schema as "competitor" to core.typed. In fact, it's the opposite: once they play nicely together they will form a formidable bug-fighting, finely-documenting team. :) core.typed has accurate compile time checking, and Schema gives an expressive contracts interface for runtime checking. Once they understand each other, you can start pushing and pulling between stati…
I think core.typed has come a long way since last time I looked at it (when we started developing schema). Obviously it's a much bigger and more serious effort, and schema was about getting as much bang right away as we could for a few bucks.
I'd love to talk in more detail about how we can collaborate, or at least make sure we play nice together.
Re: Schema for Clojure(Script) Data Shape Declaration and Validation
#53What timing! I have been making this exact thing myself. Would you be interested in pull requests making your api simpler? Maybe allow parameters to not have to have shapes? Perhaps allowing a syntax that allows a simple way to shapes in the meta alongside the ability to change the signature for people who don't want to couple too tightly to the library? When I showed mine to my local user group last month, that was…
Schemas are already optional -- you can have a s/defn with no, some, or full schematization. You can also put the schemas in the meta if you don't like the :- syntax. I'm not quite sure what you mean by the other point though. My email is in my profile, let's talk :)
Re: Schema for Clojure(Script) Data Shape Declaration and Validation
#54What timing! I have been making this exact thing myself. Would you be interested in pull requests making your api simpler? Maybe allow parameters to not have to have shapes? Perhaps allowing a syntax that allows a simple way to shapes in the meta alongside the ability to change the signature for people who don't want to couple too tightly to the library? When I showed mine to my local user group last month, that was…
Also, what about having your defn macro generate a second function like foo-t that just calls with-fn-validation on foo, to clean up that extra call? Would you be interested in such a pull request?
Quite honestly that part of things (turning validation on and off, etc) isn't really done yet -- we have plans to make it much more flexible and powerful, but haven't got there yet.
Re: Schema for Clojure(Script) Data Shape Declaration and Validation
#55Earlier quoted context omitted.
Author of core.typed here. I will challenge that schemas are "significantly" better for documentation than core.typed types. With unions, intersections, heterogeneous maps, parameterised classes, recursive types we can be very expressive. Here's some examples of the syntax for types: https://github.com/clojure/core.typed/wiki/Types And some declarative types in action: https://github.com/frenchy64/core.typed-example/…
Sorry, that didn't come across the way I wanted -- it certainly wasn't meant as a dig on the expressiveness or power of core.typed, which is a project I'm really excited about. The main driver for Schema was to make annotating function inputs and outputs as simple and readable as possible. Personally, I find annotations directly on the function arguments easier to parse than separate function type declarations, but I…
FWIW there are macros like fn> that allow you to write (fn> :- Number [a :- Symbol] 1), but you lose the ability to write ordered function types with multiple cases, so I don't use it very much.
Re: Schema for Clojure(Script) Data Shape Declaration and Validation
#56core.typed author here. It might be easy to consider Schema as "competitor" to core.typed. In fact, it's the opposite: once they play nicely together they will form a formidable bug-fighting, finely-documenting team. :) core.typed has accurate compile time checking, and Schema gives an expressive contracts interface for runtime checking. Once they understand each other, you can start pushing and pulling between stati…
I've been really pumped about core.typed since I first heard about it, and I'm excited about the possibilities of combining (or eventually replacing) schema with core.typed. I think core.typed has come a long way since last time I looked at it (when we started developing schema). Obviously it's a much bigger and more serious effort, and schema was about getting as much bang right away as we could for a few bucks. I'd…
Re: Schema for Clojure(Script) Data Shape Declaration and Validation
#57Re: Schema for Clojure(Script) Data Shape Declaration and Validation
#58Earlier quoted context omitted.
I've been really pumped about core.typed since I first heard about it, and I'm excited about the possibilities of combining (or eventually replacing) schema with core.typed. I think core.typed has come a long way since last time I looked at it (when we started developing schema). Obviously it's a much bigger and more serious effort, and schema was about getting as much bang right away as we could for a few bucks. I'd…
Fantastic, bring it on!
I regrettably haven't had much time to see where the cross-section between these libraries is exactly, being very occupied at work. But I'd rather work on one grand thing, than end up with disparate libraries that aren't as fully-featured.