I’d be on board with an extension of Comparable so you could write
ā€œ16.clamped(to: 0...10)ā€. Something along the lines of:

extension Comparable {
    func clamped(to range: ClosedRange<Self>) -> Self {
        return max(range.lowerBound, min(self, range.upperBound))
    }
}

Nevin
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to