3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $iter = function($a) : \Generator { yield $a + 1; }; $reset = function ($a) : bool { return $a == 7; }; $init = function () : int { return 3; }; function rotatable(callable $iterate, callable $reset, callable $init) : \Generator { $i = $init(); $gen = $iterate($i); while (TRUE) { yield $i; $i = $gen->current(); $reset($i) and $i = $init(); $gen = $iterate($i); } } function rotate(\Generator $generator) { $current = $generator->current(); $generator->next(); return $current; } $gen = rotatable($iter, $reset, $init); for ($i = 0; $i < 15; $i++) { var_dump(rotate($gen)); }
based on dcsQL
Output for 7.1.25 - 7.3.2
int(3) int(4) int(5) int(6) int(3) int(4) int(5) int(6) int(3) int(4) int(5) int(6) int(3) int(4) int(5)