[swift-evolution] Proposal: Allow for/in to take GeneratorType in addition to SequenceType
Dmitri Gribenko
gribozavr at gmail.com
Sun Dec 13 18:24:23 CST 2015
On Sun, Dec 13, 2015 at 3:43 PM, Michael Henson via swift-evolution <
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.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151213/ba46b8fe/attachment.html>
More information about the swift-evolution
mailing list