[swift-evolution] Add a `clamp` function to Algorithm.swift

Nevin Brackett-Rozinsky nevin.brackettrozinsky at gmail.com
Fri Mar 10 13:32:15 CST 2017

On Fri, Mar 10, 2017 at 4:16 AM, David Sweeris via swift-evolution <
swift-evolution at swift.org> wrote:

> I’m ok with doing it as an extension on `Comparable`, although we should
> add an overload for regular ranges, too.
> - Dave Sweeris

How would the semantics of that work?

Should “16.clamped(to: 0..<10)” produce 9 or 10?

What about “16.clamped(to: 0..<0)”, which is an empty range?

Does “16.0.clamped(to: 0..<10)” yield 10.0 or the next-smaller
representable Double?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170310/ae2e9bf0/attachment.html>

More information about the swift-evolution mailing list