add pipe + compose

This commit is contained in:
Felix Roos 2022-04-11 22:31:02 +02:00
parent 3f603eb84f
commit de3c453763
2 changed files with 25 additions and 1 deletions

View file

@ -42,3 +42,14 @@ export const getPlayableNoteValue = (event) => {
// rotate array by n steps (to the left)
export const rotate = (arr, n) => arr.slice(n).concat(arr.slice(0, n));
export const pipe = (...funcs) => {
return funcs.reduce(
(f, g) =>
(...args) =>
f(g(...args)),
(x) => x,
);
};
export const compose = (...funcs) => pipe(...funcs.reverse());