plumatic / schema

Clojure(Script) library for declarative data description and validation
Other
2.4k stars 256 forks source link

How is conditional a good replacement for both? #358

Closed expez closed 8 years ago

expez commented 8 years ago

How do you rewrite (both Int odd?) using conditional in a way that makes sense? I've been using pred to express these but I don't think that's intended. What about something that's int?, odd? and plus?? Granted such schemas are rare, but there doesn't seem to be any good way to express every.

w01fe commented 8 years ago

You can do (s/conditional odd? s/Int), or better (s/constrained s/Int odd?) (as described in the Readme). FWIW (both Int odd?) was not valid, you would have to do (s/both s/Int (s/pred odd?)) before so the new ways work more naturally with predicates. For two constraints you could just use two layers of constrained, or compose them together into a single predicate (s/constrained s/Int (fn pos-odd? [x] (and (pos? x) (odd? x))))

Also, can you please post questions on the mailing list (see the README) rather than as github issues in the future? Thanks!

expez commented 8 years ago

Thanks, that makes sense!

Also, can you please post questions on the mailing list (see the README) rather than as github issues in the future? Thanks!

Will do!