[swift-evolution] Proposal: Add generator functions to the language
Jordan Rose
jordan_rose at apple.com
Fri Dec 11 20:23:51 CST 2015
> On Dec 11, 2015, at 18:20 , Andrey Tarantsov <andrey at tarantsov.com> wrote:
>
>> Another possible syntax, inspired by "throws".
>>
>> func foo() yield -> String
>
> Well, again, yielding is an implementation detail. What's the advantage vs returning Generator<String>? I don't think that lying about the return type is useful for anyone.
Well, just returning "Generator<String>" doesn't distinguish this from a normal function that just returns a generator. Also, "Generator" is a protocol with an associated type, so you can't use it as a value type (yet?). Today you'd have to manually type-erase using the AnyGenerator wrapper. That also makes it harder to optimize, since clients won't know what kind of generator you're using. (Maybe that's a feature, though; it lets you change the implementation in the future. I guess it could make sense to have the interface show the "real" generator return type even if the source shows the element type.)
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151211/aeff7d3c/attachment.html>
More information about the swift-evolution
mailing list