| 12345678910111213141516171819202122232425 |
- //
- // Comparable.swift
- // MinimedKitUI
- //
- // Created by Pete Schwamb on 3/19/23.
- //
- import Foundation
- extension Comparable {
- func clamped(to range: ClosedRange<Self>) -> Self {
- if self < range.lowerBound {
- return range.lowerBound
- } else if self > range.upperBound {
- return range.upperBound
- } else {
- return self
- }
- }
- mutating func clamp(to range: ClosedRange<Self>) {
- self = clamped(to: range)
- }
- }
|