[ 
https://issues.apache.org/jira/browse/GROOVY-7556?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14711248#comment-14711248
 ] 

Matt Whipple commented on GROOVY-7556:
--------------------------------------

Sure, I could probably submit a PR also in the next several days if that would 
be easier.  A basic example based on the existing code would be:

{code}
//Forward
 def twice = { a -> a * 2 }
 def add3 = { a -> a + 3 }
 def transform = twice >> add3
 // equivalent: transform = { a -> add3(twice(a)) }
 assert transform(3) == 9

//Reverse
 def twice = { a -> a * 2 }
 def add3 = { a -> a + 3 }
 def transform = twice << add3
 // equivalent: transform = { a -> twice(add3(a)) }
 assert transform(3) == 12
{code}

I'd actually missed the fact that the arguments were also swapped between the 
two examples so the same could be done here but in the existing example it 
wouldn't have an impact either way.

> Use better example for Closure composition
> ------------------------------------------
>
>                 Key: GROOVY-7556
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7556
>             Project: Groovy
>          Issue Type: Documentation
>            Reporter: Matt Whipple
>            Priority: Minor
>
> The present examples in 
> http://docs.groovy-lang.org/latest/html/api/groovy/lang/Closure.html of using 
> solely multiplication for #leftShift and #rightShift isn't particularly 
> illuminating about the differences between forward and reverse composition. 
> Using different operators or something not associative/commutative so that 
> the results differ could help. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to