File tree Expand file tree Collapse file tree 1 file changed +5
-15
lines changed Expand file tree Collapse file tree 1 file changed +5
-15
lines changed Original file line number Diff line number Diff line change @@ -943,12 +943,6 @@ extension Sequence {
943
943
}
944
944
}
945
945
946
- @usableFromInline
947
- @_frozen
948
- internal enum _StopIteration : Error {
949
- case stop
950
- }
951
-
952
946
extension Sequence {
953
947
/// Returns the first element of the sequence that satisfies the given
954
948
/// predicate.
@@ -971,16 +965,12 @@ extension Sequence {
971
965
public func first(
972
966
where predicate: ( Element ) throws -> Bool
973
967
) rethrows -> Element ? {
974
- var foundElement : Element ?
975
- do {
976
- try self . forEach {
977
- if try predicate ( $0) {
978
- foundElement = $0
979
- throw _StopIteration. stop
980
- }
968
+ for element in self {
969
+ if try predicate ( element) {
970
+ return element
981
971
}
982
- } catch is _StopIteration { }
983
- return foundElement
972
+ }
973
+ return nil
984
974
}
985
975
}
986
976
You can’t perform that action at this time.
0 commit comments