groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <>
Subject RE: Iterate over 2 lists in a closure?
Date Thu, 01 Oct 2015 17:47:19 GMT
If your user defined types implement equals as you need, then you can just do list1 == list2.
Owen’s solution allows equality when order is different or there are duplicates.

This also sounds like a zip operation, which took me a really long time to find in Groovy
but I recently found it:

def letters = ['a', 'b']
def numbers = [1, 2]

assert ['a1', 'b2'] ==
       GroovyCollections.transpose(letters, numbers).collect { it[0] + it[1] }

In your case of testing a condition (equality) you can use any<>
method instead of collect.


From: Owen Rubel []
Sent: Thursday, October 01, 2015 1:28 PM
Subject: Re: Iterate over 2 lists in a closure?

if(list1.contains(list2) && list2.contains(list1)){ true }

Owen Rubel

On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <<>>

I want to know if it's possible to have a closure that can iterate over 2 equal length lists?
The equivalent of doing list1.each, list2.each { ... }, where each list is a list of an user-defined

Basically I want to compare elements in the lists to see if they are equal.



This email message and any attachments are for the sole use of the intended recipient(s).
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all copies of the
original message and any attachments.
View raw message