

Objects vs. Functions round 1: Currying vs. Instantiation - galaxyLogic
http://panuviljamaablog.blogspot.com/2014/03/objects-vs-functions-round-1-currying.html

======
devwebee
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));

