|
|
|
|
|
by devwebee
4476 days ago
|
|
Not sure those two cases are really interchangeable. It doesn't seem like a very good example. By introducing an object that way you're coupling your functions that work on pure data to an instance. Now to multiply two numbers you need an instance of Calc. I'd suggest something like this instead: var multiply = curry(function(x, y){
return x * y;
});
var add = curry(function(x, y){
return x + y;
});
var Calc = (function(){
function Calc(x){
this.x = x;
}
Calc.prototype.map = function(f){
this.x = f(this.x);
return this;
};
return Calc;
}());
new Calc(2).map(compose(add(2), multiply(4)));
// or
new Calc(2).map(multiply(4)).map(add(2));
|
|