Last active
May 17, 2017 18:17
-
-
Save copperwall/b19fadce28e3e230e49a3806f282722d to your computer and use it in GitHub Desktop.
Generator-backed range function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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