Created
December 30, 2018 06:39
-
-
Save torounit/55535fbfcaa04917814e9d83e3b26bdb to your computer and use it in GitHub Desktop.
compose in '@wordpress/compose' .
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
import { compose } from '@wordpress/compose'; // compose == lodash.flowRight; | |
const inc = ( a ) => { | |
return a + 1; | |
}; | |
const square = ( a ) => { | |
return a * a; | |
}; | |
//(1 + 3) ^ 2 = 16 | |
square( inc( 3 ) ); // 16 | |
compose( [ square, inc ] )( 3 ); // 16 | |
//1 + 3 ^ 2 = 10 | |
inc( square( 3 ) // 10 | |
compose( [ inc, square ] )( 3 ) // 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment