## PartialRangeThrough

`struct PartialRangeThrough<Bound>`

A partial interval up to, and including, an upper bound.

You create `PartialRangeThrough` instances by using the prefix closed range operator (prefix `...`).

``let throughFive = ...5.0``

You can use a `PartialRangeThrough` instance to quickly check if a value is contained in a particular range of values. For example:

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

You can use a `PartialRangeThrough` instance 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]"``````
Inheritance `RangeExpression` View Protocol Hierarchy → `import Swift`

### Initializers

init(_:)

#### Declaration

`init(_ upperBound: Bound)`

### Instance Variables

var upperBound: Bound

#### Declaration

`var upperBound: Bound { get }`

### Instance Methods

func contains(_:)

Returns a Boolean value indicating whether the given element is contained within the range expression.

`element`: The element to check for containment. Returns: `true` if `element` is contained in the range expression; otherwise, `false`.

#### Declaration

`func contains(_ element: Bound) -> Bool`
func relative(to:)

Returns the range of indices described by this range expression within the given collection.

You can use the `relative(to:)` method to convert a range expression, which could be missing one or both of its endpoints, into a concrete range that is bounded on both sides. The following example uses this method to convert a partial range up to `4` into a half-open range, using an array instance to add the range's lower bound.

``````let numbers = [10, 20, 30, 40, 50, 60, 70]
let upToFour = ..<4

let r1 = upToFour.relative(to: numbers)
// r1 == 0..<4``````

The `r1` range is bounded on the lower end by `0` because that is the starting index of the `numbers` array. When the collection passed to `relative(to:)` starts with a different index, that index is used as the lower bound instead. The next example creates a slice of `numbers` starting at index `2`, and then uses the slice with `relative(to:)` to convert `upToFour` to a concrete range.

``````let numbersSuffix = numbers[2...]
// numbersSuffix == [30, 40, 50, 60, 70]

``````let numbersPrefix = numbers[upToFour]
`collection`: The collection to evaluate this range expression in relation to. Returns: A range suitable for slicing `collection`. The returned range is not guaranteed to be inside the bounds of `collection`. Callers should apply the same preconditions to the return value as they would to a range provided directly by the user.
`func relative<C>(to collection: C) -> Range<Bound> where Bound == C.Index, C : Collection`