<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Personally, I am agains generators (its quite specific syntactic sugar that adds a lot of complexity), but I would be all for a comprehensive coroutine library*. One can model it after Lua’s coroutines (<a href="http://www.lua.org/pil/9.1.html" class="">http://www.lua.org/pil/9.1.html</a>), which works well with the existing syntax. Your example becomes something like:</div><div class=""><br class=""></div><div class="">helloGenerator = Coroutine.create<()->String>({name:String -> () in </div><div class=""> Coroutine.yield(“Hello”)</div><div class=""> Coroutine.yield(name ?? “World”)</div><div class="">})</div><div class=""><br class=""></div><div class="">this generates a class instance with a resume ()->String? method that can be used to retrieve the values. You can also pass values via resume (they will be then available as results of coroutine.yield)</div><div class=""><br class=""></div><div class="">One can than use helloGenerator.resume() to get the values (which can be easily wrapped in a sequence etc).</div><div class=""><br class=""></div><div class="">Benefits of this approach: no need for significant syntactic change (although a coroutine keyword could be introduced instead of func to wrap the above declaration), the coroutine functions are offloaded to a type rather than syntactic construct, type safety is quite easy to preserve. Still, its far from being a trivial thing to implement as it would require support of continuations on the compiler level. </div><div class=""><br class=""></div><div class="">Cheers, </div><div class=""><br class=""></div><div class=""> Taras</div><div class=""><br class=""></div><div class="">*Yes, current generators in Python are essentially coroutines but I think it important to keep the terminology clean. Generators are intended first and foremost as lazy sequence, well, generators. Coroutines are a much more versatile construct. </div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div>On Fri, Dec 11, 2015 at 18:21 PM, David Waite via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">Looking for feedback on crafting a proposal adding generator functions to Swift. I understand this will likely be a very involved proposal at the language level, although I actually don’t know the complexity of the change within the Swift compiler itself.
</pre></div><div class=""><br class=""></div></div></blockquote></body></html>