Skip to content

Instantly share code, notes, and snippets.

@leolanese
Created October 19, 2020 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leolanese/16c4ed4ac08da4d8224f4f7bb42d5fd4 to your computer and use it in GitHub Desktop.
Save leolanese/16c4ed4ac08da4d8224f4f7bb42d5fd4 to your computer and use it in GitHub Desktop.
function pipe
const pipe = (...functions) => args => functions.reduce((arg, fn) => fn(arg), args);
// const league = [
// { heroe: "superman", power: 'fly' },
// { heroe: "batman", power: 'millionare'},
// { heroe: "flash", power: 'speed' },
// ]
// const filter = f => arr => arr.filter(f);
// const map = m => arr => arr.map(m);
// let res = pipe(
// filter(h => h.power === 'fly'),
// map(h => h.heroe)
// )(league); // ["superman"]
// pipe(mapWords, reduceWords)(['foo', 'bar', 'baz']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment