`struct PartialRangeFrom`

A partial interval extending upward from a lower bound.

Inheritance | `RangeExpression` |
---|

### Initializers

### Instance Variables

### Instance Methods

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

- Parameter element: The element to check for containment.

#### Declaration

`@inlinable public func contains(_ element: Bound) -> Bool`

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 r2 = upToFour.relative(to: numbersSuffix)
// r2 == 2..<4
```

Use this method only if you need the concrete range it produces. To access a slice of a collection using a range expression, use the collection's generic subscript that uses a range expression as its parameter.

```
let numbersPrefix = numbers[upToFour]
// numbersPrefix == [10, 20, 30, 40]
```

- Parameter collection: The collection to evaluate this range expression in relation to.

#### Declaration

`public func relative<C>(to collection: C) -> Range<Bound> where Bound == C.Index, C: Collection`

### Type Methods

#### Declaration

`@inlinable public static func ~=(pattern: Self, value: Self.Bound) -> Bool`

You create

`PartialRangeFrom`

instances by using the postfix range operator (postfix`...`

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

You can use a partial range of a collection's indices to represent the range from the partial range's lower bound up to the end of the collection.

## Using a Partial Range as a Sequence

When a partial range uses integers as its lower and upper bounds, or any other type that conforms to the

`Strideable`

protocol with an integer stride, you can use that range in a`for`

-`in`

loop or with any sequence method that doesn't require that the sequence is finite. The elements of a partial range are the consecutive values from its lower bound continuing upward indefinitely.Because a

`PartialRangeFrom`

sequence counts upward indefinitely, do not use one with methods that read the entire sequence before returning, such as`map(_:)`

,`filter(_:)`

, or`suffix(_:)`

. It is safe to use operations that put an upper limit on the number of elements they access, such as`prefix(_:)`

or`dropFirst(_:)`

, and operations that you can guarantee will terminate, such as passing a closure you know will eventually return`true`

to`first(where:)`

.In the following example, the

`asciiTable`

sequence is made by zipping together the characters in the`alphabet`

string with a partial range starting at 65, the ASCII value of the capital letter A. Iterating over two zipped sequences continues only as long as the shorter of the two sequences, so the iteration stops at the end of`alphabet`

.The behavior of incrementing indefinitely is determined by the type of

`Bound`

. For example, iterating over an instance of`PartialRangeFrom<Int>`

traps when the sequence's next value would be above`Int.max`

.