gielfeldt/iterators

View on GitHub
src/StepIterator.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Gielfeldt\Iterators;

class StepIterator extends TraversableIterator
{
    private $step;

    public function __construct(\Traversable $iterator, int $step)
    {
        $this->step = $step;
        parent::__construct($iterator);
    }

    public function next()
    {
        $step = $this->step;
        while ($step-- > 0 && parent::valid()) {
            parent::next();
        }
    }
}