Generic Structure

PartialRangeThrough

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

Declaration

@frozen struct PartialRangeThrough<Bound> where Bound : Comparable

Overview

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]"

Topics

Initializers

init(from: Decoder)

Creates a new instance by decoding from the given decoder.

Instance Properties

Instance Methods

func contains(Bound) -> Bool

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

func encode(to: Encoder)

Encodes this value into the given encoder.

func relative<C>(to: C) -> Range<Bound>

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

Relationships

Conforms To

See Also

Range Expressions

struct PartialRangeUpTo

A partial half-open interval up to, but not including, an upper bound.

struct PartialRangeFrom

A partial interval extending upward from a lower bound.

protocol RangeExpression

A type that can be used to slice a collection.

enum UnboundedRange_

A range expression that represents the entire range of a collection.