Functional pipeline

This commit is contained in:
2023-05-03 22:42:27 -04:00
parent 9fe8227c57
commit 23ecad4f8f
2 changed files with 188 additions and 301 deletions

View File

@@ -1,3 +1,8 @@
export const comp = (...fs) => x0 => fs.reduceRight((x, f) => f(x), x0);
export const flow = (...fs) => x0 => fs.reduce((x, f) => f(x), x0);
export const pipe = (x0, ...fs) => fs.reduce((x, f) => f(x), x0);
export const aflow = (f0, ...fs) => async (...args) => fs.reduce((x, f) => f(x), await f0(...args));
export function uniq(xs) {
var seen = {};
return xs.filter(x => seen.hasOwnProperty(x) ? false : (seen[x] = true));