src/Bag.php
public function partition(callable $predicate)
    {
        $coll1 = $coll2 = [];

        foreach ($this->items as $key => $item) {
            if ($predicate($key, $item)) {
                $coll1[$key] = $item;
            } else {
                $coll2[$key] = $item;
            }
        }

        return [$this->createFrom($coll1), $this->createFrom($coll2)];
    }
public function partition(callable $predicate)
    {
        $coll1 = $coll2 = [];

        foreach ($this->items as $key => $item) {
            if ($predicate($key, $item)) {
                $coll1[$key] = $item;
            } else {
                $coll2[$key] = $item;
            }
        }

        return [$this->createFrom($coll1), $this->createFrom($coll2)];
    }
Partitions the items into two bags according to the `$predicate`.
Keys are preserved in the resulting bags.

Example:

[$trueItems, $falseItems] = $bag->partition(function ($key, $item) {
return true; // whatever logic
});

@param callable $predicate Function is passed `($key, $value)` and should return a `boolean`

@return static[] [true bag, false bag]