<div dir="ltr"><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Jaden,</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Yes that error message is not so great.</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">As for the use of guard `if someCondition { fatalError(...)}` seems to be a common way of phrasing fatal errors </div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">in the standard library but guard works just as well.</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">I updated the proposal to have the following definition:</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><div class="gmail_default">extension Strideable where Stride: Integer {</div><div class="gmail_default"> func clamped(to range: Range<Self>) -> Self {</div><div class="gmail_default"> guard !range.isEmpty { fatalError("Can not clamp to an empty range.") }</div><div class="gmail_default"> return clamped(to: range.lowerBound...(range.upperBound - 1))</div><div class="gmail_default"> }</div><div class="gmail_default">}</div><div class="gmail_default"><br></div><div class="gmail_default">- Nick </div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 16, 2017 at 11:57 AM, Jaden Geller <span dir="ltr"><<a href="mailto:jaden.geller@gmail.com" target="_blank">jaden.geller@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Mar 15, 2017, at 7:33 PM, Nicholas Maccharoli <<a href="mailto:nmaccharoli@gmail.com" target="_blank">nmaccharoli@gmail.com</a>> wrote:</div><br class="m_4983569443635852211Apple-interchange-newline"><div><div dir="ltr"><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Right, there were a few things missing!</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Thanks so much for pointing them out everyone.</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Dave - Great idea! I have updated the motivation section section as you suggested!</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Neil - Yes I also think the wording could be a bit better but since the word `clamped` is already being used </div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"> I thought I would keep it consistent. </div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Sean - Looks as if its a term of art to me as well. </div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Nate,</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Good catch! Yes I also thing clamping on an empty range should be a fatal error as well.</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">An empty range is impossible to create with `ClosedRange` so I left the implementation </div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">of that alone, but it is possible with `Range` so I updated the extension on `Strideable` like so:</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">extension</span> <span class="m_4983569443635852211gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Strideable</span></span> <span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">where</span> <span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Stride</span><span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> <span class="m_4983569443635852211gmail-pl-e" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Integer</span></span> {
<span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_4983569443635852211gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">clamped</span>(<span class="m_4983569443635852211gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">to</span> <span class="m_4983569443635852211gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">range</span>: <span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Range</span><<span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>>) <span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> <span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span> {
<span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> range.<span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">isEmpty</span> { <span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">fatalError</span>(<span class="m_4983569443635852211gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="m_4983569443635852211gmail-pl-pds" style="box-sizing:border-box">"</span>Can't form Range with upperBound < lowerBound<span class="m_4983569443635852211gmail-pl-pds" style="box-sizing:border-box">"</span></span>) }
<span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">clamped</span>(<span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">to</span>: range.<span class="m_4983569443635852211gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">lowerBound</span><span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">...</span>(range.<span class="m_4983569443635852211gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">uppe<wbr>rBound</span> <span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">-</span> <span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">1</span>))
}
}</pre></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Jaden,</div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)">Yeah I think a simple `if` check would work as well.</div></div></div></blockquote><div><br></div></span><div>I would suggest using guard. It is more idiomatic Swift for something that “fails out”.</div><div><br></div><div>Also, I think this is a bad error message. The `Range` was already created! There was no problem forming it. It was passed as the argument, no problem at all. The problem is trying to *clamp* to an empty range, not forming an empty range. I would rephrase it to say something like "Cannot clamp to an empty range”. No reason to redefine what an empty range is by mentioning `upperBound < lowerBound`.</div><div><br></div><div>Cheers,</div><div>Jaden Geller</div></div></div></blockquote></div><br></div>