Oh yes, that's problematic indeed. That made me wonder if instead of limiting the API to the Failure
type of self
, it would be possible to do a type conversion on failure types as well; so instead of the proposed new map(_:)
API
extension AsyncSequence {
public func map<Transformed>(
_ transform: @Sendable @escaping (Element) async throws(Failure) -> Transformed
) -> some AsyncSequence<ElementOfResult, Failure>
}
we could get back
) -> some AsyncSequence<Transformed, errorUnion(Failure, NewFailure)>
I'm not sure if the errorUnion(e1, e2, ..., EN)
type function introduced by SE-0413 was actually meant to be usable in type expressions, but here it would be useful IMO[1].
Can't disagree on that either!
As I understood it, the semantics of
errorUnion
were meant to be:
(1)errorUnion(E, E) = E
(2)errorUnion(E, Never) = E
(3)errorUnion(E1, E2) = any Error
whereE1 != E2
↩︎