subscript(_:)
subscript(x: (UnboundedRange_) -> ()) -> Self.SubSequence { get }
subscript(x: (UnboundedRange_) -> ()) -> Self.SubSequence { get }
import Swift
protocol Collection<Element> : Sequence
A sequence whose elements can be traversed multiple times, nondestructively, and accessed by an indexed subscript.
@frozen enum UnboundedRange_
A range expression that represents the entire range of a collection.
associatedtype SubSequence : Collection = Slice<Self> where Self.Element == Self.SubSequence.Element, Self.SubSequence == Self.SubSequence.SubSequence
A collection representing a contiguous subrange of this collection’s elements. The subsequence shares indices with the original collection.
subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
Accesses a contiguous subrange of the collection’s elements.
subscript(position: Self.Index) -> Self.Element { get }
Accesses the element at the specified position.
var count: Int { get }
The number of elements in the collection.
var first: Self.Element? { get }
The first element of the collection.
var isEmpty: Bool { get }
A Boolean value indicating whether the collection is empty.
var underestimatedCount: Int { get }
A value less than or equal to the number of elements in the collection.
subscript<R>(r: R) -> Self.SubSequence where R : RangeExpression, Self.Index == R.Bound { get }
Accesses the contiguous subrange of the collection’s elements specified by a range expression.
subscript(subranges: RangeSet<Self.Index>) -> DiscontiguousSlice<Self> { get }
Accesses a view of this collection with the elements at the given indices.
func distance(from start: Self.Index, to end: Self.Index) -> Int
Returns the distance between two indices.
func drop(while predicate: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence
Returns a subsequence by skipping elements while predicate
returns true
and returning the remaining elements.
func dropFirst(_ k: Int = 1) -> Self.SubSequence
Returns a subsequence containing all but the given number of initial elements.
func dropLast(_ k: Int = 1) -> Self.SubSequence
Returns a subsequence containing all but the specified number of final elements.
func firstIndex(where predicate: (Self.Element) throws -> Bool) rethrows -> Self.Index?
Returns the first index in which an element of the collection satisfies the given predicate.
func formIndex(_ i: inout Self.Index, offsetBy distance: Int)
Offsets the given index by the specified distance.
func formIndex(_ i: inout Self.Index, offsetBy distance: Int, limitedBy limit: Self.Index) -> Bool
Offsets the given index by the specified distance, or so that it equals the given limiting index.
func formIndex(after i: inout Self.Index)
Replaces the given index with its successor.
func index(_ i: Self.Index, offsetBy distance: Int) -> Self.Index
Returns an index that is the specified distance from the given index.
func index(_ i: Self.Index, offsetBy distance: Int, limitedBy limit: Self.Index) -> Self.Index?
Returns an index that is the specified distance from the given index, unless that distance is beyond a given limiting index.
func indices(where predicate: (Self.Element) throws -> Bool) rethrows -> RangeSet<Self.Index>
Returns the indices of all the elements that match the given predicate.
func map<T, E>(_ transform: (Self.Element) throws(E) -> T) throws(E) -> [T] where E : Error
Returns an array containing the results of mapping the given closure over the sequence’s elements.
func prefix(_ maxLength: Int) -> Self.SubSequence
Returns a subsequence, up to the specified maximum length, containing the initial elements of the collection.
func prefix(through position: Self.Index) -> Self.SubSequence
Returns a subsequence from the start of the collection through the specified position.
func prefix(upTo end: Self.Index) -> Self.SubSequence
Returns a subsequence from the start of the collection up to, but not including, the specified position.
func prefix(while predicate: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence
Returns a subsequence containing the initial elements until predicate
returns false
and skipping the remaining elements.
func randomElement() -> Self.Element?
Returns a random element of the collection.
func randomElement<T>(using generator: inout T) -> Self.Element? where T : RandomNumberGenerator
Returns a random element of the collection, using the given generator as a source for randomness.
func removingSubranges(_ subranges: RangeSet<Self.Index>) -> DiscontiguousSlice<Self>
Returns a collection of the elements in this collection that are not represented by the given range set.
func split(maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true, whereSeparator isSeparator: (Self.Element) throws -> Bool) rethrows -> [Self.SubSequence]
Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.
func suffix(_ maxLength: Int) -> Self.SubSequence
Returns a subsequence, up to the given maximum length, containing the final elements of the collection.
func suffix(from start: Self.Index) -> Self.SubSequence
Returns a subsequence from the specified position to the end of the collection.
func distance<T>(from start: Self.Index, to end: Self.Index) -> T where T : BinaryInteger
func flatMap(_ transform: (Self.Element) throws -> String?) rethrows -> [String]
func formIndex<T>(_ i: inout Self.Index, offsetBy n: T) where T : BinaryInteger
func formIndex<T>(_ i: inout Self.Index, offsetBy n: T, limitedBy limit: Self.Index) -> Bool where T : BinaryInteger
func index<T>(_ i: Self.Index, offsetBy n: T) -> Self.Index where T : BinaryInteger
func index<T>(_ i: Self.Index, offsetBy n: T, limitedBy limit: Self.Index) -> Self.Index? where T : BinaryInteger
typealias IndexDistance = Int