plumatic / schema

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

Schema for higher order functions just like in clojure.spec? #422

Closed zignd closed 3 years ago

zignd commented 4 years ago

Currently, clojure.spec offers fspec as described here for validation of higher order functions. I've noticed a few mentions to make-fn-schema in Schema, but currently, it seems to be intended only for documentation, no validation is performed. Is it possible to implement something just like fspec in Schema?

w01fe commented 4 years ago

You can write (s/fn ...) to create a validated function directly. But as you say, schemas on higher-order functions are just for documentation purposes. As Clojure does not have a notion of a static signature, as far as I know we would have to wrap the input/output in order to validate it, and that is something we wanted to avoid in the past. Not sure if anyone else has thoughts in this area, however.

gfredericks commented 4 years ago

spec (as of a year ago, at least) validates the function itself by calling it ~15 times at runtime with randomly generated inputs.

which I think was always the most surprising and controversial thing about spec.