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 19:09:20 GMT


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