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

adds stream::fold combinator #180

Merged
merged 5 commits into from
Sep 17, 2019
Merged

adds stream::fold combinator #180

merged 5 commits into from
Sep 17, 2019

Conversation

montekki
Copy link
Member

Fold. Kind of clumsy around the part with the option and moving out of the shared context.


Stdlib: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.fold
Ref: #129

Copy link
Contributor

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

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

LGTM -- going to leave it to @stjepang for the final review. We're two weeks out from needing to stabilize our full API so this might be held up for a little bit.

@montekki
Copy link
Member Author

there is no aim at implementing all combinators in Stream before that, right?

@yoshuawuyts
Copy link
Contributor

there is no aim at implementing all combinators in Stream before that, right?

I think you've been doing fantastic work, and would be saddened to stop these PRs from going through. Though making sure we feel confident in what we stabilize is really important.

Perhaps a middle ground would be to start adding unstable markers to new streams combinators. The way to do that is to add the following above each methods / struct:

#[cfg_attr(feature = "docs", doc(cfg(unstable)))]

This way we can keep working on porting over the full API surface, but without needing to worry it needs to be stable for the 1.0 release (and importantly: not adding additional API surface for @stjepang to review in the next two weeks).

@stjepang How do you feel about this? Do you think this could work?


impl<S, F, B> Future for FoldFuture<S, F, S::Item, B>
where
S: Stream + Unpin + Sized,
Copy link

Choose a reason for hiding this comment

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

I think we don't need Unpin here.


match next {
Some(v) => {
cx.waker().wake_by_ref();
Copy link

Choose a reason for hiding this comment

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

Instead of waking ourselves on every step, let's turn this into a loop instead and implement poll() like here:

https://github.com/rust-lang-nursery/futures-rs/blob/master/futures-util/src/stream/fold.rs

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Thanks! :)

@ghost
Copy link

ghost commented Sep 17, 2019

bors r+

bors bot added a commit that referenced this pull request Sep 17, 2019
180: adds stream::fold combinator r=stjepang a=montekki

Fold. Kind of clumsy around the part with the option and moving out of the shared context.
___
Stdlib: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.fold
Ref: #129 

Co-authored-by: Fedor Sakharov <fedor.sakharov@gmail.com>
@bors
Copy link
Contributor

bors bot commented Sep 17, 2019

Build succeeded

  • continuous-integration/travis-ci/push

@bors bors bot merged commit efe3516 into async-rs:master Sep 17, 2019
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

2 participants