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

Should TryStream::try_filter accept closures that return Results? #2375

Closed
mythmon opened this issue Mar 18, 2021 · 1 comment
Closed

Should TryStream::try_filter accept closures that return Results? #2375

mythmon opened this issue Mar 18, 2021 · 1 comment
Labels
A-stream Area: futures::stream C-feature-request

Comments

@mythmon
Copy link

mythmon commented Mar 18, 2021

I expected to be able to be able to filter a try stream with a fallible filter function, like this:

try_stream.try_filter(|v| v.fallible_async_operation().await?)

However, try_filter expects the closure passed to return simply a boolean. The try_ in try_filter allows it to skip Errors that are already in the stream. This seems like a gap of useful functionality.

As a work around I've done something like this

try_stream.try_filter_map(|v|
	if v.fallible_async_operation().await? {
		Ok(Some(v))
	} else {
		Ok(None)
	}
)

I would have expected both try_filter and try_filter_map to handle fallible filters.

@taiki-e
Copy link
Member

taiki-e commented Jun 18, 2023

Closing in favor of #2755.

@taiki-e taiki-e closed this as completed Jun 18, 2023
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

3 participants
@mythmon @taiki-e and others