[swift-evolution] [Proposal] Change guarantee for GeneratorType.next() to always return nil past end

Brent Royal-Gordon brent at architechies.com
Fri Mar 4 18:57:49 CST 2016

> What algorithms or components can be simplified by taking advantage of
> this extra guarantee?  If the category of code that can use it is
> broader than the category of generators that would suffer an overhead or
> implementation complexity, it might be worth doing.
> My intuition is that both categories are small.  

I do agree that both categories are probably small. But they have very different consequences:

* If you make the guarantee, certain rare types of generators will need a little more storage and an extra branch.
* If you don't make the guarantee, code which works most of the time will fail when combined with certain generators.

It seems like we're facing a tradeoff between a tiny efficiency gain in rare cases and predictable semantics in all cases. I'm not convinced efficiency is the right choice here.

Brent Royal-Gordon

More information about the swift-evolution mailing list