by masklinn · 3y ago · 0 comments
But one does not always end up creating a large list of prime numbers, do they?
> why not just return a large list of prime numbers?
Because that requires upfront knowledge of the filtering factor or absence thereof.
A generator means you don't care, you generate an infinite sequence and the consumer is free to do whatever they want.
> It is obvious that returning an array of prime numbers is what one would do in C/C++/Rust.
It's certainly not obvious for Rust.
Everything I replied to is the opinion you personally expressed.
And note that the author had already preempted your comment in the first place:
> When we want a list of all the primes below some known limit, gen_primes_upto is great, and performs fairly well. There are two issues with it, though:
> We have to know what the limit is ahead of time; this isn't always possible or convenient.