Skip to content

Commit 740721a

Browse files
committed
Address Dmitri's comments on #3600
1 parent 0bd4a0a commit 740721a

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

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)