Marc Palmer | 17 Jul 23:13

[groovy-user] Idea / a better way to do this?

Hi,

I wanted to see if a condition holds for all elements in a collection,  
but I cannot (it is late) see a clean simple way of doing this using  
the GDK.

We don't seem to have something like:

def allmatch = someList.holdsTrue { it.age > 25 }

I can't see how to do this at the moment without an external var of  
some kind to track state - maybe I'm missing something?

If not, shall I jira this for 2.0?

Marc

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

    http://xircles.codehaus.org/manage_email

Ladislav Thon | 17 Jul 23:21

Re: [groovy-user] Idea / a better way to do this?

From http://groovy.codehaus.org/GDK+Extensions+to+Object

def numbers = [ 5, 7, 9, 12 ]
assert numbers.every { it > 4 } //returns true since all #s are > 4

I believe this is just the thing you want :-)

LT

2008/7/17 Marc Palmer <marc-jTVUvg37bMAqdlJmJB21zg@public.gmane.org>:
Hi,

I wanted to see if a condition holds for all elements in a collection, but I cannot (it is late) see a clean simple way of doing this using the GDK.

We don't seem to have something like:

def allmatch = someList.holdsTrue { it.age > 25 }

I can't see how to do this at the moment without an external var of some kind to track state - maybe I'm missing something?

If not, shall I jira this for 2.0?

Marc




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

  http://xircles.codehaus.org/manage_email



Marc Palmer | 30 Jul 15:41

Re: [groovy-user] Idea / a better way to do this?


On 17 Jul 2008, at 22:21, Ladislav Thon wrote:

> From http://groovy.codehaus.org/GDK+Extensions+to+Object
>
> def numbers = [ 5, 7, 9, 12 ]
> assert numbers.every { it > 4 } //returns true since all #s are > 4

Actually, no I want the resulting list of all matching values.  
x.findAll is what I want :)

Cheers

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

    http://xircles.codehaus.org/manage_email

Dierk König | 17 Jul 23:32

RE: [groovy-user] Idea / a better way to do this?


someList.every { it.age > 25 }

cheers
Dierk 

| -----Original Message-----
| From: Marc Palmer [mailto:marc@...] 
| Sent: Donnerstag, 17. Juli 2008 23:17
| To: Groovy User
| Subject: [groovy-user] Idea / a better way to do this?
| 
| Hi,
| 
| I wanted to see if a condition holds for all elements in a 
| collection, but I cannot (it is late) see a clean simple way 
| of doing this using the GDK.
| 
| We don't seem to have something like:
| 
| def allmatch = someList.holdsTrue { it.age > 25 }
| 
| I can't see how to do this at the moment without an external 
| var of some kind to track state - maybe I'm missing something?
| 
| If not, shall I jira this for 2.0?
| 
| Marc
| 
| 
| 
| 
| ---------------------------------------------------------------------
| 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


Gmane