Overload 'in' method for Comparable to use ClosedRange
This commit is contained in:
parent
16b209cd59
commit
44ccb8dd28
|
|
@ -30,4 +30,11 @@ public extension Comparable {
|
|||
func `in`(bounds: (lower: Self, upper: Self)) -> Self {
|
||||
return min(max(bounds.lower, self), bounds.upper)
|
||||
}
|
||||
|
||||
/// Use this function to restrict comparable with lower and upper values
|
||||
/// - parameter range: ClosedRange representing bounds
|
||||
/// - returns: Current value if it fits range, otherwise lower if value is too small or upper if value is too big
|
||||
func `in`(range: ClosedRange<Self>) -> Self {
|
||||
return `in`(bounds: (lower: range.lowerBound, upper: range.upperBound))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue