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 18:50:41 GMT
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.

-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