<div dir="ltr">Curiously I was analyzing this part of the library a few minutes ago.<div>It will probably be necessary to extend &quot;Range&quot;:<br></div><div><br></div><div><div>extension Range where Element: Strideable {</div><div>    func by(n: Element.Stride) -&gt; StrideThrough&lt;Element&gt; {</div><div>        return startIndex.stride(through: endIndex, by: n)</div><div>    }</div><div>}</div></div><div><br></div><div>The first thing that came into my head was:<br></div><div><br></div><div><div>var rangeA = -150.0..&lt;150 // HalfOpenInterval&lt;Double&gt;</div><div>var rangeB = -150.0...150 // ClosedInterval&lt;Double&gt;</div><div>var rangeC = -150..&lt;150 // Range&lt;Int&gt;</div><div>var rangeD = -150...150 // Range&lt;Int&gt;</div></div><div><br></div><div>For &quot;Range&quot; we need to use startIndex and endIndex respectively, and with HalfOpenInterval/ClosedInterval only start and end.<br></div><div><br></div><div>I do not know for you, but it seems inconsistent and redundant to me.<br></div><div><br></div><br><div class="gmail_quote"><div dir="ltr">Em sáb, 19 de dez de 2015 às 18:39, Dave Abrahams via swift-dev &lt;<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>&gt; escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Dec 19, 2015, at 11:44 AM, Donnacha Oisín Kidney via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>&gt; wrote:</div><br><div><span style="font-family:AvenirNext-Regular;font-size:14px;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">You can define an extension on interval types:</span><div style="font-family:AvenirNext-Regular;font-size:14px;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:AvenirNext-Regular;font-size:14px;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;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">extension</span><span> </span><span style="color:rgb(112,61,170)">HalfOpenInterval</span><span> </span><span style="color:rgb(187,44,162)">where</span><span> </span>Bound: Strideable {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span> <span> </span></span><span style="color:rgb(187,44,162)">func</span><span><span> </span>by(n:<span> </span></span>Bound<span>.</span>Stride<span>) -&gt;<span> </span></span>StrideTo<span>&lt;</span>Bound<span>&gt; {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">   <span> </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(112,61,170)">start</span>.<span style="color:rgb(61,29,129)">stride</span>(to:<span> </span><span style="color:rgb(112,61,170)">end</span>, by: n)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">extension</span><span> </span><span style="color:rgb(112,61,170)">ClosedInterval</span><span> </span><span style="color:rgb(187,44,162)">where</span><span> </span>Bound: Strideable {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span> <span> </span></span><span style="color:rgb(187,44,162)">func</span><span><span> </span>by(n:<span> </span></span>Bound<span>.</span>Stride<span>) -&gt;<span> </span></span>StrideThrough<span>&lt;</span>Bound<span>&gt; {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">   <span> </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(112,61,170)">start</span>.<span style="color:rgb(61,29,129)">stride</span>(through:<span> </span><span style="color:rgb(112,61,170)">end</span>, by: n)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:Helvetica;font-size:12px">Which maybe gives you slightly more elegant usage:</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:Helvetica;font-size:12px"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><div style="margin:0px;line-height:normal"><span style="color:rgb(187,44,162)">for</span><span> </span>lat<span> </span><span style="color:rgb(187,44,162)">in</span><span> </span>(<span style="color:rgb(112,61,170)">CGFloat</span>(-<span style="color:rgb(49,44,221)">60</span>)...<span style="color:rgb(49,44,221)">60</span>).<span style="color:rgb(49,89,93)">by</span>(<span style="color:rgb(49,44,221)">30</span>) {</div><div style="margin:0px;line-height:normal"> <span> </span><span style="color:rgb(61,29,129)">print</span>(lat)</div><div style="margin:0px;line-height:normal">}</div><div style="margin:0px;line-height:normal;min-height:13px"><br></div><div style="margin:0px;line-height:normal"><span style="color:rgb(187,44,162)">for</span><span> </span>lat<span> </span><span style="color:rgb(187,44,162)">in</span><span> </span>(<span style="color:rgb(112,61,170)">CGFloat</span>(-<span style="color:rgb(49,44,221)">60</span>)..&lt;<span style="color:rgb(49,44,221)">60</span>).<span style="color:rgb(49,89,93)">by</span>(<span style="color:rgb(49,44,221)">30</span>) {</div><div style="margin:0px;line-height:normal"> <span> </span><span style="color:rgb(61,29,129)">print</span>(lat)</div><div style="margin:0px;line-height:normal">}</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div>This is nice; why don&#39;t we put it in the standard library and get rid of the &quot;stride&quot; methods?</div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div style="font-family:AvenirNext-Regular;font-size:14px;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><blockquote type="cite"><div>On 19 Dec 2015, at 18:59, Gavin Eadie via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">With C-style for loops to be removed from the language to general acclaim (including mine), is the following the best way to perform the required looping:<div><br></div><div><font face="Courier"><span style="font-size:11px">    for lat in (CGFloat(-60.0)).stride(through: +60.0, by: 30.0) {<br>        path.moveToPoint(CGPointMake(-180.0, lat))<br>        path.lineToPoint(CGPointMake(+180.0, lat))<br>    }<br><br>    for lon in (CGFloat(-150.0)).stride(through: +150.0, by: 30.0) {<br>        path.moveToPoint(CGPointMake(lon, +90.0))<br>        path.lineToPoint(CGPointMake(lon, -90.0))<br>    }<br></span></font><br></div><div>That seems a slightly cumbersome usage.  Is there a better way to initialize the SequenceType I want to iterate over?</div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Lo8TP3b1oIn3yQXUt9zA1UCQfR-2BMBCuqnubTuDg47-2B2JrWct5LdmVtzlyLW-2FdFy-2BgksNk2B1nhv7HyAz0CWOkz3uQImvpZhn0tb9ulJe09H7KnMvvQYuNn1jvNDTuRxES-2FE9NCn3AlgkmyF9n8EHZrSTZEYMdrE-2F-2B-2FIkSBhtNgf0z6l-2FLBFGr3QUlmpEk6MrCUh8Xw1CAyWJiIZPEP4Gw2Oq4-2FEB-2BVfb9jsek6Esir8-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>swift-dev mailing list<br><a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-dev" target="_blank">https://lists.swift.org/mailman/listinfo/swift-dev</a><br></div></blockquote></div><br></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=JfMPa-2F7wwZPzsZ3QKA8NjtONIYX4SjbWuUxtpfsTY2hrIG45T1JEtKY7V6eRrtcZ-2Bm4c-2B-2Bx1lhNRnkz8xpKofoZeCTFrNYJ-2B9gocEcD8Urs2ePECe9YLUt02RsQqM4XfmPSGcbYNhsDDullHozIEdavdcjNarhuyuONNymkRWrrqGRv0XIxLoKsbNfSMp68jaE9VbluGDqA3-2F03l4y7j7byqI-2B3xMUYqndqHIb7oR74-3D" alt="" width="1" height="1" border="0" style="font-family:AvenirNext-Regular;font-size:14px;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;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:AvenirNext-Regular;font-size:14px;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"><span> </span>_______________________________________________</span><br style="font-family:AvenirNext-Regular;font-size:14px;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"><span style="font-family:AvenirNext-Regular;font-size:14px;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">swift-dev mailing list</span><br style="font-family:AvenirNext-Regular;font-size:14px;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"><a href="mailto:swift-dev@swift.org" style="font-family:AvenirNext-Regular;font-size:14px;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" target="_blank">swift-dev@swift.org</a><br style="font-family:AvenirNext-Regular;font-size:14px;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"><a href="https://lists.swift.org/mailman/listinfo/swift-dev" style="font-family:AvenirNext-Regular;font-size:14px;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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-dev</a></div></blockquote></div><br></div><div style="word-wrap:break-word"><div>
-Dave<div><br></div><br>

</div>
<br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=fuWmDRE6-2FDdvdUHeLHruUfdigJaxz7nh99l6HfkulY9zc1AEBTCn0nA0fPpMPgi1unJE7Ep8HtxumrD1xylFuHnwzbBqVD4-2FeoRA4ErRpAmWHiVkCX6KTzplR64tYvNdtYK7-2B-2BhRYqtwiKP-2Ftgw4feBjMxBsEmzuDMyKkKXMWlNTZnQFvjGH9jt-2FLvNubEcgPytU3fzCyBW8ZisryS0zGVIihrZ7TOQoncDhIINovoA-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
_______________________________________________<br>
swift-dev mailing list<br>
<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-dev</a><br>
</blockquote></div></div>