@@ -188,9 +188,6 @@ public protocol Indexable : IndexableBase {
188
188
/// to `index(before:)`.
189
189
///
190
190
/// - SeeAlso: `index(_:offsetBy:limitedBy:)`, `formIndex(_:offsetBy:)`
191
- /// - Precondition:
192
- /// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)`
193
- /// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)`
194
191
/// - Complexity: O(1) if the collection conforms to
195
192
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the absolute
196
193
/// value of `n`.
@@ -234,9 +231,6 @@ public protocol Indexable : IndexableBase {
234
231
/// the method returns `nil`.
235
232
///
236
233
/// - SeeAlso: `index(_:offsetBy:)`, `formIndex(_:offsetBy:limitedBy:)`
237
- /// - Precondition:
238
- /// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)`
239
- /// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)`
240
234
/// - Complexity: O(1) if the collection conforms to
241
235
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the absolute
242
236
/// value of `n`.
@@ -256,9 +250,6 @@ public protocol Indexable : IndexableBase {
256
250
/// collection conforms to the `BidirectionalCollection` protocol.
257
251
///
258
252
/// - SeeAlso: `index(_:offsetBy:)`, `formIndex(_:offsetBy:limitedBy:)`
259
- /// - Precondition:
260
- /// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)`
261
- /// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)`
262
253
/// - Complexity: O(1) if the collection conforms to
263
254
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the absolute
264
255
/// value of `n`.
@@ -412,18 +403,18 @@ public struct IndexingIterator<
412
403
/// A sequence whose elements can be traversed multiple times,
413
404
/// nondestructively, and accessed by indexed subscript.
414
405
///
415
- /// Collections are used extensively throughout the standard library. When
416
- /// you use arrays, dictionaries, views of a string's contents and other
417
- /// types, you benefit from the operations that the `Collection` protocol
418
- /// declares and implements.
406
+ /// Collections are used extensively throughout the standard library. When you
407
+ /// use arrays, dictionaries, views of a string's contents and other types,
408
+ /// you benefit from the operations that the `Collection` protocol declares
409
+ /// and implements.
419
410
///
420
411
/// In addition to the methods that collections inherit from the `Sequence`
421
412
/// protocol, you gain access to methods that depend on accessing an element
422
413
/// at a specific position when using a collection.
423
414
///
424
- /// For example, if you want to print only the first word in a string,
425
- /// search for the index of the first space, and then create a subsequence up
426
- /// to that position.
415
+ /// For example, if you want to print only the first word in a string, search
416
+ /// for the index of the first space and then create a subsequence up to that
417
+ /// position.
427
418
///
428
419
/// let text = "Buffalo buffalo buffalo buffalo."
429
420
/// if let firstSpace = text.characters.index(of: " ") {
@@ -464,24 +455,24 @@ public struct IndexingIterator<
464
455
/// print(firstChar)
465
456
/// // Prints "B"
466
457
///
467
- /// The `Collection` protocol declares and provides default implementations
468
- /// for many operations that depend on elements being accessible by their
469
- /// subscript. For example, you can also access the first character of
470
- /// `text` using the `first` property, which has the value of the first
471
- /// element of the collection, or `nil` if the collection is empty.
458
+ /// The `Collection` protocol declares and provides default implementations for
459
+ /// many operations that depend on elements being accessible by their
460
+ /// subscript. For example, you can also access the first character of `text`
461
+ /// using the `first` property, which has the value of the first element of
462
+ /// the collection, or `nil` if the collection is empty.
472
463
///
473
464
/// print(text.characters.first)
474
465
/// // Prints "Optional("B")"
475
466
///
476
- /// Traversing a Collection
467
+ /// Traversing a Collection
477
468
/// =======================
478
469
///
479
- /// While a sequence may be consumed as it is traversed, a collection is
480
- /// guaranteed to be multi-pass : Any element may be repeatedly accessed by
481
- /// saving its index. Moreover, a collection's indices form a finite range
482
- /// of the positions of the collection's elements. This guarantees the
483
- /// safety of operations that depend on a sequence being finite, such as
484
- /// checking to see whether a collection contains an element.
470
+ /// Although a sequence can be consumed as it is traversed, a collection is
471
+ /// guaranteed to be multipass : Any element may be repeatedly accessed by
472
+ /// saving its index. Moreover, a collection's indices form a finite range of
473
+ /// the positions of the collection's elements. This guarantees the safety of
474
+ /// operations that depend on a sequence being finite, such as checking to see
475
+ /// whether a collection contains an element.
485
476
///
486
477
/// Iterating over the elements of a collection by their positions yields the
487
478
/// same elements in the same order as iterating over that collection using
@@ -498,7 +489,7 @@ public struct IndexingIterator<
498
489
/// // Prints "i"
499
490
/// // Prints "f"
500
491
/// // Prints "t"
501
- ///
492
+ ///
502
493
/// for i in word.characters.indices {
503
494
/// print(word.characters[i])
504
495
/// }
@@ -508,26 +499,28 @@ public struct IndexingIterator<
508
499
/// // Prints "f"
509
500
/// // Prints "t"
510
501
///
511
- /// Conforming to the Collection Protocol
502
+ /// Conforming to the Collection Protocol
512
503
/// =====================================
513
504
///
514
505
/// If you create a custom sequence that can provide repeated access to its
515
- /// elements, conformance to the `Collection` protocol gives your custom type
516
- /// a more useful and more efficient interface for sequence and collection
517
- /// operations. To add `Collection` conformance to your type, declare
518
- /// `startIndex` and `endIndex` properties, a subscript that provides at least
519
- /// read-only access to your type's elements, and the `index(after:)` method
520
- /// for advancing your collection's indices.
506
+ /// elements, make sure that its type conforms to the `Collection` protocol in
507
+ /// order to give a more useful and more efficient interface for sequence and
508
+ /// collection operations. To add `Collection` conformance to your type, you
509
+ /// must declare at least the four following requirements:
510
+ ///
511
+ /// - the `startIndex` and `endIndex` properties,
512
+ /// - a subscript that provides at least read-only access to your type's
513
+ /// elements, and
514
+ /// - the `index(after:)` method for advancing an index into your collection.
521
515
///
522
516
/// Expected Performance
523
517
/// ====================
524
518
///
525
- /// Types that conform to `Collection` are expected to provide the
526
- /// `startIndex` and `endIndex` properties and subscript access to elements
527
- /// as O(1) operations. Types that are not able to guarantee that expected
528
- /// performance must document the departure, because many collection operations
529
- /// depend on O(1) subscripting performance for their own performance
530
- /// guarantees.
519
+ /// Types that conform to `Collection` are expected to provide the `startIndex`
520
+ /// and `endIndex` properties and subscript access to elements as O(1)
521
+ /// operations. Types that are not able to guarantee that expected performance
522
+ /// must document the departure, because many collection operations depend on
523
+ /// O(1) subscripting performance for their own performance guarantees.
531
524
///
532
525
/// The performance of some collection operations depends on the type of index
533
526
/// that the collection provides. For example, a random-access collection,
@@ -696,7 +689,6 @@ public protocol Collection : Indexable, Sequence {
696
689
/// `start` must be a valid index of the collection.
697
690
/// - Returns: A subsequence starting at the `start` position.
698
691
///
699
- /// - Precondition: `start >= self.startIndex && start <= self.endIndex`
700
692
/// - Complexity: O(1)
701
693
func suffix( from start: Index ) -> SubSequence
702
694
@@ -790,9 +782,6 @@ public protocol Collection : Indexable, Sequence {
790
782
/// to `index(before:)`.
791
783
///
792
784
/// - SeeAlso: `index(_:offsetBy:limitedBy:)`, `formIndex(_:offsetBy:)`
793
- /// - Precondition:
794
- /// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)`
795
- /// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)`
796
785
/// - Complexity: O(1) if the collection conforms to
797
786
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the absolute
798
787
/// value of `n`.
@@ -836,9 +825,6 @@ public protocol Collection : Indexable, Sequence {
836
825
/// the method returns `nil`.
837
826
///
838
827
/// - SeeAlso: `index(_:offsetBy:)`, `formIndex(_:offsetBy:limitedBy:)`
839
- /// - Precondition:
840
- /// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)`
841
- /// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)`
842
828
/// - Complexity: O(1) if the collection conforms to
843
829
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the absolute
844
830
/// value of `n`.
@@ -856,8 +842,8 @@ public protocol Collection : Indexable, Sequence {
856
842
/// - end: Another valid index of the collection. If `end` is equal to
857
843
/// `start`, the result is zero.
858
844
/// - Returns: The distance between `start` and `end`. The result can be
859
- /// negative only if the collection conforms to the `BidirectionalCollection`
860
- /// protocol.
845
+ /// negative only if the collection conforms to the
846
+ /// `BidirectionalCollection` protocol.
861
847
///
862
848
/// - Complexity: O(1) if the collection conforms to
863
849
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the
@@ -926,9 +912,6 @@ extension Indexable {
926
912
/// to `index(before:)`.
927
913
///
928
914
/// - SeeAlso: `index(_:offsetBy:limitedBy:)`, `formIndex(_:offsetBy:)`
929
- /// - Precondition:
930
- /// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)`
931
- /// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)`
932
915
/// - Complexity: O(1) if the collection conforms to
933
916
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the absolute
934
917
/// value of `n`.
@@ -974,9 +957,6 @@ extension Indexable {
974
957
/// the method returns `nil`.
975
958
///
976
959
/// - SeeAlso: `index(_:offsetBy:)`, `formIndex(_:offsetBy:limitedBy:)`
977
- /// - Precondition:
978
- /// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)`
979
- /// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)`
980
960
/// - Complexity: O(1) if the collection conforms to
981
961
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the absolute
982
962
/// value of `n`.
@@ -998,9 +978,6 @@ extension Indexable {
998
978
/// collection conforms to the `BidirectionalCollection` protocol.
999
979
///
1000
980
/// - SeeAlso: `index(_:offsetBy:)`, `formIndex(_:offsetBy:limitedBy:)`
1001
- /// - Precondition:
1002
- /// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)`
1003
- /// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)`
1004
981
/// - Complexity: O(1) if the collection conforms to
1005
982
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the absolute
1006
983
/// value of `n`.
@@ -1414,7 +1391,6 @@ extension Collection {
1414
1391
/// `end` must be a valid index of the collection.
1415
1392
/// - Returns: A subsequence up to, but not including, the `end` position.
1416
1393
///
1417
- /// - Precondition: `end >= self.startIndex && end <= self.endIndex`
1418
1394
/// - Complexity: O(1)
1419
1395
/// - SeeAlso: `prefix(through:)`
1420
1396
public func prefix( upTo end: Index ) -> SubSequence {
@@ -1442,7 +1418,6 @@ extension Collection {
1442
1418
/// subsequence. `start` must be a valid index of the collection.
1443
1419
/// - Returns: A subsequence starting at the `start` position.
1444
1420
///
1445
- /// - Precondition: `start >= self.startIndex && start <= self.endIndex`
1446
1421
/// - Complexity: O(1)
1447
1422
public func suffix( from start: Index ) -> SubSequence {
1448
1423
return self [ start..< endIndex]
0 commit comments