Last active
February 12, 2019 15:53
-
-
Save miladvafaeifard/33d62819ba1f41f9d82b00f393988949 to your computer and use it in GitHub Desktop.
compose and pipe functionalities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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