-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimes3.php
More file actions
29 lines (22 loc) · 638 Bytes
/
Primes3.php
File metadata and controls
29 lines (22 loc) · 638 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
declare(strict_types=1);
namespace drupol\primes;
use drupol\primes\Iterator\CustomCallbackFilterIterator;
use Generator;
use Iterator;
final class Primes3 extends AbstractPrimes
{
protected static function sieve(Iterator $iterator): ?Generator
{
yield $primeNumber = $iterator->current();
$iterator = new CustomCallbackFilterIterator(
$iterator,
static fn (int $a): bool => (0 !== ($a % $primeNumber)),
$primeNumber
);
$iterator->next();
return $iterator->valid() ?
yield from self::sieve($iterator) :
null;
}
}