Last active
December 24, 2015 12:09
-
-
Save kunev/6796082 to your computer and use it in GitHub Desktop.
This file contains 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Това почти работи ... има 2 нещица точно които трябва да се пипнат:
21: var twice = mult.curry(2) // за да е резултата 14, иначе не пречи ...
23: add_six.compose(twice)(4);
Иначе - да ... доста интересен чейнинг/пайпинг/къмпоузинг