title: Groovy's << operator is confusing
body: <p>I'm new to Groovy and I am very lost with respect to the <code>&lt;&lt;</code> operator. I understand its use as a bit shifter as follows:</p>
  
  <pre><code>def x = 2
  x &lt;&lt; 2 //x == 8
  </code></pre>
  
  <p>However, the operator has another use when being used in a closure in strings:</p>
  
  <pre><code>"${ w -&gt; w &lt;&lt; 3}" //w == 3
  </code></pre>
  
  <p>So my question is this: In what situations does <code>&lt;&lt;</code> act as an assignment operator? In what situations does it act as a bit shifter?</p>
  
  <p>This second example is really what got me confused:</p>
  
  <pre><code>def transform(List elements, Closure action) {                    
      def result = []
      elements.each {
          result &lt;&lt; action(it)
      }
      result
  }
  </code></pre>
  
  <p>Here it seems that <code>&lt;&lt;</code> performs an append. So is there a set of rules on <code>&lt;&lt;</code>? Does <code>&lt;&lt;</code> behave differently for every data structure? Is there a codified set of rules somewhere? I can't seem to find anything on this in the Groovy documentation; instead, it's casually thrown in, in different examples, which is confusing at best.</p>