Created
          March 6, 2015 02:18 
        
      - 
      
- 
        Save nobeans/ffdd70d4629e5afe02a9 to your computer and use it in GitHub Desktop. 
    Composition of functions by Groovy
  
        
  
    
      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
    
  
  
    
  | def by8 = { it * 8 } | |
| def plus3 = { it + 3 } | |
| def devide2 = { it / 2 } | |
| // two closures | |
| assert (by8 << plus3).call(3) == 48 | |
| assert (plus3 >> by8).call(3) == 48 | |
| assert (plus3 >> by8)(3) == 48 | |
| // three closures | |
| assert (plus3 >> by8 >> devide2)(3) == 24 | |
| assert (devide2 << by8 << plus3)(3) == 24 | |
| assert (devide2 >> by8 << plus3).call(3) == 24 | |
| assert ((devide2 >> by8) << plus3).call(3) == 24 | |
| assert (devide2 >> (by8 << plus3)).call(3) == 36 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment