Skip to content

TrimIteratorIterator

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

An iterator that trims each value within a iterable.

This class extends ClosureIteratorIterator and applies trim() to each element, removing leading and trailing characters based on the specified character mask.

Usage Example:


Methods

__construct

Initializes the TrimIteratorIterator.

public __construct(iterable $iterator, string|null $characters = \self::DEFAULT_CHARACTERS): mixed

Parameters:

Parameter Type Description
$iterator iterable the iterator containing values to be trimmed
$characters string|null A string defining the characters to be trimmed.
Defaults to standard whitespace characters.

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


__construct

Initializes the ClosureIteratorIterator.

public __construct(iterable $iterator, \Closure $closure): mixed

Parameters:

Parameter Type Description
$iterator iterable the underlying iterator to wrap
$closure \Closure the transformation function applied to each element

current

Returns the current transformed element.

public current(): mixed

The closure is applied to the original current element of the iterator.

Return Value:

the transformed element


Clone this wiki locally