Last active
October 7, 2020 05:22
-
-
Save Akira-Hayasaka/839ab2c2c701919b8427df808134cabd to your computer and use it in GitHub Desktop.
currying & Function Composition (aka HOC)
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
// curried functions, a.k.a HOC | |
const witha = (extra) => (component) => (props) => { | |
console.log("witha", extra); | |
console.log("witha", component); | |
console.log("witha", props); | |
return () => component(props); | |
}; | |
const withb = (extra) => (component) => (props) => { | |
console.log("withb", extra); | |
console.log("withb", component); | |
console.log("withb", props); | |
return () => component(props); | |
}; | |
// dummy component | |
const component = (props) => { | |
console.log("render component with", props); | |
}; | |
// partial application | |
let hoca = witha("extraaa")(component); | |
let hocb = withb("extrabb")(hoca); | |
let compo = hocb("shared props"); | |
// rendering | |
compo()(); | |
console.log(""); | |
// one line | |
withb("extrabb")(witha("extraaa")(component))("shared props")()(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment