The thought occurs to me...how about 'codifying' this behaviour?
I propose something like:
def a = [ 1, 2 ]
a[0..>3]
Which would introduce a size-aware range subscript...
Thoughts/Comments?
BOB
> -----Original Message-----
> From: Bob Brown [mailto:
bob@...]
> Sent: Friday, 6 November 2009 8:40 AM
> To:
user@...
> Subject: RE: [groovy-user] Simple I'm sure.. best way to grab the first
> three items from a collection
>
> A case could be made for a bit of "defensive programming" here:
>
> def a = [ 1, 2 ]
> a[0..<Math.min(3, a.size())]
>
> Cheers,
>
> BOB
>
> > -----Original Message-----
> > From: Rick [mailto:
rickcr@...]
> > Sent: Friday, 6 November 2009 8:24 AM
> > To: Groovy Users List
> > Subject: [groovy-user] Simple I'm sure.. best way to grab the first
> > three items from a collection
> >
> > This should be so simple, but I'm stumped on the best way to do it.
> >
> > Have a collection of x number of Foo items. I want the first three
> from
> > this collection.
> >
> > Thanks an advance. I know the answer is going to be a "duh. why
> didn't
> > I think of that" moment.
> >
> > --
> > Rick R
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>
http://xircles.codehaus.org/manage_email>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email