Operator

...(_:)

Returns a partial range up to, and including, its upper bound.

Declaration

prefix static func ... (maximum: Self) -> PartialRangeThrough<Self>

Parameters

maximum

The upper bound for the range.

Discussion

Use the prefix closed range operator (prefix ...) to create a partial range of any type that conforms to the Comparable protocol. This example creates a PartialRangeThrough<Double> instance that includes any value less than or equal to 5.0.

let throughFive = ...5.0

throughFive.contains(4.0)     // true
throughFive.contains(5.0)     // true
throughFive.contains(6.0)     // false

You can use this type of partial range of a collection’s indices to represent the range from the start of the collection up to, and including, the partial range’s upper bound.

let numbers = [10, 20, 30, 40, 50, 60, 70]
print(numbers[...3])
// Prints "[10, 20, 30, 40]"

See Also

Range Expressions

static func ..< (Self, Self) -> Range<Self>

Returns a half-open range that contains its lower bound but not its upper bound.

static func ... (Self, Self) -> ClosedRange<Self>

Returns a closed range that contains both of its bounds.

static func ... (Self) -> PartialRangeFrom<Self>

Returns a partial range extending upward from a lower bound.

static func ..< (Self) -> PartialRangeUpTo<Self>

Returns a partial range up to, but not including, its upper bound.