Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@suissa
Created October 21, 2017 21:00
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 suissa/4a76f7fbc33fe6b51771305eb068a3c1 to your computer and use it in GitHub Desktop.
Save suissa/4a76f7fbc33fe6b51771305eb068a3c1 to your computer and use it in GitHub Desktop.
const pipe = (...fns ) =>
fns.reduce( ( f, g ) => (...args ) => g( f(...args ) ) )
const add = ( before ) => [ before, ( x, y ) => x + y ]
const fx1 = ( x ) => ( [ before, op ] ) => op( before, x )
const fx2 = ( x ) => ( [ before, op ] ) => op( before, ( x * x ) )
const fx3 = ( x ) => ( ...before ) => x * x * x
const result = ( x ) =>
pipe(
fx3( x ),
add,
fx2( x ),
add,
fx1( x )
)()
console.log( result( 2 ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment