-
Notifications
You must be signed in to change notification settings - Fork 30
Description
One very handy method is
func flatMapLatest<Output>(
_ transform: @Sendable @escaping (Element) async throws -> Output
)
that returns simple output (not AsyncSequence) and cancels previous operation, as new input values are processed.
But unfortunately, it only takes throwing closure parameter. I assume it is due to cancellation mechanics. It implies that if operation could be cancelled, it should throw cancellation error. And every operation inside flatMap
could be cancelled.
But closure could signal its cancellation by various means, as, for example, returning Result.failure(error).
In that case we are facing unnecessary try-catch boilerplate when reading sequence values. Would be great if we had method overload with non-throwing transform parameter.
It also means, that AsyncJustSequence should be modified, to take 'factory' initialization parameter, just like 'AsyncThrowingJustSequence'. Current init with plain value could be maintained as a convenience init over that.