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

Dave Abrahams dabrahams at apple.com
Fri Mar 4 19:49:57 CST 2016


on Fri Mar 04 2016, Brent Royal-Gordon <swift-evolution at swift.org> wrote:

>> 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.

Me neither; I'm just trying to focus the analysis.

-- 
-Dave



More information about the swift-evolution mailing list