title: How to write a conditional collect in groovy?
body: <p>Imagine I have this structure:</p>
  
  <pre><code>class Foo {
     String bar
  }
  </code></pre>
  
  <p>Now imagine I have several instance of <code>Foo</code> whose <code>bar</code> value is <code>baz_1</code>, <code>baz_2</code>, and <code>zab_3</code>.</p>
  
  <p>I want to write a collect statement that only collects the <code>bar</code> values which contain the text <code>baz</code>. I cannot get it to work, but it would look something like this:</p>
  
  <pre><code>def barsOfAllFoos = Foo.getAll().bar
  assert barsOfAllFoos == [ 'baz_1', 'baz_2', 'zab_3' ]
  def barsWithBaz = barsOfAllFoos.collect{ if( it.contains( "baz" ) { it } ) } // What is the correct syntax for this?
  assert barsWithBaz == [ 'baz_1', 'baz_2' ]
  </code></pre>