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

Stream filtering facilities #2001

Merged
merged 3 commits into from
Dec 21, 2019
Merged

Stream filtering facilities #2001

merged 3 commits into from
Dec 21, 2019

Conversation

vorot93
Copy link
Member

@vorot93 vorot93 commented Dec 20, 2019

This PR adds StreamExt::filter and StreamExt::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.

tokio/src/stream/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@hawkw hawkw left a 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.

tokio/src/stream/filter.rs Outdated Show resolved Hide resolved
tokio/src/stream/filter_map.rs Outdated Show resolved Hide resolved
/// 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.
Copy link
Member

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?

Copy link
Member

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.

tokio/src/stream/mod.rs Outdated Show resolved Hide resolved
tokio/src/stream/mod.rs Outdated Show resolved Hide resolved
Comment on lines +141 to +142
/// [`Some(item)`](Some) then the stream will yield the value `item`, but if
/// it resolves to [`None`] then the next value will be produced.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these links work?

Copy link
Member Author

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

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@carllerche carllerche merged commit 3b9c7b1 into tokio-rs:master Dec 21, 2019
@vorot93 vorot93 deleted the stream-filter branch December 21, 2019 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants