[swift-evolution] Proposal: Allow for/in to take GeneratorType in addition to SequenceType

Dave Abrahams dabrahams at apple.com
Sun Dec 13 23:45:14 CST 2015


> On Dec 13, 2015, at 4:24 PM, Dmitri Gribenko via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On Sun, Dec 13, 2015 at 3:43 PM, Michael Henson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Currently, the construct:
> 
> for x in something {}
> 
> expects "something" to be a SequenceType. From that variable, the underlying code retrieves a generator by calling something.generate(). The resulting GeneratorType instance is unavailable to calling code.
> 
> Unless there is a reason for the language to require a SequenceType, it seems like there are good use cases for accepting a caller-provided GeneratorType, too.
> 
> I support this.  We would need to define what happens when the expression is both a generator and a sequence, but otherwise I don't see why not.

When the language is able to handle recursive protocol requirements, this will become redundant, because GeneratorType will refine SequenceType (with generate returning self).  So, IMO, this isn't a problem worth solving separately.

-Dave



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151213/19e320e1/attachment.html>


More information about the swift-evolution mailing list