code: public static Collection grep(Object self, Object filter) {
          Collection answer = createSimilarOrDefaultCollection(self);
          BooleanReturningMethodInvoker bmi = new BooleanReturningMethodInvoker("isCase");
          for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) {
              Object object = iter.next();
              if (bmi.invoke(filter, object)) {
                  answer.add(object);
              }
          }
          return answer;
      }
docs: Iterates over the collection of items which this Object represents and returns each item that matches
  the given filter - calling the <code>{@link #isCase(java.lang.Object, java.lang.Object)}</code>
  method used by switch statements.  This method can be used with different
  kinds of filters like regular expressions, classes, ranges etc.
  Example:
  <pre class="groovyTestCase">
  def list = ['a', 'b', 'aa', 'bc', 3, 4.5]
  assert list.grep( ~/a+/ )  == ['a', 'aa']
  assert list.grep( ~/../ )  == ['aa', 'bc']
  assert list.grep( Number ) == [ 3, 4.5 ]
  assert list.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
  </pre>
  
  @param self   the object over which we iterate
  @param filter the filter to perform on the object (using the {@link #isCase(java.lang.Object, java.lang.Object)} method)
  @return a collection of objects which match the filter
  @since 1.5.6