failed attempt at composifying

This commit is contained in:
alex
2023-01-10 11:05:51 +00:00
parent 32e64bbb6e
commit bde7e79a38
2 changed files with 16 additions and 1 deletions
+9 -1
View File
@@ -819,7 +819,15 @@ const _setter = (func, name) =>
};
generic_params.forEach(([type, name, description]) => {
controls[name] = (...pats) => _name(name, ...pats);
controls[name] = function (...pats) {
const result = _name(name, ...pats);
// Add a function for composing this control with another pattern
result.__compose = function (pat) {
return pat[name](...pats);
};
return result;
};
Pattern.prototype[name] = _setter(controls[name], name);
});
+7
View File
@@ -1569,6 +1569,13 @@ export const outside = register('outside', function (factor, f, pat) {
*/
export const lastOf = register('lastOf', function (n, func, pat) {
const pats = Array(n - 1).fill(pat);
// It seems we have a pattern, but with a 'compose' function, let's
// use that
if ('__compose' in func) {
func = func.__compose;
}
pats.push(func(pat));
return slowcatPrime(...pats);
});