-
-
Notifications
You must be signed in to change notification settings - Fork 0
GroupByIteratorIterator
Class GroupByIteratorIterator.
Groups elements from an iterator based on a callback function.
This iterator aggregates elements into associative arrays where the keys are
determined by a user-defined function ($groupBy). Each key contains an array
of elements that share the same computed group.
- Full name:
\FastForward\Iterator\GroupByIteratorIterator - Parent class:
\FastForward\Iterator\CountableIteratorIterator
Initializes the GroupByIteratorIterator.
public __construct(iterable $iterator, \Closure $groupBy): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$iterator |
iterable | the iterator containing values to be grouped |
$groupBy |
\Closure | a function that determines the group key for each element |
Rewinds the iterator and reprocesses the grouping.
public rewind(): voidThis ensures that the grouping is correctly recomputed when the iterator is reset.
Retrieves the current group of elements.
public current(): array<int,mixed>Return Value:
the current group of elements
Retrieves the key of the current group.
public key(): mixedReturn Value:
the computed key representing the current group
Advances to the next group in the iterator.
public next(): voidChecks if the current position is valid.
public valid(): boolReturn Value:
true if a valid group exists, false otherwise
Counts the number of elements in the iterable.
public count(): intIf the inner iterator implements Countable, it uses that. Otherwise, it counts the elements by iterating through them.
Return Value:
the number of elements in the iterable