Tools for creating infinite iterators.
Count sequentially forever.
Infinite::count(int $start = 1, int $step = 1)
use IterTools\Infinite;
$start = 1;
$step = 1;
foreach (Infinite::count($start, $step) as $i) {
print($i);
}
// 1, 2, 3, 4, 5 ...Cycle through the elements of a collection sequentially forever.
Infinite::cycle(iterable $iterable)
use IterTools\Infinite;
$hands = ['rock', 'paper', 'scissors'];
foreach (Infinite::cycle($hands) as $hand) {
RockPaperScissors::playHand($hand);
}
// rock, paper, scissors, rock, paper, scissors, ...Repeat an item forever.
Infinite::repeat(mixed $item)
use IterTools\Infinite;
$dialogue = 'Are we there yet?';
foreach (Infinite::repeat($dialogue) as $repeated) {
print($repeated);
}
// 'Are we there yet?', 'Are we there yet?', 'Are we there yet?', ...