/** * @return \Traver\Collection\Builder */ protected function createBuilder() { return ImmutableMap::newBuilder(); }
/** * @param callable $keyFunction * @return PipeableLike * @see Pipeable::groupBy */ public function groupBy(callable $keyFunction) { $keyFunction = self::wrapCallback($keyFunction); $result = []; foreach ($this->asTraversable() as $key => $value) { $groupKey = $keyFunction($value, $key); if (!isset($result[$groupKey])) { $result[$groupKey] = []; } $result[$groupKey][$key] = $value; } $builder = ImmutableMap::newBuilder(); foreach ($result as $key => $group) { $groupPipeable = $this->newCollection($group); $builder->add($groupPipeable, $key); } return $builder->build(); }