Created
February 6, 2012 05:55
-
-
Save fredyang/1750036 to your computer and use it in GitHub Desktop.
help you simulate the pipeline in other functional language
This file contains hidden or 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
function makepipe ( initValue ) { | |
var result = initValue, | |
slice = [].slice, | |
rtn = function( fn ) { | |
result = fn.apply( null, [result].concat( slice.call( arguments, 1 ) ) ); | |
return rtn; | |
}; | |
rtn.get = function() { | |
return result; | |
}; | |
return rtn; | |
} | |
function plus ( x, y ) { | |
return x + y; | |
} | |
function mul ( x, y ) { | |
return x * y; | |
} | |
alert( " ( 100 + 10 ) * 2 = " + makepipe( 100 )( plus, 10 )( mul, 2 ).get() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment