Pinq\ITraversable::groupBy PHP Метод

groupBy() публичный Метод

This will implicitly index each group by the group key returned from the supplied function.
public groupBy ( callable $function ) : pinq\ITraversable
$function callable The grouping function
Результат pinq\ITraversable
    public function groupBy(callable $function);

Usage Example

Пример #1
0
 /**
  * @dataProvider assocOneToTen
  */
 public function testThatGroupByGroupsTheElementsCorrectlyAndPreservesKeys(\Pinq\ITraversable $traversable, array $data)
 {
     $isEven = function ($i) {
         return $i % 2 === 0;
     };
     //First number is odd, so the first group should be the odd group
     list($odd, $even) = $traversable->groupBy($isEven)->asArray();
     $this->assertMatches($odd, array_filter($data, function ($i) use($isEven) {
         return !$isEven($i);
     }));
     $this->assertMatches($even, array_filter($data, $isEven));
 }
All Usage Examples Of Pinq\ITraversable::groupBy