Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analogue of .last() method #2822

Open
xamgore opened this issue Jan 9, 2024 · 0 comments
Open

Analogue of .last() method #2822

xamgore opened this issue Jan 9, 2024 · 0 comments
Labels
A-stream Area: futures::stream C-feature-request

Comments

@xamgore
Copy link

xamgore commented Jan 9, 2024

I'd like to run FuturesOrdered::from_iter(...) and retrieve the result of the last element, which is Option<...>. The same function exists in std.

It can be implemented with

iter.fold(None, |_acc, x| async move { Some(x) })

But try_last would require extra checks: if there is an intermediate error, return it. If not, return the last successful Ok(...).

@taiki-e taiki-e added C-feature-request A-stream Area: futures::stream labels Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stream Area: futures::stream C-feature-request
Projects
None yet
Development

No branches or pull requests

2 participants