I would like to extend AsyncSequence in ways that depend on whether the sequence can throw. Neither AsyncSequence nor AsyncIteratorProtocol distinguish such sequences explicitly. Yet, the concurrency module does come with concrete sequences with throwing and non-throwing variants. The only generic difference I see is that the next method of non-throwing sequences are rethrowing. Here is an example:
extension AsyncMapSequence : AsyncSequence {
struct Iterator : AsyncIteratorProtocol {
mutating func next() async rethrows -> Transformed?
}
}
Whereas the throwing variant is a plain throws:
extension AsyncThrowingMapSequence : AsyncSequence {
struct Iterator : AsyncIteratorProtocol {
mutating func next() async throws -> Transformed?
}
}
(I am not even sure how rethrows is even possible for a method that does not take any arguments. The only thing that comes to mind is that the curried expression of such a method could throw some light on that...)
So, the question is how to express something along the lines of:
extension AsyncSequence where AsyncIterator /* is not throwing */ {
}
When this proposal is fully implemented you will be able to express conformance to a failable sequence by providing some syntax sugar
extension AsyncSequence where nothrow AsyncIterator {
or
struct Foo<S: nothrow AsyncSequence>
This comes from the @rethrows annotation currently attached to AsyncSequence
@rethrows public protocol AsyncSequence