Skip to content

Commit ebb25cc

Browse files
authored
Merge pull request #4346 from CodaFi/post-fix-the-prefix-postfix-prefixed-patch
2 parents fc001e9 + 3814b7a commit ebb25cc

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ Note: This is in reverse chronological order, so newer entries are added to the
33
Swift 3.0
44
---------
55

6+
* [SE-0045](https://github.com/apple/swift-evolution/blob/master/proposals/0045-scan-takewhile-dropwhile.md)
7+
8+
The `Sequence` protocol now includes two new members, `take(while:)` and
9+
`drop(while:)`. `take(while:)` is used to request the longest subsequence
10+
satisfying a predicate. `drop(while:)` is used to request the subsequence
11+
remaining after dropping the longest subsequence satisfying a predicate.
12+
613
* [SE-0136](https://github.com/apple/swift-evolution/blob/master/proposals/0136-memory-layout-of-values.md) and [SE-0101](https://github.com/apple/swift-evolution/blob/master/proposals/0101-standardizing-sizeof-naming.md)
714

815
The functions `sizeof()`, `strideof()`, and `alignof()` have been removed.

stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public struct ${Self}<
266266
}
267267

268268
public func drop(
269-
while predicate: @noescape (Base.Iterator.Element) throws -> Bool
269+
while predicate: (Base.Iterator.Element) throws -> Bool
270270
) rethrows -> SubSequence {
271271
Log.dropWhile[selfType] += 1
272272
return try base.drop(while: predicate)
@@ -278,7 +278,7 @@ public struct ${Self}<
278278
}
279279

280280
public func prefix(
281-
while predicate: @noescape (Base.Iterator.Element) throws -> Bool
281+
while predicate: (Base.Iterator.Element) throws -> Bool
282282
) rethrows -> SubSequence {
283283
Log.prefixWhile[selfType] += 1
284284
return try base.prefix(while: predicate)

stdlib/public/core/Collection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ extension Collection {
13301330
///
13311331
/// - Complexity: O(*n*), where *n* is the length of the collection.
13321332
public func drop(
1333-
while predicate: @noescape (Iterator.Element) throws -> Bool
1333+
while predicate: (Iterator.Element) throws -> Bool
13341334
) rethrows -> SubSequence {
13351335
var start = startIndex
13361336
while try start != endIndex && predicate(self[start]) {
@@ -1374,7 +1374,7 @@ extension Collection {
13741374
///
13751375
/// - Complexity: O(*n*), where *n* is the length of the collection.
13761376
public func prefix(
1377-
while predicate: @noescape (Iterator.Element) throws -> Bool
1377+
while predicate: (Iterator.Element) throws -> Bool
13781378
) rethrows -> SubSequence {
13791379
var end = startIndex
13801380
while try end != endIndex && predicate(self[end]) {

stdlib/public/core/Sequence.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,14 @@ internal class _PrefixSequence<Base : IteratorProtocol>
721721
maxLength: Swift.min(maxLength, self._maxLength),
722722
taken: _taken))
723723
}
724+
725+
internal func drop(
726+
while predicate: (Base.Element) throws -> Bool
727+
) rethrows -> AnySequence<Base.Element> {
728+
return try AnySequence(
729+
_DropWhileSequence(
730+
iterator: _iterator, nextElement: nil, predicate: predicate))
731+
}
724732
}
725733

726734
/// A sequence that lazily consumes and drops `n` elements from an underlying
@@ -1253,8 +1261,8 @@ extension Sequence where
12531261
///
12541262
/// - Parameter predicate: A closure that takes an element of the
12551263
/// sequence as its argument and returns `true` if the element should
1256-
/// be included or `false` if it should be excluded. Once the predicate
1257-
/// returns `false` it will not be called again.
1264+
/// be included or `false` if it should be excluded. Once the predicate
1265+
/// returns `false` it will not be called again.
12581266
///
12591267
/// - Complexity: O(*n*), where *n* is the length of the collection.
12601268
public func prefix(

validation-test/stdlib/Lazy.swift.gyb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,16 +1295,6 @@ let prefixDropWhileTests: [(data: [Int], value: Int, pivot: Int)] = [
12951295
([0, 10, 20, 30, 40], 40, 4),
12961296
([0, 10, 20, 30, 40], 99, 5) ]
12971297

1298-
tests.test("LazyPrefixWhileIterator") {
1299-
let base = (1...10).lazy.prefix(while: { $0 < 4 })
1300-
1301-
var iter1 = base.makeIterator()
1302-
expectEqual(1, iter1.next())
1303-
expectEqual(2, iter1.next())
1304-
expectEqual(3, iter1.next())
1305-
expectEqual(nil, iter1.next())
1306-
}
1307-
13081298
% for Kind in 'Sequence', 'Forward', 'Bidirectional':
13091299
% Self = 'Sequence' if Kind == 'Sequence' else collectionForTraversal(Kind)
13101300
% checkKind = 'ForwardCollection' if Kind == 'Forward' else Self
@@ -1365,16 +1355,6 @@ tests.test("LazyPrefixWhileBidirectionalCollection/AssociatedTypes") {
13651355

13661356
//===--- LazyDropWhile ----------------------------------------------------===//
13671357

1368-
tests.test("LazyDropWhileIterator") {
1369-
let base = (1...10).lazy.drop(while: { $0 < 4 })
1370-
1371-
var iter1 = base.makeIterator()
1372-
expectEqual(4, iter1.next())
1373-
expectEqual(5, iter1.next())
1374-
expectEqual(6, iter1.next())
1375-
expectEqual(7, iter1.next())
1376-
}
1377-
13781358
% for Kind in 'Sequence', 'Forward', 'Bidirectional':
13791359
% Self = 'Sequence' if Kind == 'Sequence' else collectionForTraversal(Kind)
13801360
% checkKind = 'ForwardCollection' if Kind == 'Forward' else Self

0 commit comments

Comments
 (0)