iterators
![Build Status][ico-build]
, (*1)
Installation
The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:, (*2)
composer require dutekvejin/iterators
Usage
Dutek\Iterator\ChunkIterator
Chunks an \Iterator into arrays with size elements., (*3)
``` php
use Dutek\Iterator\ChunkIterator;, (*4)
$iterator = new \ArrayIterator([1, 2, 3, 4, 5]);
$size = 2;
$chunkIterator = new ChunkIterator($iterator, $size);, (*5)
assert(iterator_to_array($chunkIterator) === [[1, 2], [3, 4], [5]]);, (*6)
#### `Dutek\Iterator\MapIterator`
Applies the callback to the elements of the given `\Iterator`.
``` php
use Dutek\Iterator\MapIterator;
$iterator = new \ArrayIterator([1, 2, 3, 4, 5]);
$callback = function (int $item) {
return $item ** 2;
};
$mapIterator = new MapIterator($iterator, $callback);
assert(iterator_to_array($mapIterator) === [1, 4, 9, 16, 25]);
Credits
License
Released under MIT License - see the License File for details., (*7)