- 
      
 - 
        
Save vstarck/2362274 to your computer and use it in GitHub Desktop.  
    x.js
  
        
  
    
      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
    
  
  
    
  | // create a number type | |
| hug('type')('number'); | |
| // set the constructor | |
| hug('type')('number')('#set')('init', function($self, num) { | |
| $self('#set')('#value', isNaN(Number(num)) ? 0 : Number(num)); | |
| }); | |
| // methods... | |
| hug('type')('number')('#set')('+', function($self, $rest) { | |
| var num = $rest.reduce(function(memo, current) { | |
| return memo + current('#value'); | |
| }, $self()); | |
| return $self('#type')()('#new')(num); | |
| }); | |
| // shortcut | |
| var number = hug('type')('number'); | |
| var one = number('#new')(1); | |
| var two = number('#new')(2); | |
| var three = number('#new')(3); | |
| var six = one('+', two, three); | |
| var twelve = one('+', one, one, one, one, one, six); | |
| six(); // 6 | |
| twelve(); //12 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment