Skip to content

Instantly share code, notes, and snippets.

@fredyang
Created February 6, 2012 05:55
Show Gist options
  • Save fredyang/1750036 to your computer and use it in GitHub Desktop.
Save fredyang/1750036 to your computer and use it in GitHub Desktop.
help you simulate the pipeline in other functional language
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