public function filter(callable $callback): self
    {
        $collection = Factory::create();
        $index      = 0;
        foreach ($this->items as $key => $value) {
            if ($callback($value, $key, $index++)) {
                $collection->set($key, $value);
            }
        }

        return $collection;
    }
public function filter(callable $callback): self
    {
        $collection = Factory::create();
        $index      = 0;
        foreach ($this->items as $key => $value) {
            if ($callback($value, $key, $index++)) {
                $collection->set($key, $value);
            }
        }

        return $collection;
    }
public function filter ( callable $ callback ) : self { $ collection = Factory :: create ( ) ; $ index = 0 ; foreach ( $ this -> items as $ key => $ value ) { if ( $ callback ( $ value , $ key , $ index ++ ) ) { $ collection -> set ( $ key , $ value ) ; } } return $ collection ; }
Filter and return a new Collection.

@performanceCompared true
Filter and return a new Collection .