Swift Evolution, Having a`clamp` function available in the standard library would complement `min` and `max` really well.
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. Still needs some work, but here is the draft proposal I wrote previously https://github.com/Nirma/swift-evolution/commit/a51c543a76e9a1021996fb4b617311a588e7f397 Basically it boils down to something like this. public func clamp<T : Comparable>(value: T, _ lower: T, _ upper: T) -> T { return max(lower, min(value, upper)) } What does the community think? - Nick
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution