original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: 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
docstring_tokens: Groups elements of this map based on the result of an expression .