Last active
          November 20, 2017 20:40 
        
      - 
      
 - 
        
Save donabrams/7e25f5921f33ff49947830e9cfa6ad9f to your computer and use it in GitHub Desktop.  
    choice.js - OOP Either
  
        
  
    
      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
    
  
  
    
  | const choice = (decision) => { | |
| let yes = () => {}; | |
| let no = () => {}; | |
| const a = { | |
| yes: (f) => { yes = f; return a; }, | |
| no: (f) => { no = f; return a; }, | |
| decide: () => { | |
| const next = decision() ? yes() : no(); | |
| return next.decide ? next.decide() : next; | |
| } | |
| }; | |
| return a; | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment