groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Clark <plotinussm...@gmail.com>
Subject Re: closures and iterators
Date Mon, 15 Jun 2015 05:19:19 GMT
Try something like this:

response.data.each {
   it.children.each {
     it.children.each {
       it.children.each {grower ->
         println([grower.type, grower.profile_id,grower.name  <http://it.name>, grower.created,
grower.modified,"",""].join("|"))
         it.children.each {farm ->
           println([farm.type, farm.farm_id,farm.name  <http://it.name>, farm.created,
farm.modified,grower.profile_id,""].join("|"))
           it.children.each {field ->
             println([field.type, field.field_id,field.name  <http://it.name>, field.created,
field.modified,grower.profile_id,farm.farm_id].join("|")) } } } } } }

Moving the brackets is optional, it just hurts my eyes to see all of 
those dangling angle brackets each on a line by itself.

On 06/14/2015 11:45 PM, Kurt Andrews wrote:
> I'm trying to figure out how to pass an extra parameter to the closure 
> that's being passed to each in the following code
>
> response.data.each {
>    it.children.each {
>      it.children.each {
>        it.children.each {// growers
>          println([it.type, it.profile_id,it.name  <http://it.name>, it.created,
it.modified,"",""].join("|"))
>          it.children.each {// farms
>            println([it.type, it.farm_id,it.name  <http://it.name>, it.created,
it.modified,grower.profile_id,""].join("|"))
>            it.children.each {// fields
>              println([it.type, it.field_id,it.name  <http://it.name>, it.created,
it.modified,grower.profile_id,farm.farm_id].join("|"))
>            }
>          }
>        }
>      }
>    }
> }
> I'm trying to pass the grower profile_id down to the farms and the 
> fields and pass the farms farm_id down to fields.   Is there a simple 
> way to do this?
>
> Thanks,
>
> Kurt


Mime
View raw message