I couldn't find a method to do this in ClosedRange, basically something simple like this:
extension ClosedRange {
/// Force the value to be within the lower and upper bounds of this range
/// - Parameter value: some value
/// - Returns: a value within the bounds of this range
func boundWithin(_ value: Bound) -> Bound {
max(lowerBound, min(value, upperBound))
}
}
should this method be built-in to CloseRange?
Can you help me come up with a better name and signature of my method above? There is clamped already, is clamped here better?
Edit:
got this warning:
Use of 'max' as reference to global function in module 'Swift' will change in future versions of Swift to reference instance method in generic struct 'ClosedRange' which comes via a conditional conformance
Use 'Swift.' to continue to reference the global function
What's the proper thing to do? Swift.max, Swift.min?
or add where some_type to my extension? If so, what's the type?
I haven't read those other threads. Just glancing at them, I didn't see this, but it's probably in there somewhere. I think it makes more sense to reverse your arguments.