Install the last stable version
yarn add ppx_fields
Annotate a record with [%fields]
module FormState = {
[@deriving fields]
type t = {
email: string,
age: int,
};
}And you get the following generated for you:
module FormState = {
type t = {
email: string,
age: int,
};
module Fields = {
type fieldName(_) =
| Email: fieldName(string)
| Age: fieldName(int);
type field =
| Field(fieldName('a), 'a): field;
let get: type value. (t, fieldName(value)) => value;
let set: type value. (t, fieldName(value), value) => t;
let compare: (fieldName('a), fieldName('b)) => int;
let fold: (t, ~initial: 'result, ~f: ('result, field) => 'result) => 'result;
};
};Install esy
yarn global add esy
esySee esy.json for the available scripts.