You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Les Hartzman <lh...@gmail.com> on 2015/10/01 19:22:39 UTC
Iterate over 2 lists in a closure?
Hi,
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 type.
Basically I want to compare elements in the lists to see if they are equal.
Thanks.
Les
Re: Iterate over 2 lists in a closure?
Posted by Juan Vazquez <ju...@gmail.com>.
Would this work? Tried with simple classes and ints. Not sure if it fits
your scenario
//equal would is an empty list... using groovy truth
if(list1 - list2){
println "not equal"
}else{
println "equal"
}
Thanks,
Juan
On Fri, Oct 2, 2015 at 8:08 AM, Winnebeck, Jason <
Jason.Winnebeck@windstream.com> wrote:
> As for Dinko's note that transpose is on List -- I don't know how I've
> missed it -- I had been looking for this feature in Groovy a long time
> (under the name of "zip" like it's found in Python). Maybe it's because I
> normally check Iterable and Collection added methods more often than list.
> I would second Schalk's comment about adding a zip function that works with
> Iterable/Iterator. Whether or not it should match with "null" when one
> iterator is longer than the other is up for debate, but both transpose in
> Groovy and zip in Python both ignore any "extra" elements, although there
> is a zip_longest() in Python that takes a "fill value" to use. I'd propose
> the method is defined so any of the following work:
>
> zip(a, b)
> a.zip(b)
> zip(a, b,c,d)
> a.zip(b,c,d)
>
> I think that would be compatible with Groovy extension methods if it's
> defined as:
>
> static <T> Iterable<T> zip(Iterable<? extends T> self, Iterable<? extends
> T>... others)
>
> Jason
>
> -----Original Message-----
> From: Schalk Cronjé [mailto:ysb33r@gmail.com]
> Sent: Friday, October 02, 2015 5:22 AM
> To: users@groovy.incubator.apache.org
> Subject: Re: Iterate over 2 lists in a closure?
>
> This thread made me think a zip iterator could be a useful addition to the
> language.
>
> def myList = [1,2,3]
> def myMap = [ a:'b', c:'d', e:'f' ]
> zip(myList,myMap).each { l,m -> println "$l $m" }
>
> Prints out
> 1 a=b
> 2 c=d
> 3 e=f
>
> If one collection is exhausted, whilst the other is not, then just return
> 'null' for the additional items.
>
>
> On 02/10/2015 09:44, Dinko Srkoč wrote:
> > On 1 October 2015 at 19:47, Winnebeck, Jason
> > <Ja...@windstream.com> wrote:
> >> [...]
> >> 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]
> >> }
> >>
> > There's an easier way to use `transpose`:
> >
> > assert ['a1', 'b2'] == [letters, numbers].transpose()*.join('')
> >
> > Cheers,
> > Dinko
> >
> >>
> >> In your case of testing a condition (equality) you can use any method
> >> instead of collect.
> >>
> >>
> >>
> >> Jason
> >>
> >>
> >>
> >> From: Owen Rubel [mailto:orubel@gmail.com]
> >> Sent: Thursday, October 01, 2015 1:28 PM
> >> To: users@groovy.incubator.apache.org
> >> Subject: Re: Iterate over 2 lists in a closure?
> >>
> >>
> >>
> >> if(list1.contains(list2) && list2.contains(list1)){ true }
> >>
> >>
> >> Owen Rubel
> >> 415-971-0976
> >> orubel@gmail.com
> >>
> >>
> >>
> >> On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com>
> wrote:
> >>
> >> Hi,
> >>
> >>
> >>
> >> 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 type.
> >>
> >>
> >>
> >> Basically I want to compare elements in the lists to see if they are
> equal.
> >>
> >>
> >>
> >> Thanks.
> >>
> >>
> >>
> >> Les
> >>
> >>
> >>
> >>
> >>
> >> ________________________________
> >> 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.
>
>
> --
> Schalk W. Cronjé
> Twitter / Ello / Toeter : @ysb33r
>
>
> ----------------------------------------------------------------------
> 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.
>
--
-Juan
Re: Iterate over 2 lists in a closure?
Posted by Shil Sinha <sh...@gmail.com>.
I like the idea of having a default fill value as well, though if the zip
method (maybe different from zip_longest) is defined as a non-static
extension method I think it would make sense for the result to have as many
rows as 'self' has elements.
On Fri, Oct 2, 2015 at 10:50 AM, Schalk Cronjé <ys...@gmail.com> wrote:
> I like the zip_longest suggestion.
>
>
> On 02/10/2015 14:08, Winnebeck, Jason wrote:
>
>> As for Dinko's note that transpose is on List -- I don't know how I've
>> missed it -- I had been looking for this feature in Groovy a long time
>> (under the name of "zip" like it's found in Python). Maybe it's because I
>> normally check Iterable and Collection added methods more often than list.
>> I would second Schalk's comment about adding a zip function that works with
>> Iterable/Iterator. Whether or not it should match with "null" when one
>> iterator is longer than the other is up for debate, but both transpose in
>> Groovy and zip in Python both ignore any "extra" elements, although there
>> is a zip_longest() in Python that takes a "fill value" to use. I'd propose
>> the method is defined so any of the following work:
>>
>> zip(a, b)
>> a.zip(b)
>> zip(a, b,c,d)
>> a.zip(b,c,d)
>>
>> I think that would be compatible with Groovy extension methods if it's
>> defined as:
>>
>> static <T> Iterable<T> zip(Iterable<? extends T> self, Iterable<? extends
>> T>... others)
>>
>> Jason
>>
>> -----Original Message-----
>> From: Schalk Cronjé [mailto:ysb33r@gmail.com]
>> Sent: Friday, October 02, 2015 5:22 AM
>> To: users@groovy.incubator.apache.org
>> Subject: Re: Iterate over 2 lists in a closure?
>>
>> This thread made me think a zip iterator could be a useful addition to
>> the language.
>>
>> def myList = [1,2,3]
>> def myMap = [ a:'b', c:'d', e:'f' ]
>> zip(myList,myMap).each { l,m -> println "$l $m" }
>>
>> Prints out
>> 1 a=b
>> 2 c=d
>> 3 e=f
>>
>> If one collection is exhausted, whilst the other is not, then just return
>> 'null' for the additional items.
>>
>>
>> On 02/10/2015 09:44, Dinko Srkoč wrote:
>>
>>> On 1 October 2015 at 19:47, Winnebeck, Jason
>>> <Ja...@windstream.com> wrote:
>>>
>>>> [...]
>>>> 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]
>>>> }
>>>>
>>>> There's an easier way to use `transpose`:
>>>
>>> assert ['a1', 'b2'] == [letters, numbers].transpose()*.join('')
>>>
>>> Cheers,
>>> Dinko
>>>
>>> In your case of testing a condition (equality) you can use any method
>>>> instead of collect.
>>>>
>>>>
>>>>
>>>> Jason
>>>>
>>>>
>>>>
>>>> From: Owen Rubel [mailto:orubel@gmail.com]
>>>> Sent: Thursday, October 01, 2015 1:28 PM
>>>> To: users@groovy.incubator.apache.org
>>>> Subject: Re: Iterate over 2 lists in a closure?
>>>>
>>>>
>>>>
>>>> if(list1.contains(list2) && list2.contains(list1)){ true }
>>>>
>>>>
>>>> Owen Rubel
>>>> 415-971-0976
>>>> orubel@gmail.com
>>>>
>>>>
>>>>
>>>> On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com>
>>>> wrote:
>>>>
>>>> Hi,
>>>>
>>>>
>>>>
>>>> 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 type.
>>>>
>>>>
>>>>
>>>> Basically I want to compare elements in the lists to see if they are
>>>> equal.
>>>>
>>>>
>>>>
>>>> Thanks.
>>>>
>>>>
>>>>
>>>> Les
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> ________________________________
>>>> 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.
>>>>
>>>
>>
>
> --
> Schalk W. Cronjé
> Twitter / Ello / Toeter : @ysb33r
>
>
Re: Iterate over 2 lists in a closure?
Posted by Schalk Cronjé <ys...@gmail.com>.
I like the zip_longest suggestion.
On 02/10/2015 14:08, Winnebeck, Jason wrote:
> As for Dinko's note that transpose is on List -- I don't know how I've missed it -- I had been looking for this feature in Groovy a long time (under the name of "zip" like it's found in Python). Maybe it's because I normally check Iterable and Collection added methods more often than list. I would second Schalk's comment about adding a zip function that works with Iterable/Iterator. Whether or not it should match with "null" when one iterator is longer than the other is up for debate, but both transpose in Groovy and zip in Python both ignore any "extra" elements, although there is a zip_longest() in Python that takes a "fill value" to use. I'd propose the method is defined so any of the following work:
>
> zip(a, b)
> a.zip(b)
> zip(a, b,c,d)
> a.zip(b,c,d)
>
> I think that would be compatible with Groovy extension methods if it's defined as:
>
> static <T> Iterable<T> zip(Iterable<? extends T> self, Iterable<? extends T>... others)
>
> Jason
>
> -----Original Message-----
> From: Schalk Cronjé [mailto:ysb33r@gmail.com]
> Sent: Friday, October 02, 2015 5:22 AM
> To: users@groovy.incubator.apache.org
> Subject: Re: Iterate over 2 lists in a closure?
>
> This thread made me think a zip iterator could be a useful addition to the language.
>
> def myList = [1,2,3]
> def myMap = [ a:'b', c:'d', e:'f' ]
> zip(myList,myMap).each { l,m -> println "$l $m" }
>
> Prints out
> 1 a=b
> 2 c=d
> 3 e=f
>
> If one collection is exhausted, whilst the other is not, then just return 'null' for the additional items.
>
>
> On 02/10/2015 09:44, Dinko Srkoč wrote:
>> On 1 October 2015 at 19:47, Winnebeck, Jason
>> <Ja...@windstream.com> wrote:
>>> [...]
>>> 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]
>>> }
>>>
>> There's an easier way to use `transpose`:
>>
>> assert ['a1', 'b2'] == [letters, numbers].transpose()*.join('')
>>
>> Cheers,
>> Dinko
>>
>>> In your case of testing a condition (equality) you can use any method
>>> instead of collect.
>>>
>>>
>>>
>>> Jason
>>>
>>>
>>>
>>> From: Owen Rubel [mailto:orubel@gmail.com]
>>> Sent: Thursday, October 01, 2015 1:28 PM
>>> To: users@groovy.incubator.apache.org
>>> Subject: Re: Iterate over 2 lists in a closure?
>>>
>>>
>>>
>>> if(list1.contains(list2) && list2.contains(list1)){ true }
>>>
>>>
>>> Owen Rubel
>>> 415-971-0976
>>> orubel@gmail.com
>>>
>>>
>>>
>>> On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>>
>>>
>>> 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 type.
>>>
>>>
>>>
>>> Basically I want to compare elements in the lists to see if they are equal.
>>>
>>>
>>>
>>> Thanks.
>>>
>>>
>>>
>>> Les
>>>
>>>
>>>
>>>
>>>
>>> ________________________________
>>> 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.
>
--
Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r
RE: Iterate over 2 lists in a closure?
Posted by "Winnebeck, Jason" <Ja...@windstream.com>.
As for Dinko's note that transpose is on List -- I don't know how I've missed it -- I had been looking for this feature in Groovy a long time (under the name of "zip" like it's found in Python). Maybe it's because I normally check Iterable and Collection added methods more often than list. I would second Schalk's comment about adding a zip function that works with Iterable/Iterator. Whether or not it should match with "null" when one iterator is longer than the other is up for debate, but both transpose in Groovy and zip in Python both ignore any "extra" elements, although there is a zip_longest() in Python that takes a "fill value" to use. I'd propose the method is defined so any of the following work:
zip(a, b)
a.zip(b)
zip(a, b,c,d)
a.zip(b,c,d)
I think that would be compatible with Groovy extension methods if it's defined as:
static <T> Iterable<T> zip(Iterable<? extends T> self, Iterable<? extends T>... others)
Jason
-----Original Message-----
From: Schalk Cronjé [mailto:ysb33r@gmail.com]
Sent: Friday, October 02, 2015 5:22 AM
To: users@groovy.incubator.apache.org
Subject: Re: Iterate over 2 lists in a closure?
This thread made me think a zip iterator could be a useful addition to the language.
def myList = [1,2,3]
def myMap = [ a:'b', c:'d', e:'f' ]
zip(myList,myMap).each { l,m -> println "$l $m" }
Prints out
1 a=b
2 c=d
3 e=f
If one collection is exhausted, whilst the other is not, then just return 'null' for the additional items.
On 02/10/2015 09:44, Dinko Srkoč wrote:
> On 1 October 2015 at 19:47, Winnebeck, Jason
> <Ja...@windstream.com> wrote:
>> [...]
>> 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]
>> }
>>
> There's an easier way to use `transpose`:
>
> assert ['a1', 'b2'] == [letters, numbers].transpose()*.join('')
>
> Cheers,
> Dinko
>
>>
>> In your case of testing a condition (equality) you can use any method
>> instead of collect.
>>
>>
>>
>> Jason
>>
>>
>>
>> From: Owen Rubel [mailto:orubel@gmail.com]
>> Sent: Thursday, October 01, 2015 1:28 PM
>> To: users@groovy.incubator.apache.org
>> Subject: Re: Iterate over 2 lists in a closure?
>>
>>
>>
>> if(list1.contains(list2) && list2.contains(list1)){ true }
>>
>>
>> Owen Rubel
>> 415-971-0976
>> orubel@gmail.com
>>
>>
>>
>> On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com> wrote:
>>
>> Hi,
>>
>>
>>
>> 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 type.
>>
>>
>>
>> Basically I want to compare elements in the lists to see if they are equal.
>>
>>
>>
>> Thanks.
>>
>>
>>
>> Les
>>
>>
>>
>>
>>
>> ________________________________
>> 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.
--
Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r
----------------------------------------------------------------------
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.
Re: Iterate over 2 lists in a closure?
Posted by Schalk Cronjé <ys...@gmail.com>.
This thread made me think a zip iterator could be a useful addition to
the language.
def myList = [1,2,3]
def myMap = [ a:'b', c:'d', e:'f' ]
zip(myList,myMap).each { l,m -> println "$l $m" }
Prints out
1 a=b
2 c=d
3 e=f
If one collection is exhausted, whilst the other is not, then just
return 'null' for the additional items.
On 02/10/2015 09:44, Dinko Srkoč wrote:
> On 1 October 2015 at 19:47, Winnebeck, Jason
> <Ja...@windstream.com> wrote:
>> [...]
>> 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]
>> }
>>
> There's an easier way to use `transpose`:
>
> assert ['a1', 'b2'] == [letters, numbers].transpose()*.join('')
>
> Cheers,
> Dinko
>
>>
>> In your case of testing a condition (equality) you can use any method
>> instead of collect.
>>
>>
>>
>> Jason
>>
>>
>>
>> From: Owen Rubel [mailto:orubel@gmail.com]
>> Sent: Thursday, October 01, 2015 1:28 PM
>> To: users@groovy.incubator.apache.org
>> Subject: Re: Iterate over 2 lists in a closure?
>>
>>
>>
>> if(list1.contains(list2) && list2.contains(list1)){ true }
>>
>>
>> Owen Rubel
>> 415-971-0976
>> orubel@gmail.com
>>
>>
>>
>> On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com> wrote:
>>
>> Hi,
>>
>>
>>
>> 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 type.
>>
>>
>>
>> Basically I want to compare elements in the lists to see if they are equal.
>>
>>
>>
>> Thanks.
>>
>>
>>
>> Les
>>
>>
>>
>>
>>
>> ________________________________
>> 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.
--
Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r
Re: Iterate over 2 lists in a closure?
Posted by Dinko Srkoč <di...@gmail.com>.
On 1 October 2015 at 19:47, Winnebeck, Jason
<Ja...@windstream.com> wrote:
> [...]
> 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]
> }
>
There's an easier way to use `transpose`:
assert ['a1', 'b2'] == [letters, numbers].transpose()*.join('')
Cheers,
Dinko
>
>
> In your case of testing a condition (equality) you can use any method
> instead of collect.
>
>
>
> Jason
>
>
>
> From: Owen Rubel [mailto:orubel@gmail.com]
> Sent: Thursday, October 01, 2015 1:28 PM
> To: users@groovy.incubator.apache.org
> Subject: Re: Iterate over 2 lists in a closure?
>
>
>
> if(list1.contains(list2) && list2.contains(list1)){ true }
>
>
> Owen Rubel
> 415-971-0976
> orubel@gmail.com
>
>
>
> On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com> wrote:
>
> Hi,
>
>
>
> 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 type.
>
>
>
> Basically I want to compare elements in the lists to see if they are equal.
>
>
>
> Thanks.
>
>
>
> Les
>
>
>
>
>
> ________________________________
> 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.
RE: Iterate over 2 lists in a closure?
Posted by "Winnebeck, Jason" <Ja...@windstream.com>.
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<http://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/Iterable.html#any(groovy.lang.Closure)> method instead of collect.
Jason
From: Owen Rubel [mailto:orubel@gmail.com]
Sent: Thursday, October 01, 2015 1:28 PM
To: users@groovy.incubator.apache.org
Subject: Re: Iterate over 2 lists in a closure?
if(list1.contains(list2) && list2.contains(list1)){ true }
Owen Rubel
415-971-0976
orubel@gmail.com<ma...@gmail.com>
On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com>> wrote:
Hi,
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 type.
Basically I want to compare elements in the lists to see if they are equal.
Thanks.
Les
----------------------------------------------------------------------
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.
Re: Iterate over 2 lists in a closure?
Posted by Owen Rubel <or...@gmail.com>.
there ya go. :)
Owen Rubel
415-971-0976
orubel@gmail.com
On Thu, Oct 1, 2015 at 10:42 AM, Les Hartzman <lh...@gmail.com> wrote:
> Thanks. I also just discovered: list1.equals(list2).
>
> On Thu, Oct 1, 2015 at 10:28 AM, Owen Rubel <or...@gmail.com> wrote:
>
>> if(list1.contains(list2) && list2.contains(list1)){ true }
>>
>> Owen Rubel
>> 415-971-0976
>> orubel@gmail.com
>>
>> On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> 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 type.
>>>
>>> Basically I want to compare elements in the lists to see if they are
>>> equal.
>>>
>>> Thanks.
>>>
>>> Les
>>>
>>>
>>
>
Re: Iterate over 2 lists in a closure?
Posted by Les Hartzman <lh...@gmail.com>.
Thanks. I also just discovered: list1.equals(list2).
On Thu, Oct 1, 2015 at 10:28 AM, Owen Rubel <or...@gmail.com> wrote:
> if(list1.contains(list2) && list2.contains(list1)){ true }
>
> Owen Rubel
> 415-971-0976
> orubel@gmail.com
>
> On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com> wrote:
>
>> Hi,
>>
>> 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 type.
>>
>> Basically I want to compare elements in the lists to see if they are
>> equal.
>>
>> Thanks.
>>
>> Les
>>
>>
>
Re: Iterate over 2 lists in a closure?
Posted by Owen Rubel <or...@gmail.com>.
if(list1.contains(list2) && list2.contains(list1)){ true }
Owen Rubel
415-971-0976
orubel@gmail.com
On Thu, Oct 1, 2015 at 10:22 AM, Les Hartzman <lh...@gmail.com> wrote:
> Hi,
>
> 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 type.
>
> Basically I want to compare elements in the lists to see if they are equal.
>
> Thanks.
>
> Les
>
>