[swift-evolution] [Idea] Add `bounds` function to standard library

Karl razielim at gmail.com
Wed Aug 31 08:10:07 CDT 2016

> On 30 Aug 2016, at 10:18, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> As an additive proposal, I don't think this would be in scope for the current phase of Swift 4.
> Looking forward, though, I'm not sure this belongs in the standard library. In general, my understanding is that Swift's standard library is deliberately small, and that the criteria for additions are that it's widely used *and* also non-trivial for the user to write correctly. I've had to use clamping, obviously, but it's a trivial one-liner that is hard to write incorrectly. If anything, I'd be in favor of removing max and min into a future math library outside the standard library.

min & max (and clamping) are hardly “math” operations. They operate on Comparables, so you can apply them to more abstract things than just numbers.

Otherwise, you might as well put Comparable and all standard numeric types like Int and Float in a math library, too.

More information about the swift-evolution mailing list