<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 Mar 15, 2017, at 8:21 PM, Nicholas Maccharoli &lt;<a href="mailto:nmaccharoli@gmail.com" class="">nmaccharoli@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Jaden,</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Yes that error message is not so great.</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">As for the use of guard &nbsp;`if someCondition { fatalError(...)}` seems to be a common way of phrasing fatal errors&nbsp;</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">in the standard library but guard works just as well.</div></div></div></blockquote><div><br class=""></div><div>I’d guess that’s because most of the standard library predates the existence of `guard`, but I’m not sure! Either spelling is probably fine (and more the topic of a pull request than a SE review 🙂).</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">I updated the proposal to have the following definition:</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><div class="gmail_default">extension Strideable where Stride: Integer {</div><div class="gmail_default">&nbsp; &nbsp; func clamped(to range: Range&lt;Self&gt;) -&gt; Self {</div><div class="gmail_default">&nbsp; &nbsp; &nbsp; &nbsp; guard !range.isEmpty { fatalError("Can not clamp to an empty range.") }</div><div class="gmail_default">&nbsp; &nbsp; &nbsp; &nbsp; return clamped(to: range.lowerBound...(range.upperBound - 1))</div><div class="gmail_default">&nbsp; &nbsp; }</div><div class="gmail_default">}</div><div class="gmail_default"><br class=""></div><div class="gmail_default">- Nick&nbsp;</div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Mar 16, 2017 at 11:57 AM, Jaden Geller <span dir="ltr" class="">&lt;<a href="mailto:jaden.geller@gmail.com" target="_blank" class="">jaden.geller@gmail.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Mar 15, 2017, at 7:33 PM, Nicholas Maccharoli &lt;<a href="mailto:nmaccharoli@gmail.com" target="_blank" class="">nmaccharoli@gmail.com</a>&gt; wrote:</div><br class="m_4983569443635852211Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Right, there were a few things missing!</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Thanks so much for pointing them out everyone.</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,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:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,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&nbsp;</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I thought I would keep it consistent.&nbsp;</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Sean - Looks as if its a term of art to me as well.&nbsp;</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Nate,</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,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:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">An empty range is impossible to create with `ClosedRange` so I left the implementation&nbsp;</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,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:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,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)" class=""><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>&lt;<span class="m_4983569443635852211gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>&gt;) <span class="m_4983569443635852211gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">-&gt;</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 &lt; 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 class="">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:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Jaden,</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Yeah I think a simple `if` check would work as well.</div></div></div></blockquote><div class=""><br class=""></div></span><div class="">I would suggest using guard. It is more idiomatic Swift for something that “fails out”.</div><div class=""><br class=""></div><div class="">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 &lt; lowerBound`.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Jaden Geller</div></div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""><div class="">Cheers,</div><div class="">Jaden Geller</div></body></html>