Skip to content

Instantly share code, notes, and snippets.

@kunev
Last active December 24, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunev/6796082 to your computer and use it in GitHub Desktop.
Save kunev/6796082 to your computer and use it in GitHub Desktop.
function sum(a, b) { return a + b; }
function mult(a, b) { return a * b; }
Function.prototype.curry = function ( ) {
var slice = Array.prototype.slice,
args = slice.apply(arguments),
that = this;
return function ( ) {
return that.apply(null, args.concat(slice.apply(arguments)));
};
};
Function.prototype.compose = function(f) {
var that = this;
return function (arg) {
return that.call(null, f(arg));
}
};
var add_six = sum.curry(6);
var twice = sum.curry(2);
add_six.curry(twice)(4); //14
@momchil-anachkov
Copy link

Това почти работи ... има 2 нещица точно които трябва да се пипнат:

21: var twice = mult.curry(2) // за да е резултата 14, иначе не пречи ...
23: add_six.compose(twice)(4);

Иначе - да ... доста интересен чейнинг/пайпинг/къмпоузинг

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment