Skip to content

Commit f2e1707

Browse files
committed
Make forEach and map on SKDResponseArray rethrowing
1 parent d5b06c8 commit f2e1707

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Sources/SourceKitD/SKDResponseArray.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public final class SKDResponseArray {
3535

3636
/// If the `applier` returns `false`, iteration terminates.
3737
@discardableResult
38-
public func forEach(_ applier: (Int, SKDResponseDictionary) -> Bool) -> Bool {
38+
public func forEach(_ applier: (Int, SKDResponseDictionary) throws -> Bool) rethrows -> Bool {
3939
for i in 0..<count {
40-
if !applier(i, SKDResponseDictionary(sourcekitd.api.variant_array_get_value(array, i), response: resp)) {
40+
if try !applier(i, SKDResponseDictionary(sourcekitd.api.variant_array_get_value(array, i), response: resp)) {
4141
return false
4242
}
4343
}
@@ -46,29 +46,29 @@ public final class SKDResponseArray {
4646

4747
/// If the `applier` returns `false`, iteration terminates.
4848
@discardableResult
49-
public func forEachUID(_ applier: (Int, sourcekitd_uid_t) -> Bool) -> Bool {
49+
public func forEachUID(_ applier: (Int, sourcekitd_uid_t) throws -> Bool) rethrows -> Bool {
5050
for i in 0..<count {
51-
if let uid = sourcekitd.api.variant_array_get_uid(array, i), !applier(i, uid) {
51+
if let uid = sourcekitd.api.variant_array_get_uid(array, i), try !applier(i, uid) {
5252
return false
5353
}
5454
}
5555
return true
5656
}
5757

58-
public func map<T>(_ transform: (SKDResponseDictionary) -> T) -> [T] {
58+
public func map<T>(_ transform: (SKDResponseDictionary) throws -> T) rethrows -> [T] {
5959
var result: [T] = []
6060
result.reserveCapacity(self.count)
61-
self.forEach { _, element in
62-
result.append(transform(element))
61+
try self.forEach { _, element in
62+
result.append(try transform(element))
6363
return true
6464
}
6565
return result
6666
}
6767

68-
public func compactMap<T>(_ transform: (SKDResponseDictionary) -> T?) -> [T] {
68+
public func compactMap<T>(_ transform: (SKDResponseDictionary) throws -> T?) rethrows -> [T] {
6969
var result: [T] = []
70-
self.forEach { _, element in
71-
if let transformed = transform(element) {
70+
try self.forEach { _, element in
71+
if let transformed = try transform(element) {
7272
result.append(transformed)
7373
}
7474
return true

0 commit comments

Comments
 (0)