Last active
August 31, 2020 14:28
-
-
Save drupol/8a1ff3c4d5ccbb56a1e45823677a9b38 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Run this code with: php -n to make sure no configuration will be used | |
* so xdebug will not be used either. | |
*/ | |
declare(strict_types=1); | |
function llist($n = 2) { | |
yield $n; | |
return yield from llist($n + 1); | |
} | |
$callback = fn(int $p) => fn(int $a, int $b, Iterator $it): bool => $a % $p !== 0; | |
$i = 0; | |
$iterator = llist(); | |
while (true) { | |
$prime = $iterator->current(); | |
var_dump($prime); | |
if ($i++ > 100) { | |
break; | |
} | |
$iterator = new CallbackFilterIterator( | |
$iterator, | |
$callback($prime) | |
); | |
$iterator->next(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment