<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="">An implementation of this is actually pretty complicated, since you aren’t supposed to call a generator once it’s returned nil.<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span> NilPaddedZipGenerator&lt;G0: GeneratorType, G1: GeneratorType&gt; : <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">GeneratorType</span> {</div><p style="margin: 0px; line-height: normal; min-height: 13px;" class="">&nbsp;&nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">private</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> (g0, g1): (<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">G0</span>?, <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">G1</span>?)</div><p style="margin: 0px; line-height: normal; min-height: 13px;" class="">&nbsp;&nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">mutating</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> next() -&gt; (<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">G0</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>?, <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">G1</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>?)? {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> (e0,e1) = (<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">g0</span>?.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">next</span>(),<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">g1</span>?.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">next</span>())</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span> (e0,e1) {</div><div style="margin: 0px; line-height: normal; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>case<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (</span>nil<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">,</span>nil<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">): </span>return<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>nil</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> (&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span>): <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">g1</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> (<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span>,&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span>): <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">g0</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span></div><div style="margin: 0px; line-height: normal; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>default<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span>break</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> (e0,e1)</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; }</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span> NilPaddedZip&lt;S0: SequenceType, S1: SequenceType&gt; : <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">LazySequenceType</span> {</div><p style="margin: 0px; line-height: normal; min-height: 13px;" class="">&nbsp;&nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">private</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> (s0, s1): (<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">S0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">S1</span>)</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> generate() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">NilPaddedZipGenerator</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">S0</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Generator</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">S1</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Generator</span>&gt; {</div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>NilPaddedZipGenerator<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(g0: </span>s0<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">generate</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(), g1: </span>s1<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">generate</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">())</span></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; }</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(187, 44, 162);" class="">@warn_unused_result</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> zipWithPadding&lt;S0: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SequenceType</span>, S1: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SequenceType</span>&gt;(s0: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">S0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span> s1: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">S1</span>)</div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; -&gt; </span>NilPaddedZip<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">S0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">S1</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&gt; {</span></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">NilPaddedZip</span>(s0: s0, s1: s1)</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div></div><div><blockquote type="cite" class=""><div class="">On 6 Dec 2015, at 23:44, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Is there an implementation in the stdlib for (T?, T?) like this?</div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 4:37 PM, Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Sun, Dec 6, 2015 at 3:34 PM, Erica Sadun via swift-evolution<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span><span class="Apple-converted-space">&nbsp;</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 class="" style="word-wrap: break-word;"><div class="">It's pretty easy to build your own Zips. Not sure the language really needs this. For example, I recently built a zip that produces (T?, T?) which fills one of the two with nil until both lists are consumed:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>longZip&lt;S0: SequenceType, S1: SequenceType&gt;(seq0: S0,<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="Apple-converted-space">&nbsp;</span>seq1: S1) -&gt;</div><div class="" style="margin: 0px; line-height: normal;"><span class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span>AnyGenerator<span class="">&lt;(</span>S0<span class="">.</span>Generator<span class="">.</span>Element<span class="">?,<span class="Apple-converted-space">&nbsp;</span></span>S1<span class="">.</span>Generator<span class="">.</span>Element<span class="">?)&gt; {</span></div></div></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class=""></div></div><div class="gmail_extra">Just wanted to point out that AnyGenerator has an inherent cost from the type erasure.&nbsp; The implementation in the standard library uses generics and is fully optimizable.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">Dmitri</div><div class=""><br class=""></div>--<span class="Apple-converted-space">&nbsp;</span><br class=""><div class="gmail_signature">main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br class="">(j){printf("%d\n",i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" target="_blank" class="">gribozavr@gmail.com</a>&gt;*/</div></div></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Lo8TP3b1oIn3yQXUt9zA1UCQfR-2BMBCuqnubTuDg47-2B016z-2F8HeT95QRrJrhT2NAKJPocQhb3AofXv07OB3FXYsWIGA1k-2F2-2BJpLMg-2BZCmXGqx7mocuK-2Bx6ejN8qCnp0318VhhODd8A0pr6IljpDPqeCK1H7ySi-2F-2BK9hsKnh6SDq26CqzrlLyXAmjQHo05ocU2aXfkA8Wuzvc6m62fQ33wFHfCPvfb52iKbBv4scJdtq4-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span></span><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></body></html>