The proposal rules out passing issues as inout like this:
However, in order to suppress an issue, the parameter would also need to become optional (
inout Issue?
) and this would mean that all usages would first need to be unwrapped. This feels non-ergonomic, and would differ from the standard library's typical pattern forcompactMap
functions.
But this is not the only option. We could make the closure return Void?
instead and have the parameter remain inout Issue
. With this change, all the sample code from the proposal would remain the same, save for the shadowing of the parameter:
@Test(.compactMapIssues { issue in
- var issue = issue
issue.comments.append("Checking whether two literals are equal")
- return issue
})
Importantly, you can still return nil to filter out issues:
@Test(.compactMapIssues { issue in
guard !SensitiveTerms.all.contains(where: { description.contains($0) }) else {
return nil
}
issue.comments.append("Not sensitive")
})
With this change I could also see one of the simpler names like transformIssues
or handleIssues
making a comeback.