feat: add lazy prime iterator API (primes_from, primes_upto)#178
feat: add lazy prime iterator API (primes_from, primes_upto)#178s-celles wants to merge 1 commit intoJuliaMath:mainfrom
Conversation
Add PrimeIterator{T, Up} unified parametric type with primes_from(n) for
ascending and primes_upto(n) for descending lazy iteration over primes.
Fully composable with Base.Iterators (take, takewhile, zip, etc.).
Closes JuliaMath#176.
c8b285c to
7580f64
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #178 +/- ##
==========================================
+ Coverage 93.08% 94.40% +1.32%
==========================================
Files 2 2
Lines 463 483 +20
==========================================
+ Hits 431 456 +25
+ Misses 32 27 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
IMO API isn't quite what we want. By committing to an iterator API without an upfront size, we are unable to know whether the user will iterate it enough for a sieve to be worth it. I think the better API here is |
|
That's a fair point, and I'd argue the two APIs are complementary rather than exclusive though. # find the first prime ≥ n satisfying an arbitrary predicate
first(p for p in primes_from(n) if p % 4 == 1)
# twin prime candidates — no upper bound
zip(primes_from(2), Iterators.drop(primes_from(2), 1))For these, |
|
That's fair. I feel like those use-cases likely should be written in terms of |
Add
PrimeIterator{T, Up}unified parametric type with:primes_from(n)for ascending andprimes_upto(n)for descendinglazy iteration over primes.
Fully composable with
Base.Iterators(take,takewhile,zip, etc.).Closes #176