Skip to content

Commit 20b72e4

Browse files
gribozavrMax Moiseev
authored andcommitted
stdlib: make 'Sequence.first(where:)' a pure protocol extension (no dynamic dispatch)
SE-0032 did not propose a protocol entry point, only a protocol extension. Using a pure protocol extension is the right choice here because a concrete sequence can't provide a more efficient implementation of this method than the default one.
1 parent 457055d commit 20b72e4

File tree

3 files changed

+1
-29
lines changed

3 files changed

+1
-29
lines changed

stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public class SequenceLog {
8282
public static var map = TypeIndexed(0)
8383
public static var filter = TypeIndexed(0)
8484
public static var forEach = TypeIndexed(0)
85-
public static var first = TypeIndexed(0)
8685
public static var dropFirst = TypeIndexed(0)
8786
public static var dropLast = TypeIndexed(0)
8887
public static var prefixMaxLength = TypeIndexed(0)
@@ -115,6 +114,7 @@ public class CollectionLog : SequenceLog {
115114
public static var isEmpty = TypeIndexed(0)
116115
public static var count = TypeIndexed(0)
117116
public static var _customIndexOfEquatableElement = TypeIndexed(0)
117+
public static var first = TypeIndexed(0)
118118
public static var advance = TypeIndexed(0)
119119
public static var advanceLimit = TypeIndexed(0)
120120
public static var distance = TypeIndexed(0)
@@ -243,13 +243,6 @@ public struct ${Self}<
243243
Log.forEach[selfType] += 1
244244
try base.forEach(body)
245245
}
246-
247-
public func first(
248-
where predicate: (Base.Iterator.Element) throws -> Bool
249-
) rethrows -> Base.Iterator.Element? {
250-
Log.first[selfType] += 1
251-
return try base.first(where: predicate)
252-
}
253246

254247
public typealias SubSequence = Base.SubSequence
255248

stdlib/public/core/Sequence.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,6 @@ public protocol Sequence {
566566
whereSeparator isSeparator: (Iterator.Element) throws -> Bool
567567
) rethrows -> [SubSequence]
568568

569-
/// Returns the first element of the sequence that satisfies the given
570-
/// predicate or nil if no such element is found.
571-
///
572-
/// - Parameter predicate: A closure that takes an element of the
573-
/// sequence as its argument and returns a Boolean value indicating
574-
/// whether the element is a match.
575-
/// - Returns: The first match or `nil` if there was no match.
576-
func first(
577-
where predicate: (Iterator.Element) throws -> Bool
578-
) rethrows -> Iterator.Element?
579-
580569
func _customContainsEquatableElement(
581570
_ element: Iterator.Element
582571
) -> Bool?

validation-test/stdlib/SequenceType.swift.gyb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -941,16 +941,6 @@ SequenceTypeTests.test("forEach/dispatch") {
941941
expectCustomizable(tester, tester.log.forEach)
942942
}
943943

944-
//===----------------------------------------------------------------------===//
945-
// first()
946-
//===----------------------------------------------------------------------===//
947-
948-
SequenceTypeTests.test("first/dispatch") {
949-
let tester = SequenceLog.dispatchTester([OpaqueValue(1)])
950-
_ = tester.first { $0.value == 1 }
951-
expectCustomizable(tester, tester.log.first)
952-
}
953-
954944
//===----------------------------------------------------------------------===//
955945
// dropFirst()
956946
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)