You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/SafeCollectionAccess/Safe Collection Access.swift
+8-6Lines changed: 8 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -176,9 +176,7 @@ public extension BidirectionalCollection {
176
176
177
177
/// Returns the position immediately after the given index, or `nil` if there is none.
178
178
///
179
-
/// The successor of an index must be well defined. For an index `i` into an immutable
180
-
/// collection `c`, calling `c.index(after: i)` returns the same index every
181
-
/// time.
179
+
/// The successor of an index must be well defined. For an index `i` into an immutable collection `c`, calling `c.index(after: i)` returns the same index every time.
182
180
///
183
181
/// - Parameter i: An index of the collection.
184
182
/// - Returns: The index value immediately after `i`, or `nil` if such an index wouldn't be in the collection.
@@ -190,7 +188,8 @@ public extension BidirectionalCollection {
190
188
191
189
/// Replaces the given index with its successor, or `nil` if there is none.
192
190
///
193
-
/// `i` is set to `nil` if the resulting index wouldn't be in the collection.
191
+
/// If you pass `nil` for `i`, this returns immediately because there's nothing after nothing.
192
+
/// If the resulting index wouldn't be in the collection, then `i` is set to `nil`.
194
193
///
195
194
/// - Parameter i: An index of the collection.
196
195
func formIndexOrNil(after i:inoutIndex?){
@@ -211,7 +210,8 @@ public extension BidirectionalCollection {
211
210
212
211
/// Replaces the given index with its predecessor, or `nil` if there is none.
213
212
///
214
-
/// `i` is set to `nil` if the resulting index wouldn't be in the collection.
213
+
/// If you pass `nil` for `i`, this returns immediately because there's nothing before nothing.
214
+
/// If the resulting index wouldn't be in the collection, then `i` is set to `nil`.
215
215
///
216
216
/// - Parameter i: An index of the collection.
217
217
func formIndexOrNil(before i:inoutIndex?){
@@ -224,7 +224,9 @@ public extension BidirectionalCollection {
224
224
///
225
225
/// - Parameters:
226
226
/// - i: A valid index of the collection.
227
-
/// - distance: The distance to offset `i`. `distance` must not be negative unless the collection conforms to the `BidirectionalCollection` protocol.
227
+
/// - distance: The distance to offset `i`.
228
+
/// `distance` may be negative.
229
+
///
228
230
/// - Returns: An index offset by `distance` from the index `i`.
229
231
/// If `distance` is positive, this is the same value as the result of `distance` calls to `index(after:)`.
230
232
/// If `distance` is negative, this is the same value as the result of `abs(distance)` calls to `index(before:)`.
0 commit comments