public function getFilteredCopy(\Closure $filter)
    {
        $copy = clone $this;
        $filteredData = [];
        foreach ($this->data as $key => $item) {
            if ($filter($item)) {
                $filteredData[$key] = $item;
            }
        }

        $copy->data = $filteredData;
        return $copy;
    }
public function getFilteredCopy(\Closure $filter)
    {
        $copy = clone $this;
        $filteredData = [];
        foreach ($this->data as $key => $item) {
            if ($filter($item)) {
                $filteredData[$key] = $item;
            }
        }

        $copy->data = $filteredData;
        return $copy;
    }
public function getFilteredCopy ( \ Closure $ filter ) { $ copy = clone $ this ; $ filteredData = [ ] ; foreach ( $ this -> data as $ key => $ item ) { if ( $ filter ( $ item ) ) { $ filteredData [ $ key ] = $ item ; } } $ copy -> data = $ filteredData ; return $ copy ; }
This method can be used to pass a closure to created a filtered copy.
The closure get an collection item passed and needs to return true when the item should
be kept or false when it can be skipped.

@param callable $filter
@return AbstractCollection
This method can be used to pass a closure to created a filtered copy . The closure get an collection item passed and needs to return true when the item should be kept or false when it can be skipped .