We care about safety and correctness of forms as much as we care about UX aspect. So one of the goals of this library is to ensure that input data from UI can be safely turned into expected and correct result.
The core types everything is based on are input
and output
. input
is representation of a raw form state in UI. output
is a representation of valid form data. The whole process of filling out the form is considered as a process of deserialization of raw data (strings / booleans from DOM or any other environment) into type safe data structure via validators
—user defined functions that ensure validity of an input
. We guarantee on a type level that if form gets submitted, the types of submittable data are correct.
To illustrate the IO concept, consider an email
field in a form. In UI, email represented as a string. But in an application domain it should be of Email.t
type which holds parsed representation of valid email. So the expected result of an email field should be of Email.t
type.
type input = {email: string};
type output = {email: Email.t};
To turn the former into the latter, you must define function, which takes input
and returns result
: either Ok(Email.t)
or Error(message)
. More on this, in the next sections.
Next: Basic Usage →