<div dir="ltr"><div>I&#39;m still not sold on the generate keyword; this syntax (once it works) seems clear enough for me:</div><div><br></div><div>func fibonacci() -&gt; SequenceType&lt;Int&gt; {</div><div>   var (i, j) = (0, 1)</div><div>   repeat {</div><div>      (i, j) = (j, i + j)</div><div>      yield i</div><div>   }</div><div>}</div><div class="gmail_extra"><br></div><div class="gmail_extra">The intent is hard to miss: this function returns something that satisfies a specialization of SequenceType to type Int. The function can do this either </div><div class="gmail_extra"><br></div><div class="gmail_extra">(1) by returning a valid SequenceType struct/class object, </div><div class="gmail_extra">(2) by doing a simple return, in which case compiler impements an empty sequence behind the scenes, or</div><div class="gmail_extra">(3) by inserting a few yield operators before doing (1) or (2), in which case the compiler creates an appropriate generator struct</div><div class="gmail_extra"><br></div><div class="gmail_extra">Whether the function goes the route (1), (2) or (3) is an implementation detail of no import to its users.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 12, 2015 at 8:46 AM, David Waite via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><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"><div>It is tough to give examples which are suitably approachable, illustrative, and complex. Perhaps the Fibonacci sequence:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>generator func fibonacci() -&gt; Int {</div><div>   var = 0, j = 1</div><div>   repeat {</div><div>      (i, j) = (j, i + j)</div><div>      yield i</div><div>   }</div><div>}</div></blockquote><div><br></div><div>In addition to being a more complex problem, the sequence is also infinite. Luckily the functional influences on sequences let you deal with that without issue:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>// print the first 25 numbers in the fibonacci sequence</div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>fibonacci().prefix(25).forEach { print($0) }</div></blockquote><div><br></div>-DW<span class=""><div><br><div><blockquote type="cite"><div>On Dec 11, 2015, at 6:38 PM, Kametrixom Tikara &lt;<a href="mailto:kametrixom@icloud.com" target="_blank">kametrixom@icloud.com</a>&gt; wrote:</div><br><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">What exactly is the difference to just returning a sequence?</span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1"><span style="color:rgb(53,86,138)">func</span><span> </span>helloGenerator(name :<span> </span><span style="color:rgb(195,89,0)">String</span>?) -&gt; [<span style="color:rgb(195,89,0)">String</span>] {</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">   <span> </span><span style="color:rgb(53,86,138)">return</span><span> </span>[</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">       <span> </span><span style="color:rgb(232,35,0)">&quot;Hello&quot;</span>,</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">        name ??<span> </span><span style="color:rgb(232,35,0)">&quot;World&quot;</span></font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">    ]</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">}</font></div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:16px"><font size="1"><br></font></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(88,126,168)"><font size="1"><span style="color:rgb(53,86,138)">for</span><span><span> </span>str<span> </span></span><span style="color:rgb(53,86,138)">in</span><span><span> </span></span>helloGenerator<span>(</span><span style="color:rgb(232,35,0)">&quot;David&quot;</span><span>) {</span></font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">   <span> </span><span style="color:rgb(88,126,168)">print</span>(str)</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">}</font></div><div><br></div><div>And if you want if lazy:</div><div><br></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1"><span style="color:rgb(53,86,138)">func</span><span> </span>helloGenerator(name :<span> </span><span style="color:rgb(195,89,0)">String</span>?) -&gt;<span> </span><span style="color:rgb(195,89,0)">LazyCollection</span>&lt;[<span style="color:rgb(195,89,0)">String</span>]&gt; {</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">   <span> </span><span style="color:rgb(53,86,138)">return</span><span> </span>[</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">       <span> </span><span style="color:rgb(232,35,0)">&quot;Hello&quot;</span>,</font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">        name ??<span> </span><span style="color:rgb(232,35,0)">&quot;World&quot;</span></font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">    ].<span style="color:rgb(88,126,168)">lazy</span></font></div><div style="margin:0px;line-height:normal;font-family:Menlo"><font size="1">}</font></div></div></div></div></blockquote></div><br></div>
</span><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1p9Jer2O6jVE9KWvo-2B9iUaEyN8slp4IizyiLwsfp54Oqefzc418okPdBEDNYIjD86A2xajmfE-2BK5nDkWA7GMxx8LxzA5oJumDJ0LB0U-2F3zFDgzTspN3BavT5QhG2YsRuRJXXYw2lrAFGJM5KmlsoQcySl77zleNyJJWVF2QR6r9xfH8aoSPOLSvDFacp0oNIXV5eMWPKeBhCzz6vf37OUMf1A19wJF5w4qdPPdrPr5E-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>