« Return to Thread: Groovy syntax /API enhancement

Re: Groovy syntax /API enhancement

by Tom Nichols :: Rate this Message:

Reply to Author | View in Thread

On Sun, Apr 20, 2008 at 7:20 PM, Jochen Theodorou <blackdrag@...> wrote:

> >   4. support everyWithIndex, anyWithIndex, collectWithIndex,
> >
> >      sumWithIndex etc. it's even better if the original every, any has
> >      an implicit variable/syntax for retrieving the index
> >      e.g. [10,20].collectWithIndex{ it,i -> it*(i+1) } = [ 10, 40 ]
> >
>
>  I am against all these withIndex methods... they are polluting the API so
> much. I would like to have a more general solution, but I can't think of any
> yet

Can't you just modify the each/any/collect methods to test how many
parameters the closure takes?  If the closure only takes one param
assume it is the item.  If it takes two params, assume (item, index).
No?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: Groovy syntax /API enhancement