From 97a38a6f59a545c84b6f9fb1b0734d3be4a9b6f6 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 5 Dec 2022 20:45:25 +0000 Subject: [PATCH] more fiddling with making module level curried functions --- packages/core/pattern.mjs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 925da1550..7a84afe64 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1546,7 +1546,7 @@ function _composeOp(a, b, func) { // Default op to 'set', e.g. pat.squeeze(pat2) = pat.set.squeeze(pat2) for (const how of hows) { Pattern.prototype[how.toLowerCase()] = function (...args) { return this.set[how.toLowerCase()](args) }; - curry_toplevel(how, 2); + curry_toplevel(how.toLowerCase(), 2); } curry_toplevel(what, 2); } @@ -1563,14 +1563,22 @@ function _composeOp(a, b, func) { * .struct("x ~ x ~ ~ x ~ x ~ ~ ~ x ~ x ~ ~") * .slow(4) */ - Pattern.prototype.struct = function(...args) { return this.keepif.out(...args) } + Pattern.prototype.struct = function(...args) { return this.keepif.out(...args) } + curry_toplevel('struct', 2); Pattern.prototype.structAll = function(...args) { return this.keep.out(...args) } + curry_toplevel('structAll', 2); Pattern.prototype.mask = function(...args) { return this.keepif.in(...args) } + curry_toplevel('mask', 2); Pattern.prototype.maskAll = function(...args) { return this.keep.in(...args) } + curry_toplevel('maskAll', 2); Pattern.prototype.reset = function(...args) { return this.keepif.trig(...args) } + curry_toplevel('reset', 2); Pattern.prototype.resetAll = function(...args) { return this.keep.trig(...args) } + curry_toplevel('resetAll', 2); Pattern.prototype.restart = function(...args) { return this.keepif.trigzero(...args) } + curry_toplevel('restart', 2); Pattern.prototype.restartAll = function(...args) { return this.keep.trigzero(...args) } + curry_toplevel('restartAll', 2); })(); // methods of Pattern that get callable factories @@ -1613,6 +1621,9 @@ Pattern.prototype.factories = { // the magic happens in Pattern constructor. Keeping this in prototype enables adding methods from the outside (e.g. see tonal.ts) function curry_toplevel(name, arity=1) { + //if (name in pattern) { + // throw(`${name} already exists`); + //} if (arity == 1) { pattern[name] = (pat) => pat[name](); } @@ -1631,10 +1642,9 @@ for (const x of [[1, ['inv', 'invert', 'rev']], [2, ['chop','chunk','chunkBack', 'mask','struct','superimpose'].concat(Pattern.prototype.patternified)], [3, ['every','juxBy','off','range','rangex','range2','when']], [4, ['echo']] - ] - ) { - for (const func of x[1]) { - curry_toplevel(func, x[0]); + ]) { + for (const name of x[1]) { + curry_toplevel(name, x[0]); } }