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.
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.
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.
You can install the package via composer:
composer require doekenorg/iterator-functionsPlease see CHANGELOG for more information what has changed recently.
./vendor/bin/pestThe MIT License (MIT). Please see License File for more information.