Skip to content

Commit 320e439

Browse files
committed
[Standard library] Duplicate subscript requirement in RandomAccessCollection.
Similar to what we did for BidirectionalCollection, duplicate the subscript-returning-SubSequence requirement in RandomAccessCollection.
1 parent eacf223 commit 320e439

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

stdlib/public/core/RandomAccessCollection.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ public protocol RandomAccessCollection :
8181
/// }
8282
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
8383
var indices: Indices { get }
84+
85+
/// Accesses a contiguous subrange of the collection's elements.
86+
///
87+
/// The accessed slice uses the same indices for the same elements as the
88+
/// original collection uses. Always use the slice's `startIndex` property
89+
/// instead of assuming that its indices start at a particular value.
90+
///
91+
/// This example demonstrates getting a slice of an array of strings, finding
92+
/// the index of one of the strings in the slice, and then using that index
93+
/// in the original array.
94+
///
95+
/// let streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
96+
/// let streetsSlice = streets[2 ..< streets.endIndex]
97+
/// print(streetsSlice)
98+
/// // Prints "["Channing", "Douglas", "Evarts"]"
99+
///
100+
/// let index = streetsSlice.index(of: "Evarts") // 4
101+
/// print(streets[index!])
102+
/// // Prints "Evarts"
103+
///
104+
/// - Parameter bounds: A range of the collection's indices. The bounds of
105+
/// the range must be valid indices of the collection.
106+
subscript(bounds: Range<Index>) -> SubSequence { get }
84107
}
85108

86109
/// Supply the default "slicing" `subscript` for `RandomAccessCollection`

0 commit comments

Comments
 (0)