futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

Should TryStream::try_filter accept closures that return Results?

Open mythmon opened this issue 3 years ago • 0 comments

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.

mythmon avatar Mar 18 '21 21:03 mythmon