groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David M. Karr" <davidmichaelk...@gmail.com>
Subject Re: Unexpected use of "collection.field.first()"
Date Wed, 13 Jan 2016 20:23:36 GMT
On 01/13/2016 11:59 AM, Jennifer Strater wrote:
> 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?

Uh, yeah, and now I see that I've already gone down this path before, as 
I was one of the commenters on that posting. :)

>
> On Wed, Jan 13, 2016 at 1:09 PM, David M. Karr 
> <davidmichaelkarr@gmail.com <mailto: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
>>     <http://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 <mailto: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