src/Map.php
public function partition($expression)
    {
        $outer = new MapOfCollections;
        $proto = new static;

        $this->walk(function ($v, $k) use ($expression, $outer, $proto) {
            $partition = $this->call($expression, $v, $k);

            $inner = $outer->has($partition) ? $outer->get($partition) : clone $proto;
            $inner->set($k, $v);

            $outer->set($partition, $inner);
        });

        return $outer;
    }
public function partition($expression)
    {
        $outer = new MapOfCollections;
        $proto = new static;

        $this->walk(function ($v, $k) use ($expression, $outer, $proto) {
            $partition = $this->call($expression, $v, $k);

            $inner = $outer->has($partition) ? $outer->get($partition) : clone $proto;
            $inner->set($k, $v);

            $outer->set($partition, $inner);
        });

        return $outer;
    }
public function partition ( $ expression ) { $ outer = new MapOfCollections ; $ proto = new static ; $ this -> walk ( function ( $ v , $ k ) use ( $ expression , $ outer , $ proto ) { $ partition = $ this -> call ( $ expression , $ v , $ k ) ; $ inner = $ outer -> has ( $ partition ) ? $ outer -> get ( $ partition ) : clone $ proto ; $ inner -> set ( $ k , $ v ) ; $ outer -> set ( $ partition , $ inner ) ; } ) ; return $ outer ; }
Groups elements of this map based on the result of an expression.

Calls the expression for each element in this map. The expression
receives the value and key, respectively.  The expression may return
any value: this value is the grouping key and the element is put into
that group.

```
$nums = new Map(range(0, 9));
$part = $nums->partition(function ($value, $key) {
return 0 == $value % 2 ? 'even' : 'odd';
});
var_dump(
$part['odd']->count(), // 5
array_sum($part['even']->toArray()) // 20
);
```

@param callable|string $expression
@return MapOfCollections
@api
Groups elements of this map based on the result of an expression .