Skip to content

Instantly share code, notes, and snippets.

@torounit
Created December 30, 2018 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torounit/55535fbfcaa04917814e9d83e3b26bdb to your computer and use it in GitHub Desktop.
Save torounit/55535fbfcaa04917814e9d83e3b26bdb to your computer and use it in GitHub Desktop.
compose in '@wordpress/compose' .
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