<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 9, 2016, at 4:33 AM, Haravikk via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">While I’m in favour of the basic idea I think the operator selection is too complex, and I’m not sure about the need for negative strides. Really all I want are the following:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>(0 ... 6).striding(by: 2)<span class="Apple-tab-span" style="white-space:pre">        </span>// [0, 2, 4, 6]<span class="Apple-tab-span" style="white-space:pre">                </span>x from 0 to 6</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>(0 ..< 6).striding(by: 2)<span class="Apple-tab-span" style="white-space:pre">        </span>// [0, 2, 4]<span class="Apple-tab-span" style="white-space:pre">                </span>x from 0 while <6</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>(6 ... 0).striding(by: 2)<span class="Apple-tab-span" style="white-space:pre">        </span>// [6, 4, 2, 0]<span class="Apple-tab-span" style="white-space:pre">                </span>x from 6 to 0</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>(6 ..> 0).striding(by: 2)<span class="Apple-tab-span" style="white-space:pre">        </span>// [6, 4, 2]<span class="Apple-tab-span" style="white-space:pre">                </span>x from 6 while >0</font></div><div class=""><br class=""></div><div class="">Everything else should be coverable either by flipping the order, or using .reverse(). The main advantage is that there’s only one new operator to clarify the 6 ..> 0 case, though you could always just reuse the existing operator if you just interpret it as “x from 6 to, but not including, 0"</div></div></div></blockquote></div><br class=""><div class="">`.reverse()` returns an array, though, not a StrideTo<>, which means it’ll get in an infinite loop on infinite sequences. This works fine:</div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> i </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">stride</span><span style="font-variant-ligatures: no-common-ligatures" class="">(from: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.0</span><span style="font-variant-ligatures: no-common-ligatures" class="">, to: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures" class="">.infinity, by: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">M_PI</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">someTestInvolving</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(i) { </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">break</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ...</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">But this never even starts executing the loop because of the infinite loop inside `.reverse()`:</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> i </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">stride</span><span style="font-variant-ligatures: no-common-ligatures" class="">(from: -</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures" class="">.infinity, to: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.0</span><span style="font-variant-ligatures: no-common-ligatures" class="">, by: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">M_PI</span><span style="font-variant-ligatures: no-common-ligatures" class="">).</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">reverse</span><span style="font-variant-ligatures: no-common-ligatures" class="">() {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">someTestInvolving</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(i) { </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">break</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> }</span></div><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> ...</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div></span></div></span></span></div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></body></html>