move some utilities to utils.mjs
This commit is contained in:
parent
fb826bed70
commit
9eba883978
3 changed files with 32 additions and 32 deletions
|
|
@ -1,35 +1,5 @@
|
||||||
import Fraction from './fraction.mjs';
|
import Fraction from './fraction.mjs';
|
||||||
import { isNote, toMidi, compose } from './util.mjs';
|
import { isNote, toMidi, compose, removeUndefineds, flatten, id, listRange, curry } 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
class TimeSpan {
|
class TimeSpan {
|
||||||
constructor(begin, end) {
|
constructor(begin, end) {
|
||||||
|
|
|
||||||
|
|
@ -53,3 +53,33 @@ export const pipe = (...funcs) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const compose = (...funcs) => pipe(...funcs.reverse());
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { curry } from './strudel.mjs';
|
import { curry } from './util.mjs';
|
||||||
|
|
||||||
function unionWithObj(a, b, func) {
|
function unionWithObj(a, b, func) {
|
||||||
const common = Object.keys(a).filter((k) => Object.keys(b).includes(k));
|
const common = Object.keys(a).filter((k) => Object.keys(b).includes(k));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue