groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jennifer Strater <jenn.stra...@gmail.com>
Subject Re: Unexpected use of "collection.field.first()"
Date Wed, 13 Jan 2016 19:59:32 GMT
I found two different ways to answer this.

1.)
http://stackoverflow.com/questions/32723147/groovy-implicit-spread-dot-operator
This question from stackoverflow, which references the Groovy documentation
for GPath expressions.

2.)
http://naleid.com/blog/2008/12/24/groovy-spread-operator-optional-for-properties-plus-a-peek-into-the-sausage-factory/
This wonderful blog post that dives into the details.

Is this what you were looking for?

On Wed, Jan 13, 2016 at 1:09 PM, David M. Karr <davidmichaelkarr@gmail.com>
wrote:

>
>
> On 01/13/2016 10:50 AM, Jennifer Strater wrote:
>
> Hi David,
>
> I assume the confusion is related to the implicit spread-dot? If you look
> at the result of data.childs.name you will find [Judith,Adriana].  It
> then takes the first element of that list.
>
>
> Oh, right.  So when does Groovy do the spread-dot operator "implicitly"?
>
>
> -Jenn
>
> On Wed, Jan 13, 2016 at 12:38 PM, David M. Karr <
> davidmichaelkarr@gmail.com> wrote:
>
>> Today I noticed an unexpected way the "first()" function behaves. I'd
>> appreciate some clarification.
>>
>> With the following data:
>>
>> def data = [
>>   name : 'Ivan', age: 35,
>>   childs : [
>>     [name: 'Judith', age:8], [name: 'Adriana', age:5]
>>     ]
>> ]
>>
>> The following two statements produce the same result:
>>
>> println data.childs.first().name
>> println data.childs.name.first()
>>
>> Being "Judith".
>>
>> The first one is obvious to me.  The second one is unexpected. What's
>> going on here exactly?
>>
>
>
>

Mime
View raw message