I got the idea from https://internals.rust-lang.org/t/pre-rfc-generator-integration-with-for-loops/6625/11.
But that is a fair criticism. I'll have to think of some examples before I decide whether I agree. I do think there should be some nice way to iterate over generators with return arguments, though. And a for_each
combinator isn't enough, because we may want to yield
in the body of the loop.
But I honestly think that the stuff about for
-loops is the less-interesting part of my post. The more interesting part is the idea that there are different kinds of generators (stage 1 and stage 3), and that they are useful in different circumstances.