diff --git a/packages/core/strudel.mjs b/packages/core/strudel.mjs index 24c2d723..35f16d4c 100644 --- a/packages/core/strudel.mjs +++ b/packages/core/strudel.mjs @@ -1,35 +1,5 @@ import Fraction from './fraction.mjs'; -import { isNote, toMidi, compose } from './util.mjs'; - -// Removes 'None' values from given list -const removeUndefineds = (xs) => xs.filter((x) => x != undefined); - -const flatten = (arr) => [].concat(...arr); - -const id = (a) => a; - -const listRange = (min, max) => Array.from({ length: max - min + 1 }, (_, i) => i + min); - -export function curry(func, overload) { - const fn = function curried(...args) { - if (args.length >= func.length) { - return func.apply(this, args); - } else { - const partial = function (...args2) { - return curried.apply(this, args.concat(args2)); - }; - if (overload) { - overload(partial, args); - } - return partial; - } - }; - if (overload) { - // overload function without args... needed for chordBass.transpose(2) - overload(fn, []); - } - return fn; -} +import { isNote, toMidi, compose, removeUndefineds, flatten, id, listRange, curry } from './util.mjs'; class TimeSpan { constructor(begin, end) { diff --git a/packages/core/util.mjs b/packages/core/util.mjs index 719918e3..2de7a8e6 100644 --- a/packages/core/util.mjs +++ b/packages/core/util.mjs @@ -53,3 +53,33 @@ export const pipe = (...funcs) => { }; export const compose = (...funcs) => pipe(...funcs.reverse()); + +// Removes 'None' values from given list +export const removeUndefineds = (xs) => xs.filter((x) => x != undefined); + +export const flatten = (arr) => [].concat(...arr); + +export const id = (a) => a; + +export const listRange = (min, max) => Array.from({ length: max - min + 1 }, (_, i) => i + min); + +export function curry(func, overload) { + const fn = function curried(...args) { + if (args.length >= func.length) { + return func.apply(this, args); + } else { + const partial = function (...args2) { + return curried.apply(this, args.concat(args2)); + }; + if (overload) { + overload(partial, args); + } + return partial; + } + }; + if (overload) { + // overload function without args... needed for chordBass.transpose(2) + overload(fn, []); + } + return fn; +} diff --git a/packages/core/value.mjs b/packages/core/value.mjs index 1484a800..878e6b1f 100644 --- a/packages/core/value.mjs +++ b/packages/core/value.mjs @@ -1,4 +1,4 @@ -import { curry } from './strudel.mjs'; +import { curry } from './util.mjs'; function unionWithObj(a, b, func) { const common = Object.keys(a).filter((k) => Object.keys(b).includes(k));