Skip to content

UniqueIteratorIterator

github-actions edited this page Mar 31, 2026 · 3 revisions

Filters duplicate values from an iterator, ensuring uniqueness.

This iterator allows traversing an iterable while maintaining a record of seen values, returning only the first occurrence of each unique value. Subsequent occurrences are skipped.

Usage Example:


Methods

__construct

Initializes the UniqueIteratorIterator.

public __construct(iterable $iterator, bool $strict = true, bool $caseSensitive = true): mixed

Parameters:

Parameter Type Description
$iterator iterable the iterator to filter for unique values
$strict bool whether to use strict comparison (default: true)
$caseSensitive bool whether to use case-sensitive comparison (default: true)

key

Retrieves the normalized sequential key for the current unique element.

public key(): int

Return Value:

the zero-based position of the current unique value


next

Advances to the next unique element.

public next(): void

rewind

Resets the iterator and clears the seen values.

public rewind(): void

Inherited methods

count

Counts the number of elements exposed by the inner iterator.

public count(): int

If 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


Clone this wiki locally