dutekvejin / iterators
Installs: 8 638
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.1|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- phpunit/phpunit: ^7.3|^8.0
This package is not auto-updated.
Last update: 2024-12-20 15:16:25 UTC
README
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
:
composer require dutekvejin/iterators
Usage
Dutek\Iterator\ChunkIterator
Chunks an \Iterator
into arrays with size
elements.
use Dutek\Iterator\ChunkIterator; $iterator = new \ArrayIterator([1, 2, 3, 4, 5]); $size = 2; $chunkIterator = new ChunkIterator($iterator, $size); assert(iterator_to_array($chunkIterator) === [[1, 2], [3, 4], [5]]);
Dutek\Iterator\MapIterator
Applies the callback to the elements of the given \Iterator
.
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.