From fa59334a462da9aac58c7cacd87cb21c86987e0e Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 8 Feb 2022 17:08:11 +0000 Subject: [PATCH] add some module level curried aliases --- strudel.mjs | 12 ++++++++++-- test/pattern.test.mjs | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/strudel.mjs b/strudel.mjs index ae9bf4b7..c08519a9 100644 --- a/strudel.mjs +++ b/strudel.mjs @@ -632,6 +632,14 @@ function pr(args) { polyrhythm(args) } -export {Fraction, TimeSpan, Hap, Pattern, - pure, stack, slowcat, fastcat, cat, sequence, polymeter, pm, polyrhythm, pr, reify, silence} +const fast = curry((a, pat) => pat.fast(a)) +const slow = curry((a, pat) => pat.slow(a)) +const early = curry((a, pat) => pat.early(a)) +const late = curry((a, pat) => pat.late(a)) +const rev = pat => pat.rev() + +export {Fraction, TimeSpan, Hap, Pattern, + pure, stack, slowcat, fastcat, cat, sequence, polymeter, pm, polyrhythm, pr, reify, silence, + fast, slow, early, late, rev +} diff --git a/test/pattern.test.mjs b/test/pattern.test.mjs index 7de9bace..bd13c4d3 100644 --- a/test/pattern.test.mjs +++ b/test/pattern.test.mjs @@ -2,7 +2,7 @@ import Fraction from 'fraction.js' import { strict as assert } from 'assert'; -import {TimeSpan, Hap, Pattern, pure, stack, fastcat, slowcat, cat, sequence, polyrhythm, silence} from "../strudel.mjs"; +import {TimeSpan, Hap, Pattern, pure, stack, fastcat, slowcat, cat, sequence, polyrhythm, silence, fast} from "../strudel.mjs"; const ts = (begin, end) => new TimeSpan(Fraction(begin), Fraction(end)); const hap = (whole, part, value) => new Hap(whole, part, value) @@ -104,6 +104,18 @@ describe('Pattern', function() { sequence(1,2,3).fast(1.5,2).firstCycle ) }) + it("works as a static function", function () { + assert.deepStrictEqual( + sequence(1,2,3).fast(1,2).firstCycle, + fast(sequence(1,2), sequence(1,2,3)).firstCycle + ) + }) + it("works as a curried static function", function () { + assert.deepStrictEqual( + sequence(1,2,3).fast(1,2).firstCycle, + fast(sequence(1,2))(sequence(1,2,3)).firstCycle + ) + }) }) describe('_slow()', function () { it('Makes things slower', function () { @@ -176,5 +188,11 @@ describe('Pattern', function() { sequence(sequence("a", "a"), "a", "a").firstCycle ) }) + it("works with currying", () => { + assert.deepStrictEqual( + pure("a").every(3, fast(2))._fast(3).firstCycle, + sequence(sequence("a", "a"), "a", "a").firstCycle + ) + }) }) })