<div dir="ltr"><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">​Dave,</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">​</div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px">I’m ok with doing it as an extension on `Comparable`, although we should add an overload for regular ranges, too.</span></blockquote><div><br></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">​Yeah, I completely agree and for now I&#39;ll drop the topic of removing the global definitions for min / max​.</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">So the aim of this proposal would be to add `clamp` to both `Range` and `Comparable`.</div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><br></div><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">- Nick  </div><div> </div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 10, 2017 at 6:16 PM, David Sweeris <span dir="ltr">&lt;<a href="mailto:davesweeris@mac.com" target="_blank">davesweeris@mac.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class="m_2458407801295457640gmail-"><blockquote type="cite"><div>On Mar 10, 2017, at 1:12 AM, Nicholas Maccharoli via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_2458407801295457640gmail-m_-3494181985858301227Apple-interchange-newline"><div><div dir="ltr"><div style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)"><div style="font-size:12.8px">Sorry for sidetracking by talking about dumping the global definitions of `min` and `max` but if that could be done and it were decided by the swift community that adding a clamp function would be appropriate, I guess with the array implementations of min / max the clamp function might be implemented like this?</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><p class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-p1"><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s1">extension</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s2"> </span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">Comparable</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s2"> {</span></p><p class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-p2"><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">    </span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s1">func</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3"> clamped(to range: </span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s4">ClosedRange</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">&lt;</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s5">Self</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">&gt;) -&gt; </span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s5">Self</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3"> {</span></p><p class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-p2"><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">        </span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s1">return</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3"> [range.</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s4">lowerBound</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">, [</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s1">self</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">, range.</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s4">upperBound</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">].</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s4">min</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">()!].</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s4">max</span><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">(<wbr>)!</span></p><p class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-p2"><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">    }</span></p><p class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-p2"><span class="m_2458407801295457640gmail-m_-3494181985858301227gmail-m_8093425548888026859gmail-s3">}</span></p></div></div></div></div></blockquote></span>I’m ok with doing it as an extension on `Comparable`, although we should add an overload for regular ranges, too.</div><div><br></div><div>- Dave Sweeris </div></div></blockquote></div><br></div></div>