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

Kevin Ballard kevin at sb.org
Tue Mar 8 19:07:12 CST 2016


On Tue, Mar 8, 2016, at 05:03 PM, Dmitri Gribenko wrote:
> On Tue, Mar 8, 2016 at 4:50 PM, Kevin Ballard <kevin at sb.org> wrote:
> > In fact, it's the only requirement not enforced by the type system that a GeneratorType implementation must conform to.
> 
> That's not true.  Once you start putting generators into a larger
> context, you have:
> 
> - collection's generator should generate the same elements as
> subscripting would produce;
> 
> - a generator for a sequence should produce at least
> `underestimatedCount` elements;
> 
> - a generator for a sequence should produce the same elements as the
> `forEach` method;
> 
> - lots and lots of similar high-level relationships.

Those are requirements for collections/sequences, I was talking strictly about GeneratorType implementations. If you want to talk about sequences/collections, then we've already bypassed the whole post-nil discussion because anyone working with sequences/collections instead of generators has already lost the ability to invoke next() after it has returned nil.

-Kevin Ballard


More information about the swift-evolution mailing list