Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Last active February 12, 2019 15:53
Show Gist options
  • Save miladvafaeifard/33d62819ba1f41f9d82b00f393988949 to your computer and use it in GitHub Desktop.
Save miladvafaeifard/33d62819ba1f41f9d82b00f393988949 to your computer and use it in GitHub Desktop.
compose and pipe functionalities
const uranus = {};
const trace = label => value => {
console.log(`${ label }: $ { value }`);
return value;
}
Object.defineProperty(uranus, 'compose', {
value: (...fns) => value => fns.reduceRight((g,f) => f(g), value),
configurable: false
});
Object.defineProperty(uranus, 'pipe', {
value: (...fns) => value => fns.reduce((g,f) => f(g), value),
configurable: false
});
const add = uranus.compose(x => x + 1);
console.log(add(5)); // 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment