public function getBy(\Closure $callback)
    {
        $instanceCopy = $this->getNewCollection();
        foreach ($this as $offset => $entity) {
            if ($callback($entity)) {
                $instanceCopy->append($entity);
            }
        }

        return $instanceCopy;
    }
public function getBy(\Closure $callback)
    {
        $instanceCopy = $this->getNewCollection();
        foreach ($this as $offset => $entity) {
            if ($callback($entity)) {
                $instanceCopy->append($entity);
            }
        }

        return $instanceCopy;
    }
public function getBy ( \ Closure $ callback ) { $ instanceCopy = $ this -> getNewCollection ( ) ; foreach ( $ this as $ offset => $ entity ) { if ( $ callback ( $ entity ) ) { $ instanceCopy -> append ( $ entity ) ; } } return $ instanceCopy ; }
Get collection of entities matching criteria given in callback

Usage example:

$colleciton->getBy(function($entity) {
return $entity->name == 'John';
});

@param Closure $callback
@return static
Get collection of entities matching criteria given in callback