| @@ 426-436 (lines=11) @@ | ||
| 423 | * @param boolean $sort |
|
| 424 | * @return GroupbyIterator |
|
| 425 | */ |
|
| 426 | function group_by($strategy, $iterable, $sort = true) |
|
| 427 | { |
|
| 428 | if (!is_bool($sort)) { |
|
| 429 | throw new \InvalidArgumentException('Argument $sort must be a boolean'); |
|
| 430 | } |
|
| 431 | ||
| 432 | return new GroupbyIterator( |
|
| 433 | conversions\mixed_to_value_getter($strategy), |
|
| 434 | $sort ? sorted($strategy, $iterable) : conversions\mixed_to_iterator($iterable) |
|
| 435 | ); |
|
| 436 | } |
|
| 437 | ||
| 438 | /** |
|
| 439 | * Make an iterator that returns consecutive groups from the |
|
| @@ 481-491 (lines=11) @@ | ||
| 478 | * @param boolean $reverse |
|
| 479 | * @return SortedIterator |
|
| 480 | */ |
|
| 481 | function sorted($strategy, $iterable, $reverse = false) |
|
| 482 | { |
|
| 483 | if (!is_bool($reverse)) { |
|
| 484 | throw new \InvalidArgumentException('Argument $reverse must be boolean'); |
|
| 485 | } |
|
| 486 | return new SortedIterator( |
|
| 487 | conversions\mixed_to_value_getter($strategy), |
|
| 488 | conversions\mixed_to_iterator($iterable), |
|
| 489 | $reverse |
|
| 490 | ); |
|
| 491 | } |
|
| 492 | ||
| 493 | /** |
|
| 494 | * Make an iterator that returns values from $iterable where the |
|