<div dir="ltr">So, having played with this for a bit, it&#39;s not clear to me that a more elaborate implementation of `cycle` functionality would be measurably beneficial over a barebones one.<div><br></div><div>Documentation for `Sequence` clearly indicates that `dropLast` and `suffix` must not be used on infinite sequences. The same can be said to be obvious for `map`, `split`, and the current incarnation of `filter` because these functions return arrays. All other protocol requirements except `drop(while:)` behave as expected with their default implementation.</div><div><br></div><div>There is an improvement possible for `drop(while:)` in that it can be made to return instead of looping forever if the predicate matches every value. However, numerous protocol extension methods that can be shadowed but not overridden have the same issue, and the true solution to that problem is not within the scope of an additive change (it&#39;d require re-designing `Sequence` itself--for overall questionable gain, I think).</div><div><br></div><div>With that in mind, I&#39;d suggest that we&#39;re not looking at much more than this:</div><div><br></div><div>```</div><div><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">extension</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">Collection</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> cycled() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Cycle</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Self</span><span style="font-variant-ligatures:no-common-ligatures">&gt; {</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">    </span><span style="font-variant-ligatures:no-common-ligatures">return</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Cycle</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures">self</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  }</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">struct</span><span style="font-variant-ligatures:no-common-ligatures"> Cycle&lt;T : </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Collection</span><span style="font-variant-ligatures:no-common-ligatures">&gt; {</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> repeatedValues: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">internal</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">var</span><span style="font-variant-ligatures:no-common-ligatures"> _iterator: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span><span style="font-variant-ligatures:no-common-ligatures">.Iterator</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">internal</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">init</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"> _repeatedValues: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span><span style="font-variant-ligatures:no-common-ligatures">) {</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">repeatedValues</span><span style="font-variant-ligatures:no-common-ligatures"> = _repeatedValues</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">_iterator</span><span style="font-variant-ligatures:no-common-ligatures"> = _repeatedValues.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">makeIterator</span><span style="font-variant-ligatures:no-common-ligatures">()</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  }</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">extension</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Cycle</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> : </span><span style="font-variant-ligatures:no-common-ligatures">IteratorProtocol</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">, </span><span style="font-variant-ligatures:no-common-ligatures">Sequence</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">var</span><span style="font-variant-ligatures:no-common-ligatures"> underestimatedCount: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">repeatedValues</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">count</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">&gt;</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">0</span><span style="font-variant-ligatures:no-common-ligatures"> ? </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">max</span><span style="font-variant-ligatures:no-common-ligatures"> : </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">0</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  }</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">mutating</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> next() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span><span style="font-variant-ligatures:no-common-ligatures">.Iterator.Element? {</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">if</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> next = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">_iterator</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">next</span><span style="font-variant-ligatures:no-common-ligatures">() { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"> next }</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">    </span><span style="font-variant-ligatures:no-common-ligatures">_iterator</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> = </span><span style="font-variant-ligatures:no-common-ligatures">repeatedValues</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">makeIterator</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">()</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">_iterator</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">next</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">()</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  }</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)">

























</p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p></div><div>```</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 2, 2017 at 12:45 PM, Xiaodi Wu <span dir="ltr">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Very useful links. Clearly, `cycle` is a related topic. It&#39;s at once more general, in that it would operate on sequences and produce an infinite sequence, and much more tricky to implement, as evidenced by the extensive discussion on support for cycling infinite sequences. Both of those factors could arguably change the balance in terms of thresholds for inclusion in the standard library.<br><div class="gmail_quote"><div><div class="gmail-h5"><div dir="ltr">On Tue, May 2, 2017 at 11:40 Ole Begemann via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail-h5"><div bgcolor="#FFFFFF">
    <div class="gmail-m_-8516102761344108193m_2830531646399196249moz-cite-prefix">On 02.05.2017 18:33, Ole Begemann via
      swift-evolution wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div class="gmail-m_-8516102761344108193m_2830531646399196249moz-cite-prefix">For reference, here are some links to
        previous discussions on related topics:<br>
        <br>
        1) Kevin Ballard in December 2015: <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151228/004635.html" target="_blank">Proposal:
          CollectionType.cycle property for an infinite sequence</a><br>
        <br>
        2) Ben Cohen in February 2016: <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170213/032120.html" target="_blank">Sequence/Collection
          Enhancements</a> (one of the enhancements that Ben proposed to
        consider for adding to the standard library is a <tt>cycle</tt>
        method for <tt>Collection</tt> and/or <tt>Sequence</tt>. I
        don&#39;t think there is a more specific proposal for this yet, but
        at least we know it&#39;s on the core team&#39;s radar.</div>
    </blockquote></div><div bgcolor="#FFFFFF">
    This should be <b>February 2017</b>, of course. Sorry.<br>
  </div></div></div><span class="gmail-">

______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</span></blockquote></div></blockquote></div><br></div></div>