Last active
February 26, 2020 20:08
-
-
Save munkacsitomi/71cf5b84d9e634f71cb2128a928f2caf to your computer and use it in GitHub Desktop.
<3 JS
This file contains hidden or 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 add = (a) => (b) => a + b; | |
const addMore = (a) => (b) => (c) => add(a)(b) + c; | |
console.log(add(2)(4)); | |
console.log(addMore(2)(4)(6)); | |
// 6 | |
// 12 |
This file contains hidden or 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 pipe = (...fns) => x => fns.reduce((y, f) => f(y), x); | |
const trace = label => value => { | |
console.log(`${label}: ${value}`); | |
return value; | |
}; | |
const g = n => n + 1; | |
const f = n => n * 2; | |
const h = pipe(g, trace('after g'), f, trace('after f')); | |
h(20); | |
// after g: 21 | |
// after f: 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment