doekenorg / iterator-functions
A package that provides array_* like functions for iterators.
Installs: 4 573
Dependents: 0
Suggesters: 0
Security: 0
Stars: 67
Watchers: 5
Forks: 1
Open Issues: 3
pkg:composer/doekenorg/iterator-functions
Requires
- php: ^7.4|^8.0
Requires (Dev)
- pestphp/pest: ^1.15
- vimeo/psalm: ^4.9
This package is auto-updated.
Last update: 2025-10-24 21:39:19 UTC
README
The doekenorg/iterator-functions package provides a curated set of array_* like functions for iterators in PHP. This
package is built to encourage developers to make more use of Iterators by simplifying common tasks.
Available functions
All available functions are modeled after their array_* equivalent. But instead of returning an array it will return
an Iterator instance. This means that you can use them in the same way, but get the added memory preserving benefits.
iterator_column(\Traversable $iterator, $column_key, $index_key = null): ColumnIteratoriterator_filter(Iterator $iterator, ?callable $callback = null): \CallbackFilterIteratoriterator_flip(Iterator $iterator): FlipIteratoriterator_keys(\Iterator $iterator): KeysIteratoriterator_map(callable $callback, iterable ...$iterators): MapIteratoriterator_reduce(\Iterator $iterator, callable $callback, $initial = null)iterator_values(\Iterator $iterator): ValuesIteratoriterator_walk(\Iterator $iterator, callable $callback, ...$arguments): void
Note: There are no _diff or _intersect functions available, because these are not possible without forgoing on the
memory benefits of iterators.
Available iterators
Where possible the functions make use of native iterators. Any missing iterators were added to this package.
ColumnIterator- Iterator that returns a single column for the iteration array / object.FlipIterator- Iterator that flips the key and the value of the current iteration.KeysIterator- Iterator that returns only the keys of the provided iterator.MapIterator- Iterator that applies a callback to the elements of the given iterators.ValuesIterator- Iterator that returns only the values of the provided iterator.
Install
You can install the package via composer:
composer require doekenorg/iterator-functions
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
./vendor/bin/pest
License
The MIT License (MIT). Please see License File for more information.