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