<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 10, 2017, at 1:12 AM, Nicholas Maccharoli 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=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:"comic sans ms",sans-serif;color:rgb(39,78,19)"><div class="gmail_default" 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 class="gmail_default" style="font-size:12.8px"><br class=""></div><div class="gmail_default" style="font-size:12.8px"><p class="gmail-m_8093425548888026859gmail-p1"><span class="gmail-m_8093425548888026859gmail-s1">extension</span><span class="gmail-m_8093425548888026859gmail-s2"> </span><span class="gmail-m_8093425548888026859gmail-s3">Comparable</span><span class="gmail-m_8093425548888026859gmail-s2"> {</span></p><p class="gmail-m_8093425548888026859gmail-p2"><span class="gmail-m_8093425548888026859gmail-s3"> </span><span class="gmail-m_8093425548888026859gmail-s1">func</span><span class="gmail-m_8093425548888026859gmail-s3"> clamped(to range: </span><span class="gmail-m_8093425548888026859gmail-s4">ClosedRange</span><span class="gmail-m_8093425548888026859gmail-s3"><</span><span class="gmail-m_8093425548888026859gmail-s5">Self</span><span class="gmail-m_8093425548888026859gmail-s3">>) -> </span><span class="gmail-m_8093425548888026859gmail-s5">Self</span><span class="gmail-m_8093425548888026859gmail-s3"> {</span></p><p class="gmail-m_8093425548888026859gmail-p2"><span class="gmail-m_8093425548888026859gmail-s3"> </span><span class="gmail-m_8093425548888026859gmail-s1">return</span><span class="gmail-m_8093425548888026859gmail-s3"> [range.</span><span class="gmail-m_8093425548888026859gmail-s4">lowerBound</span><span class="gmail-m_8093425548888026859gmail-s3">, [</span><span class="gmail-m_8093425548888026859gmail-s1">self</span><span class="gmail-m_8093425548888026859gmail-s3">, range.</span><span class="gmail-m_8093425548888026859gmail-s4">upperBound</span><span class="gmail-m_8093425548888026859gmail-s3">].</span><span class="gmail-m_8093425548888026859gmail-s4">min</span><span class="gmail-m_8093425548888026859gmail-s3">()!].</span><span class="gmail-m_8093425548888026859gmail-s4">max</span><span class="gmail-m_8093425548888026859gmail-s3">(<wbr class="">)!</span></p><p class="gmail-m_8093425548888026859gmail-p2"><span class="gmail-m_8093425548888026859gmail-s3"> }</span></p><p class="gmail-m_8093425548888026859gmail-p2"><span class="gmail-m_8093425548888026859gmail-s3">}</span></p></div></div></div></div></blockquote>I’m ok with doing it as an extension on `Comparable`, although we should add an overload for regular ranges, too.</div><div><br class=""></div><div>- Dave Sweeris </div></body></html>