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