.
-. - ( , in, result out this ).
. arguments , , /, , g() .
, , , , .
, ;
( : - - , JS- )
partial application, currying JS, : , , ; , .
-, , configs-first, data-last.
:
var toLowerCase = function(str){
return String(str).toLowerCase();
}
var replace = curry(function(needle, heystack, str){
return String(str).replace(needle, heystack);
});
arr.map( replace(/\s[A-Z]/g, toLowerCase) );
var replaceWhitespaceWith = replace(/\s+/g);
arr.map( replaceWhitespaceWith("-") );
, , , ( )
var prepend = a => b => String(a) + String(b);
var substr = (from, to) => value => String(str).substr(from, to);
arr.map( compose( prepend("foo"), substr(0, 5) ) );
arr.map( compose( prepend("bar"), substr(5) ) );
I’m not going to ever call such functions with all arguments, all I want to pass to them is their configs and get a function that performs the task on the transmitted data / value.
Instead, substr(0, 5, someString)I would always write someString.substr(0, 5), so why make any effort so that the last argument (data) is applicable on the first call?