Skip to content

[FEATURE REQUEST] Non-throwing flatMapLatest #45

@NickSudibor

Description

@NickSudibor

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions