@@ -1140,7 +1140,6 @@ extension Collection where SubSequence == Slice<Self> {
1140
1140
}
1141
1141
}
1142
1142
1143
- // TODO: swift-3-indexing-model - review the following
1144
1143
extension Collection where SubSequence == Self {
1145
1144
/// Removes and returns the first element of the collection.
1146
1145
///
@@ -1149,6 +1148,7 @@ extension Collection where SubSequence == Self {
1149
1148
///
1150
1149
/// - Complexity: O(1)
1151
1150
public mutating func popFirst( ) -> Iterator . Element ? {
1151
+ // TODO: swift-3-indexing-model - review the following
1152
1152
guard !isEmpty else { return nil }
1153
1153
let element = first!
1154
1154
self = self [ index ( after: startIndex) ..< endIndex]
@@ -1196,21 +1196,22 @@ extension Collection {
1196
1196
var i = makeIterator ( )
1197
1197
return i. next ( )
1198
1198
}
1199
- // TODO: swift-3-indexing-model - uncomment and replace above ready (or should we still use the iterator one?)
1199
+
1200
+ // TODO: swift-3-indexing-model - uncomment and replace above ready (or should we still use the iterator one?)
1200
1201
/// Returns the first element of `self`, or `nil` if `self` is empty.
1201
1202
///
1202
1203
/// - Complexity: O(1)
1203
1204
// public var first: Iterator.Element? {
1204
1205
// return isEmpty ? nil : self[startIndex]
1205
1206
// }
1206
1207
1207
- // TODO: swift-3-indexing-model - review the following
1208
1208
/// A value less than or equal to the number of elements in the collection.
1209
1209
///
1210
1210
/// - Complexity: O(1) if the collection conforms to
1211
1211
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the length
1212
1212
/// of the collection.
1213
1213
public var underestimatedCount : Int {
1214
+ // TODO: swift-3-indexing-model - review the following
1214
1215
return numericCast ( count)
1215
1216
}
1216
1217
@@ -1223,7 +1224,7 @@ extension Collection {
1223
1224
return distance ( from: startIndex, to: endIndex)
1224
1225
}
1225
1226
1226
- // TODO: swift-3-indexing-model - rename the following to _customIndexOfEquatable(element)?
1227
+ // TODO: swift-3-indexing-model - rename the following to _customIndexOfEquatable(element)?
1227
1228
/// Customization point for `Collection.index(of:)`.
1228
1229
///
1229
1230
/// Define this method if the collection can find an element in less than
@@ -1245,7 +1246,6 @@ extension Collection {
1245
1246
//===----------------------------------------------------------------------===//
1246
1247
1247
1248
extension Collection {
1248
- // TODO: swift-3-indexing-model - review the following
1249
1249
/// Returns an array containing the results of mapping the given closure
1250
1250
/// over the sequence's elements.
1251
1251
///
@@ -1266,6 +1266,7 @@ extension Collection {
1266
1266
public func map< T> (
1267
1267
_ transform: @noescape ( Iterator . Element) throws -> T
1268
1268
) rethrows -> [ T ] {
1269
+ // TODO: swift-3-indexing-model - review the following
1269
1270
let count : Int = numericCast ( self . count)
1270
1271
if count == 0 {
1271
1272
return [ ]
@@ -1470,10 +1471,12 @@ extension Collection {
1470
1471
return prefix ( upTo: index ( after: position) )
1471
1472
}
1472
1473
1473
- // TODO: swift-3-indexing-model - review the following
1474
- /// Returns the longest possible subsequences of the sequence, in order, that
1475
- /// don't contain elements satisfying the given predicate. Elements that are
1476
- /// used to split the sequence are not returned as part of any subsequence.
1474
+ /// Returns the longest possible subsequences of the collection, in order,
1475
+ /// that don't contain elements satisfying the given predicate.
1476
+ ///
1477
+ /// The resulting array consists of at most `maxSplits + 1` subsequences.
1478
+ /// Elements that are used to split the sequence are not returned as part of
1479
+ /// any subsequence.
1477
1480
///
1478
1481
/// The following examples show the effects of the `maxSplits` and
1479
1482
/// `omittingEmptySubsequences` parameters when splitting a string using a
@@ -1483,7 +1486,7 @@ extension Collection {
1483
1486
/// let line = "BLANCHE: I don't want realism. I want magic!"
1484
1487
/// print(line.characters.split(isSeparator: { $0 == " " })
1485
1488
/// .map(String.init))
1486
- /// // Prints "["BLANCHE:", "I", "don't", "want", "realism.", "I", "want", "magic!"]"
1489
+ /// // Prints "["BLANCHE:", "I", "don\ 't", "want", "realism.", "I", "want", "magic!"]"
1487
1490
///
1488
1491
/// The second example passes `1` for the `maxSplits` parameter, so the
1489
1492
/// original string is split just once, into two new strings.
@@ -1501,24 +1504,28 @@ extension Collection {
1501
1504
/// // Prints "["BLANCHE:", "", "", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
1502
1505
///
1503
1506
/// - Parameters:
1504
- /// - maxSplits: The maximum number of times to split the sequence, or one
1505
- /// less than the number of subsequences to return. If `maxSplits + 1`
1506
- /// subsequences are returned, the last one is a suffix of the original
1507
- /// sequence containing the remaining elements. `maxSplits` must be
1508
- /// greater than or equal to zero.
1507
+ /// - maxSplits: The maximum number of times to split the collection, or
1508
+ /// one less than the number of subsequences to return. If
1509
+ /// `maxSplits + 1` subsequences are returned, the last one is a suffix
1510
+ /// of the original collection containing the remaining elements.
1511
+ /// `maxSplits` must be greater than or equal to zero. The default value
1512
+ /// is `Int.max`.
1509
1513
/// - omittingEmptySubsequences: If `false`, an empty subsequence is
1510
1514
/// returned in the result for each pair of consecutive elements
1511
1515
/// satisfying the `isSeparator` predicate and for each element at the
1512
- /// start or end of the sequence satisfying the `isSeparator` predicate.
1516
+ /// start or end of the collection satisfying the `isSeparator`
1517
+ /// predicate. The default value is `true`.
1513
1518
/// - isSeparator: A closure that takes an element as an argument and
1514
- /// returns a Boolean value indicating whether the sequence should be
1519
+ /// returns a Boolean value indicating whether the collection should be
1515
1520
/// split at that element.
1516
- /// - Returns: An array of subsequences, split from this sequence's elements.
1521
+ /// - Returns: An array of subsequences, split from this collection's
1522
+ /// elements.
1517
1523
public func split(
1518
1524
maxSplits: Int = Int . max,
1519
1525
omittingEmptySubsequences: Bool = true ,
1520
1526
isSeparator: @noescape ( Iterator . Element) throws -> Bool
1521
1527
) rethrows -> [ SubSequence ] {
1528
+ // TODO: swift-3-indexing-model - review the following
1522
1529
_precondition ( maxSplits >= 0 , " Must take zero or more splits " )
1523
1530
1524
1531
var result : [ SubSequence ] = [ ]
@@ -1560,64 +1567,67 @@ extension Collection {
1560
1567
}
1561
1568
}
1562
1569
1563
- // TODO: swift-3-indexing-model - review the following
1564
1570
extension Collection where Iterator. Element : Equatable {
1565
- /// Returns the longest possible subsequences of the sequence, in order, that
1566
- /// don't contain elements satisfying the given predicate. Elements that are
1567
- /// used to split the sequence are not returned as part of any subsequence.
1571
+ /// Returns the longest possible subsequences of the collection, in order,
1572
+ /// around elements equal to the given element.
1573
+ ///
1574
+ /// The resulting array consists of at most `maxSplits + 1` subsequences.
1575
+ /// Elements that are used to split the collection are not returned as part
1576
+ /// of any subsequence.
1568
1577
///
1569
1578
/// The following examples show the effects of the `maxSplits` and
1570
- /// `omittingEmptySubsequences` parameters when splitting a string using a
1571
- /// closure that matches spaces . The first use of `split` returns each word
1572
- /// that was originally separated by one or more spaces.
1579
+ /// `omittingEmptySubsequences` parameters when splitting a string at each
1580
+ /// space character (" ") . The first use of `split` returns each word that
1581
+ /// was originally separated by one or more spaces.
1573
1582
///
1574
1583
/// let line = "BLANCHE: I don't want realism. I want magic!"
1575
- /// print(line.characters.split(isSeparator: { $0 == " " } )
1584
+ /// print(line.characters.split(separator: " ")
1576
1585
/// .map(String.init))
1577
- /// // Prints "["BLANCHE:", "I", "don't", "want", "realism.", "I", "want", "magic!"]"
1586
+ /// // Prints "["BLANCHE:", "I", "don\ 't", "want", "realism.", "I", "want", "magic!"]"
1578
1587
///
1579
1588
/// The second example passes `1` for the `maxSplits` parameter, so the
1580
1589
/// original string is split just once, into two new strings.
1581
1590
///
1582
- /// print(line.characters.split(maxSplits: 1, isSeparator: { $0 == " " } )
1591
+ /// print(line.characters.split(separator: " ", maxSplits: 1 )
1583
1592
/// .map(String.init))
1584
1593
/// // Prints "["BLANCHE:", " I don\'t want realism. I want magic!"]"
1585
1594
///
1586
1595
/// The final example passes `false` for the `omittingEmptySubsequences`
1587
1596
/// parameter, so the returned array contains empty strings where spaces
1588
1597
/// were repeated.
1589
1598
///
1590
- /// print(line.characters.split(omittingEmptySubsequences: false, isSeparator: { $0 == " " } )
1599
+ /// print(line.characters.split(separator: " ", omittingEmptySubsequences: false )
1591
1600
/// .map(String.init))
1592
1601
/// // Prints "["BLANCHE:", "", "", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
1593
1602
///
1594
1603
/// - Parameters:
1595
- /// - maxSplits: The maximum number of times to split the sequence, or one
1596
- /// less than the number of subsequences to return. If `maxSplits + 1`
1597
- /// subsequences are returned, the last one is a suffix of the original
1598
- /// sequence containing the remaining elements. `maxSplits` must be
1599
- /// greater than or equal to zero.
1604
+ /// - separator: The element that should be split upon.
1605
+ /// - maxSplits: The maximum number of times to split the collection, or
1606
+ /// one less than the number of subsequences to return. If
1607
+ /// `maxSplits + 1` subsequences are returned, the last one is a suffix
1608
+ /// of the original collection containing the remaining elements.
1609
+ /// `maxSplits` must be greater than or equal to zero. The default value
1610
+ /// is `Int.max`.
1600
1611
/// - omittingEmptySubsequences: If `false`, an empty subsequence is
1601
- /// returned in the result for each pair of consecutive elements
1602
- /// satisfying the `isSeparator` predicate and for each element at the
1603
- /// start or end of the sequence satisfying the `isSeparator` predicate.
1604
- /// - isSeparator: A closure that takes an element as an argument and
1605
- /// returns a Boolean value indicating whether the sequence should be
1606
- /// split at that element.
1607
- /// - Returns: An array of subsequences, split from this sequence's elements.
1612
+ /// returned in the result for each consecutive pair of `separator`
1613
+ /// elements in the collection and for each instance of `separator` at
1614
+ /// the start or end of the collection. If `true`, only nonempty
1615
+ /// subsequences are returned. The default value is `true`.
1616
+ /// - Returns: An array of subsequences, split from this collection's
1617
+ /// elements.
1608
1618
public func split(
1609
1619
separator: Iterator . Element ,
1610
1620
maxSplits: Int = Int . max,
1611
1621
omittingEmptySubsequences: Bool = true
1612
1622
) -> [ SubSequence ] {
1613
- return split (
1614
- maxSplits: maxSplits,
1615
- omittingEmptySubsequences: omittingEmptySubsequences,
1616
- isSeparator: { $0 == separator } )
1623
+ // TODO: swift-3-indexing-model - review the following
1624
+ return split (
1625
+ maxSplits: maxSplits,
1626
+ omittingEmptySubsequences: omittingEmptySubsequences,
1627
+ isSeparator: { $0 == separator } )
1617
1628
}
1618
1629
}
1619
1630
1620
- // TODO: swift-3-indexing-model - review the following
1621
1631
extension Collection where SubSequence == Self {
1622
1632
/// Removes and returns the first element of the collection.
1623
1633
///
@@ -1629,6 +1639,7 @@ extension Collection where SubSequence == Self {
1629
1639
/// - SeeAlso: `popFirst()`
1630
1640
@discardableResult
1631
1641
public mutating func removeFirst( ) -> Iterator . Element {
1642
+ // TODO: swift-3-indexing-model - review the following
1632
1643
_precondition ( !isEmpty, " can't remove items from an empty collection " )
1633
1644
let element = first!
1634
1645
self = self [ index ( after: startIndex) ..< endIndex]
0 commit comments