Skip to content

Instantly share code, notes, and snippets.

@drupol
Last active August 31, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drupol/8a1ff3c4d5ccbb56a1e45823677a9b38 to your computer and use it in GitHub Desktop.
Save drupol/8a1ff3c4d5ccbb56a1e45823677a9b38 to your computer and use it in GitHub Desktop.
<?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