Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fernandocanizo/399f62aa0684ee59c45e89fa532a26ab to your computer and use it in GitHub Desktop.
Save fernandocanizo/399f62aa0684ee59c45e89fa532a26ab to your computer and use it in GitHub Desktop.
Using reduce to apply a pipeline of functions
"use strict";
const pipe = functions => data => {
return functions.reduce((value, func) => func(value), data);
};
const pipeline = pipe([
n => n + 1,
n => n * 2,
n => n * n,
]);
pipeline(5); // 144
pipeline(1); // 16
@fernandocanizo
Copy link
Author

Poor man curry?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment