4 ms·
In concatenative languages, this style of composition is the norm, and it does indeed work well for many tasks: http://concatenative.org/wiki/view/Pipeline%20s
by RodgerTheGreat 11y ago
In concatenative languages, this style of composition is the norm, and it does indeed work well for many tasks:
http://concatenative.org/wiki/view/Pipeline%20style http://concatenative.org/wiki/view/Pipeline%20style
- lisivka 11y agoIt is available in JS too: function double(str) { return str+', '+str; } function ucase(str) { return str.slice(0,1).toUpperCase()+ str.slice(1); } function exclamation(str) { return str+"!"; } var _="hello"; _ = double(_); _ = ucase(_); // _ = foo(_); _ = exclamation(_); console.log(_); // Hello, hello! function pipe() { var functions=[]; for(var i=0; i<arguments.length; i++) { functions[i]=arguments[i]; } return function pipe_call(arg) { for(var i=0; i<functions.length; i++) { arg=functions[i](arg); } return arg; } } var _="hello"; _ =pipe( double, ucase, // foo, exclamation )(_); console.log(_); // Hello, hello!