-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 exposed by the inner iterator.
public count(): intIf the inner iterator implements
-
See: \Countable, this method SHALL return the value provided by that implementation. Otherwise, it MUST count elements by iterating over the iterator. If the inner iterator is not cloneable, this method SHALL wrap the current object in an
-
See: \IteratorIterator instance and count through that wrapper to avoid performing an invalid clone operation. If the inner iterator is cloneable, this method SHOULD count over a clone so that the original iterator state is preserved as much as possible.
Return Value:
the total number of elements available from the inner iterator