Robert Fischer | 18 Aug 21:22
Favicon
Gravatar

[groovy-dev] Closure Arguments?

(Hit up the user list again, but I'm apparently still not subscribed.)

Is there a way to allow a closure to take an arbitrary number of arguments and get them as a list?
I'm thinking of a behavior similar to Java's varargs.

Notably, the API already has Closure#run taking a single value or a list of values, so I guess I'm
really just asking if that's exposed in the Groovy syntax somewhere.

~~ Robert.

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

    http://xircles.codehaus.org/manage_email

Robert Fischer | 18 Aug 21:33
Favicon
Gravatar

[groovy-dev] Re: Closure Arguments?

Sure, ask a question and immediately the answer dawns on you.

Looks like you can do { Object[] args -> } and it will get you that behavior.

Nifty.

~~ Robert.

Robert Fischer wrote:
> (Hit up the user list again, but I'm apparently still not subscribed.)
> 
> Is there a way to allow a closure to take an arbitrary number of arguments and get them as a list?
> I'm thinking of a behavior similar to Java's varargs.
> 
> Notably, the API already has Closure#run taking a single value or a list of values, so I guess I'm
> really just asking if that's exposed in the Groovy syntax somewhere.
> 
> ~~ Robert.
> 

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

    http://xircles.codehaus.org/manage_email

Jim White | 18 Aug 22:57

Re: [groovy-dev] Re: Closure Arguments?

Robert Fischer wrote:
> Sure, ask a question and immediately the answer dawns on you.
> 
> Looks like you can do { Object[] args -> } and it will get you that behavior.

The Java syntax is supported also:

{ Object... args -> }

Jim

> Nifty.
> 
> ~~ Robert.
> 
> Robert Fischer wrote:
> 
>>(Hit up the user list again, but I'm apparently still not subscribed.)
>>
>>Is there a way to allow a closure to take an arbitrary number of arguments and get them as a list?
>>I'm thinking of a behavior similar to Java's varargs.
>>
>>Notably, the API already has Closure#run taking a single value or a list of values, so I guess I'm
>>really just asking if that's exposed in the Groovy syntax somewhere.
>>
>>~~ Robert.
>>
> 
> 
> ---------------------------------------------------------------------
(Continue reading)


Gmane