Fix sometimes (#1243)

* test and fix for sometimes bug
This commit is contained in:
Alex McLean 2025-01-16 11:18:33 +00:00 committed by GitHub
parent d5ab391a98
commit 00b0341839
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 7 deletions

View file

@ -499,7 +499,7 @@ export const undegrade = register('undegrade', (pat) => pat._undegradeBy(0.5), t
export const sometimesBy = register('sometimesBy', function (patx, func, pat) {
return reify(patx)
.fmap((x) => stack(pat._degradeBy(x), func(pat._undegradeBy(1 - x))))
.fmap((x) => stack(pat._degradeBy(x), func(pat)._undegradeBy(1 - x)))
.innerJoin();
});

View file

@ -52,6 +52,7 @@ import {
stackCentre,
s_cat,
calculateTactus,
sometimes,
} from '../index.mjs';
import { steady } from '../signal.mjs';
@ -1253,4 +1254,13 @@ describe('Pattern', () => {
expect(s('bev').chop(8).loopAt(2).tactus).toStrictEqual(Fraction(4));
});
});
describe('sometimes', () => {
it('works with constant functions', () => {
expect(
pure('a')
.sometimes((x) => pure('b'))
.fast(16).firstCycleValues.length,
).toStrictEqual(16);
});
});
});