Created
October 21, 2017 20:29
-
-
Save suissa/1c387b43a72cd0a925cbb7ced9e150cc to your computer and use it in GitHub Desktop.
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
const pipe = (...fns ) => | |
fns.reduce( ( f, g ) => (...args ) => g( f(...args ) ) ) | |
const fx1 = ( x ) => ( before = 0 ) => before + x | |
const fx2 = ( x ) => ( before = 0 ) => before + ( x * x ) | |
const fx3 = ( x ) => ( before = 0 ) => before + ( x * x * x ) | |
// f(x) = x^3 + x^2 + x | |
const result = ( x ) => pipe( fx3( x ), fx2( x ), fx1( x ) )() | |
console.log( result( 2 ) ) | |
// 14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment