-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Stream filtering facilities #2001
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, modulo a couple of nits.
/// will be run against them. If the predicate | ||
/// resolves to `true`, then the stream will yield the value, but if the | ||
/// predicate resolves to `false`, then the value | ||
/// will be discarded and the next value will be produced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's worth highlighting that this differs from futures-rs
's version, in that it takes a synchronous predicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, i think that would add confusion.
/// [`Some(item)`](Some) then the stream will yield the value `item`, but if | ||
/// it resolves to [`None`] then the next value will be produced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these links work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should, see !Unpin here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
This PR adds
StreamExt::filter
andStreamExt::filter_map
which allow filtering and mapping items yielded by the wrapped stream.Unlike the version in #1962 combinators presented here accept synchronous predicates which do immediate check upon receiving items from inner stream. The necessity and design of versions for asynchronous predicate is a subject of a further discussion.