title: Can additional parameters be added to a Groovy closure invocation?
body: <p>I am trying to understand groovy better and came across this usage.</p>
  
  <p>Found this while using Http-Builder, though my question is independent of that - I am mainly interested in finding the "groovy-way" for the general use-case implied.</p>
  
  <p>There is an existing "request" method that takes a closure and when the http-builder invokes that closure it passes it one parameter, the "request".   What is the best way to get additional information passed in to such a closure?</p>
  
  <p>Following normal usage, the code might look something like:</p>
  
  <pre><code>myHttpClient.request(POST) { req -&gt;
     uri.path = 'some path'
     uri.query = [ p1:'value1', p2:'value2' ]
  ....
  }
  </code></pre>
  
  <p>In this example, I would like to be able to dynamically set (or pass in) three values - the path, and the values for the query parameters 1 &amp; 2.</p>
  
  <p>I don't know enough to know the right way, but have done something like this:</p>
  
  <p><strong>EDIT</strong> cleaned up the code</p>
  
  <pre><code>def myPath = '/a/b/c'
  def p1Param = 'p1Value'
  def p2Param = 'p2Value'
  def myClosure = { req -&gt; 
     uri.path = myPath
     uri.query = [ p1:p1Param, p2:p2Param ]
  ....
  }
  
  // first call:
  myHttpClient.request(POST, myClosure)
  // later on: 
  myPath = '/new/path'
  p1Param = 'newValue1'
  p2Param = 'newValue2'
  myHttpClient.request(POST, myClosure)
  </code></pre>
  
  <p>While this works and is DRY, it is also ugly and I think/hope there is a better way.  I also thought about putting the entire call into its own closure and simply calling that - again I was hoping there is a better way!</p>