A partial half-open interval up to, but not including, an upper bound.
SDK
- Xcode 9.0+
Framework
- Swift Standard Library
Declaration
@frozen struct PartialRangeUpTo<Bound> where Bound : Comparable
Overview
You create Partial
instances by using the prefix half-open range operator (prefix ..<
).
let upToFive = ..<5.0
You can use a Partial
instance to quickly check if a value is contained in a particular range of values. For example:
upToFive.contains(3.14) // true
upToFive.contains(6.28) // false
upToFive.contains(5.0) // false
You can use a Partial
instance of a collection’s indices to represent the range from the start of the collection up to, but not including, the partial range’s upper bound.
let numbers = [10, 20, 30, 40, 50, 60, 70]
print(numbers[..<3])
// Prints "[10, 20, 30]"