Created
October 21, 2017 22:15
-
-
Save suissa/39e43f677c0ea94a947790cf6950a963 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 add = ( before ) => [ before, ( x, y ) => x + y ] | |
const startFn = ( x, y ) => x + y | |
const fx1 = ( x ) => ( [ before = 0, op = startFn ] ) => op( before, x ) | |
const fx2 = ( x ) => ( [ before = 0, op = startFn ] ) => op( before, x * x ) | |
const fx3 = ( x ) => ( [ before = 0, op = startFn ] ) => op( before, x * x * x ) | |
const start = () => [] | |
const result = ( x ) => | |
pipe( | |
start, | |
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