Add pattern composers, implements #82

This commit is contained in:
alex 2022-04-21 14:13:26 +01:00
parent 36d1a68b9a
commit b370c405da
2 changed files with 60 additions and 25 deletions

View file

@ -275,14 +275,14 @@ const generic_params = [
const _name = (name, ...pats) => sequence(...pats).withValue((x) => ({ [name]: x }));
const _unionise = (func) =>
const _setter = (func) =>
function (...pats) {
return this.union(func(...pats));
return this.set(func(...pats));
};
generic_params.forEach(([type, name, description]) => {
controls[name] = (...pats) => _name(name, ...pats);
Pattern.prototype[name] = _unionise(controls[name]);
Pattern.prototype[name] = _setter(controls[name]);
});
export default controls;