for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* File was created 09.06.2015 06:50
*
* @author Karsten J. Gerber <[email protected]>
*/
namespace PeekAndPoke\Component\Psi\Operation\FullSet;
use PeekAndPoke\Component\Psi\FullSetOperation;
class ChunkOperation implements FullSetOperation
{
/** @var int */
private $chunkSize;
* @param int $chunkSize
public function __construct($chunkSize)
$this->chunkSize = max(1, (int) $chunkSize);
}
* {@inheritdoc}
public function apply(\Iterator $set)
$group = 0;
$counter = $this->chunkSize;
$ret = [];
foreach ($set as $item) {
$ret[$group][] = $item;
if (--$counter === 0) {
++$group;
return new \ArrayIterator($ret);