yattee/Extensions/Comparable+Clamped.swift

8 lines
168 B
Swift
Raw Normal View History

2022-02-16 20:23:11 +00:00
import Foundation
extension Comparable {
func clamped(to limits: ClosedRange<Self>) -> Self {
min(max(self, limits.lowerBound), limits.upperBound)
}
}