<div dir="ltr"><div class="gmail_default" style="font-family:&quot;comic sans ms&quot;,sans-serif;color:rgb(39,78,19)">Swift Evolution, </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)">Having a`clamp` function available in the standard library would complement `min` and `max` really well.</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)">I mentioned this before when the discussion for Swift 4 was still in stage 1, but now that stage 2 has started I thought it might be worth while to bring up again.</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)">Still needs some work, but here is the draft proposal I wrote previously</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"><font color="#274e13" face="comic sans ms, sans-serif"><a href="https://github.com/Nirma/swift-evolution/commit/a51c543a76e9a1021996fb4b617311a588e7f397">https://github.com/Nirma/swift-evolution/commit/a51c543a76e9a1021996fb4b617311a588e7f397</a></font><br></div><div class="gmail_default"><br></div><div class="gmail_default"><font color="#274e13" face="comic sans ms, sans-serif">Basically it boils down to something like this.</font></div><div class="gmail_default"><font color="#274e13" face="comic sans ms, sans-serif"><br></font></div><div class="gmail_default"><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)"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">public</span> <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">clamp</span>&lt;<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">T</span> : <span class="gmail-pl-e" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Comparable</span></span>&gt;(<span class="gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">value</span></span>: T, <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">lower</span>: T, <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">upper</span>: T) <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">-&gt;</span> T {
  <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">max</span>(lower, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">min</span>(value, upper))
}</pre></div><div class="gmail_default"><br></div><div class="gmail_default"><br></div><div class="gmail_default"><font color="#274e13" face="comic sans ms, sans-serif">What does the community think?</font></div><div class="gmail_default"><font color="#274e13" face="comic sans ms, sans-serif"><br></font></div><div class="gmail_default"><font color="#274e13" face="comic sans ms, sans-serif">- Nick </font></div></div>