allow calling all multiple times

This commit is contained in:
Felix Roos 2025-06-24 06:06:37 +02:00
parent 8e0f23e081
commit 0003ce174e
No known key found for this signature in database

View file

@ -113,8 +113,9 @@ export function repl({
* all(x => x.pianoroll()) * all(x => x.pianoroll())
* ``` * ```
*/ */
let allTransforms = [];
const all = function (transform) { const all = function (transform) {
allTransform = transform; allTransforms.push(transform);
return silence; return silence;
}; };
/** Applies a function to each of the running patterns separately. This is intended for future use with upcoming 'stepwise' features. See `all` for a version that applies the function to all the patterns stacked together into a single pattern. /** Applies a function to each of the running patterns separately. This is intended for future use with upcoming 'stepwise' features. See `all` for a version that applies the function to all the patterns stacked together into a single pattern.
@ -202,8 +203,10 @@ export function repl({
} else if (eachTransform) { } else if (eachTransform) {
pattern = eachTransform(pattern); pattern = eachTransform(pattern);
} }
if (allTransform) { if (allTransforms.length) {
pattern = allTransform(pattern); for (let i in allTransforms) {
pattern = allTransforms[i](pattern);
}
} }
if (!isPattern(pattern)) { if (!isPattern(pattern)) {
const message = `got "${typeof evaluated}" instead of pattern`; const message = `got "${typeof evaluated}" instead of pattern`;