-
-
Save DJTB/abadd0feb4d7059df3bbcbbdb4da9194 to your computer and use it in GitHub Desktop.
Revisions
-
JamieMason revised this gist
Jun 6, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,8 @@ ```js const compose = (...fns) => fns.reduceRight((prevFn, nextFn) => (...args) => nextFn(prevFn(...args)), value => value ); ``` @@ -25,7 +25,7 @@ const example = compose( Call the function: ```js example('hello') ``` Console output is: -
JamieMason revised this gist
Aug 3, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ ## Definition ```js const compose = (...fns) => fns.reverse().reduce((prevFn, nextFn) => value => nextFn(prevFn(value)), value => value @@ -15,11 +15,11 @@ const compose = fns => Create the function, composed of three others: ```js const example = compose( val => { console.log(1); return `1<${val}>`; }, val => { console.log(2); return `2<${val}>`; }, val => { console.log(3); return `3<${val}>`; } ); ``` Call the function: -
JamieMason created this gist
Feb 4, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ # ES6 JavaScript Compose Function ## Definition ```js const compose = fns => fns.reverse().reduce((prevFn, nextFn) => value => nextFn(prevFn(value)), value => value ); ``` ## Example Create the function, composed of three others: ```js const example = compose([ val => { console.log(1); return `1<${val}>`; }, val => { console.log(2); return `2<${val}>`; }, val => { console.log(3); return `3<${val}>`; } ]); ``` Call the function: ```js x('hello') ``` Console output is: ``` 3 2 1 "1<2<3<hello>>>" ```