Skip to content

Instantly share code, notes, and snippets.

@leolanese
Created October 19, 2020 20:55
Show Gist options
  • Save leolanese/4189484cc16b13e5d34bbec3f4868a04 to your computer and use it in GitHub Desktop.
Save leolanese/4189484cc16b13e5d34bbec3f4868a04 to your computer and use it in GitHub Desktop.
compose
const compose = (...functions) => args => functions.reduceRight((arg, fn) => fn(arg), args);
// Example:
// 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 = compose(
// map(h => h.heroe),
// filter(h => h.power === 'fly')
//)(league); // ["superman"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment