Skip to content

Instantly share code, notes, and snippets.

@xat
Created October 1, 2016 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xat/003ae3c2ea31c8ab61da0201c51225ef to your computer and use it in GitHub Desktop.
Save xat/003ae3c2ea31c8ab61da0201c51225ef to your computer and use it in GitHub Desktop.
const pipeline = (...fns) => (val) => fns.reduce((prom, fn) => prom.then(fn), Promise.resolve(val));
const myPipe = pipeline(
(val) => val + 1,
(val) => val + 1
);
Promise.resolve(1)
.then(myPipe)
.then((result) => {
console.log('result', result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment