Skip to content

Instantly share code, notes, and snippets.

@copperwall
Last active May 17, 2017 18:17
Show Gist options
  • Save copperwall/b19fadce28e3e230e49a3806f282722d to your computer and use it in GitHub Desktop.
Save copperwall/b19fadce28e3e230e49a3806f282722d to your computer and use it in GitHub Desktop.
Generator-backed range function
<?php
function range(int $start, int $end, int step = 1): Iterator {
while ($start < $end) {
yield $start;
$start += $step;
}
}
function infinite() {
$i = 1;
while (true) {
yield $i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment