コード例 #1
0
ファイル: ImmutableMapTest.php プロジェクト: hoesler/traver
 /**
  * @return \Traver\Collection\Builder
  */
 protected function createBuilder()
 {
     return ImmutableMap::newBuilder();
 }
コード例 #2
0
ファイル: PipeableLike.php プロジェクト: hoesler/traver
 /**
  * @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();
 }