title: EachWithIndex groovy statement
body: <p>I am new to groovy and I've been facing some issues understanding the <code>each{}</code> and <code>eachwithindex{}</code> statements in groovy.</p>
  
  <p>Are <code>each</code> and <code>eachWithIndex</code> actually methods? If so what are the arguments that they take?</p>
  
  <p>In the groovy documentation there is this certain example:</p>
  
  <pre><code>def numbers = [ 5, 7, 9, 12 ]
  numbers.eachWithIndex{ num, idx -&gt; println "$idx: $num" } //prints each index and number
  </code></pre>
  
  <p>Well, I see that <code>numbers</code> is an array. What are <code>num</code> and <code>idx</code> in the above statement? What does the <code>-&gt;</code> operator do? </p>
  
  <p>I do know that <code>$idx</code> and <code>$num</code> prints the value, but how is it that <code>idx</code> and <code>num</code> are automatically being associated with the index and contents of the array? What is the logic behind this? Please help.</p>