Skip to content

Commit 5ed80de

Browse files
authored
Use pack iteration (#494)
1 parent ef3a6f1 commit 5ed80de

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed
+4-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11

22
@_spi(Internal)
33
public func areEqual<each Element: Equatable>(_ lhs: (repeat each Element), _ rhs: (repeat each Element)) -> Bool {
4-
5-
// https://github.com/apple/swift-evolution/blob/main/proposals/0408-pack-iteration.md
6-
7-
func isEqual<T: Equatable>(_ left: T, _ right: T) throws {
8-
if left == right {
9-
return
10-
}
11-
12-
throw NotEqual()
4+
5+
for (left, right) in repeat (each lhs, each rhs) {
6+
guard left == right else { return false }
137
}
14-
15-
do {
16-
repeat try isEqual(each lhs, each rhs)
17-
} catch {
18-
return false
19-
}
20-
218
return true
9+
2210
}
2311

Sources/VergeComparator/TypedComparator.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ extension TypedComparator {
4242
*/
4343
public static func equality<each T: Equatable>() -> Self where Self == AnyEqualityComparator<(repeat each T)> {
4444
return .init { a, b in
45-
areEqual((repeat each a), (repeat each b))
45+
46+
for (left, right) in repeat (each a, each b) {
47+
guard left == right else { return false }
48+
}
49+
return true
50+
4651
}
4752
}
4853

0 commit comments

Comments
 (0)