sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
293 stars 23 forks source link

Export and document $.validate #219

Open dakom opened 5 years ago

dakom commented 5 years ago

Type.validate is a useful tool for both getting type validation as an Either, and getting more detailed info about where an error occured

Would be great to have it documented on the public Readme(s) - and to have it exported as a function on sanctuary-def via $.validate() :)

I'd imagine the signature would be something like:

validate :: Type -> a -> Either ErrorMessage a

Not sure what ErrorMessage is though

janwirth commented 3 years ago

New api proposal

const pi = def('myVar')([])($.IntegerType)(3.14)
davidchambers commented 3 years ago

Both the pure function suggested by @dakom and the assertion suggested by @FranzSkuffka are good ideas! I would like to provide both, as they have different use cases.