Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8B55A18697 for ; Mon, 15 Jun 2015 05:20:28 +0000 (UTC) Received: (qmail 57390 invoked by uid 500); 15 Jun 2015 05:20:28 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 57349 invoked by uid 500); 15 Jun 2015 05:20:28 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 57339 invoked by uid 99); 15 Jun 2015 05:20:28 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jun 2015 05:20:28 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id E80A71A5637 for ; Mon, 15 Jun 2015 05:20:27 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.901 X-Spam-Level: ** X-Spam-Status: No, score=2.901 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, WEIRD_QUOTING=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id At2eVc_IB7Ad for ; Mon, 15 Jun 2015 05:20:14 +0000 (UTC) Received: from mail-oi0-f48.google.com (mail-oi0-f48.google.com [209.85.218.48]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 583C024CEA for ; Mon, 15 Jun 2015 05:20:13 +0000 (UTC) Received: by oial131 with SMTP id l131so18534722oia.3 for ; Sun, 14 Jun 2015 22:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=mewyLoDTLoDLwHI9qrLBNZJ0rBsrHM+nC0pMzgyVGg0=; b=Fnjs207ZqfqHrgWmoHFNgTvT/yu1GEmhWU8bQf2cFozK7fy95kVF/mJSOBWE2VoCWQ GA+KSr3l/GDCOIlIvSbS7N+bSVelLUyQhmRUClBvAP/VDJIV1RTS8CPjkyZv5y5Vho0D me1Y13BdplqOCkMOU+3BxDZJswNZPNLyuFq+PBQ4KipkzyXUo3z0xKl2+Ym/jTnHNwuZ 01WbcsvvmAdH8wQK/xFltzAEH2nR6aNUb4Xuc3GGD3UGr/wJnLk6PD7Gde5fyIDTXGiA nxNQgIUT6YLTufdtDF8M2bL8FX4uE0Km07ZY6NRrHiP5MUjRvonfdp7oE8Ga2npqxrlN g9MA== X-Received: by 10.60.125.229 with SMTP id mt5mr22412469oeb.18.1434345561532; Sun, 14 Jun 2015 22:19:21 -0700 (PDT) Received: from [192.168.0.133] (cpe-70-121-13-147.tx.res.rr.com. [70.121.13.147]) by mx.google.com with ESMTPSA id d70sm8255546oih.16.2015.06.14.22.19.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Jun 2015 22:19:21 -0700 (PDT) Message-ID: <557E6057.5060106@gmail.com> Date: Mon, 15 Jun 2015 00:19:19 -0500 From: David Clark User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: users@groovy.incubator.apache.org Subject: Re: closures and iterators References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------060709030705060901030000" This is a multi-part message in MIME format. --------------060709030705060901030000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 , grower.created, grower.modified,"",""].join("|")) it.children.each {farm -> println([farm.type, farm.farm_id,farm.name , farm.created, farm.modified,grower.profile_id,""].join("|")) it.children.each {field -> println([field.type, field.field_id,field.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 , it.created, it.modified,"",""].join("|")) > it.children.each {// farms > println([it.type, it.farm_id,it.name , it.created, it.modified,grower.profile_id,""].join("|")) > it.children.each {// fields > println([it.type, it.field_id,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 --------------060709030705060901030000 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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, grower.created, grower.modified, "", ""].join("|"))
        it.children.each { farm ->
          println([farm.type, farm.farm_id, farm.name, farm.created, farm.modified, grower.profile_id, ""].join("|"))
          it.children.each { field ->
            println([field.type, field.field_id, field.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, it.created, it.modified, "", ""].join("|"))
        it.children.each { // farms
          println([it.type, it.farm_id, it.name, it.created, it.modified, grower.profile_id, ""].join("|"))
          it.children.each { // fields
            println([it.type, it.field_id, 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

--------------060709030705060901030000--