Skip to content

Instantly share code, notes, and snippets.

@kpittman-securus
Created May 11, 2021 17:40
Show Gist options
  • Save kpittman-securus/6080fd909114a1cd67fe7d4808ecb832 to your computer and use it in GitHub Desktop.
Save kpittman-securus/6080fd909114a1cd67fe7d4808ecb832 to your computer and use it in GitHub Desktop.
Pipe in plain JS
const pipe = (...funcs) => (...args) => funcs.reduce((prev, cur) => cur(prev), ...args);
const add2 = (x) => x+2;
const times5 = (x) => x*5;
const minus8 = (x) => x-8;
const fn = pipe(times5, add2, minus8, times5, minus8);
console.log([1,2,3,4,5].map(fn));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment