Skip to content

Instantly share code, notes, and snippets.

@edorian
Created June 28, 2018 18:08
Show Gist options
  • Save edorian/ca3ff9b5fa3255723314e52c4036ac27 to your computer and use it in GitHub Desktop.
Save edorian/ca3ff9b5fa3255723314e52c4036ac27 to your computer and use it in GitHub Desktop.
step() feels very inelegant
<?php
$fizz = function() {
while(true) {
yield '';
yield '';
yield 'Fizz';
}
};
$buzz = function() {
while(true) {
yield '';
yield '';
yield '';
yield '';
yield 'Buzz';
}
};
function step(\Generator $gen) {
$value = $gen->current();
$gen->next();
return $value;
}
$fizzGen = $fizz();
$buzzGen = $buzz();
foreach(range(1,100) as $i) {
echo step($fizzGen) . step($buzzGen) ?: $i, PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment