Last active
          December 16, 2015 01:14 
        
      - 
      
 - 
        
Save cem2ran/06a29350d807aaba9d82 to your computer and use it in GitHub Desktop.  
    Auto-currying for the masses
  
        
  
    
      This file contains hidden or 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.prototype.curried = function (f=this) { | |
| return (...args) => args.length < f.length | |
| ? f.curried(args.reduce((g, arg) => g.bind(null, arg), f)) | |
| : f.apply(null, args); | |
| }; | 
  
    
      This file contains hidden or 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
    
  
  
    
  | var adder = function(a,b,c) { | |
| return a + b + c; | |
| }; | |
| var add = adder.curried(); | |
| var add3 = add(1)(2) | |
| console.log(add(1)(2)(3)) //=> 6 | |
| console.log(add(4,5)(6)) //=> 15 | |
| console.log(add3(5)) //=> 8 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment