One of motivations to for this proposal was to remove the need for else/then blocks. I can’t see how you example is better than:
let y: Foo = for x in wow {
...
};
let foo: u32 = {
// compute `foo` based on `y`
};
Well, except one thing, it creates explicit scope for y which could make handling lifetime containing results better, but with NLL, I think, its importance significantly diminishes.
You probably meant the same as an Arg argument? I.e. Generator signature will look like this:
pub trait Generator {
type Yield;
type Return;
type Arg;
fn resume(&mut self, arg: Self::Arg) -> GeneratorState<Self::Yield, Self::Return>;
}
One problem with you example is that we can’t decide what value to use as an argument on the first iteration. We could leave resume argumentless and add method resume_with_arg, or use Option<Self::Arg>, but it will make generators significantly more complex. And overall I think requiring to use continue in every path of the for-loop body will make for loops harder to write, modify and read.
Also it will make desugaring of for loops significantly more complex, as continue with the value currently does not work anywhere, in contrast with break expressions.
Could you please provide examples where argument based iterators and continue with value could be useful?