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

Unnecesary trait bound on FlatMap? #649

Open
kiljacken opened this issue Dec 27, 2019 · 1 comment
Open

Unnecesary trait bound on FlatMap? #649

kiljacken opened this issue Dec 27, 2019 · 1 comment

Comments

@kiljacken
Copy link

kiljacken commented Dec 27, 2019

While working on a toy piece of code, I ended up with something that I've boiled down to the following example:

async fn test() {
    use async_std::{stream, prelude::*};
    let res = stream::from_iter(vec!['a', 'b', 'c'])
        .flat_map(|item| stream::from_iter(vec![1, 2, 3]))
        .flat_map(|item| stream::from_iter(vec![4, 5, 6]))
        .for_each(|item| ());
    res.await;
}

This does not work however, as the second invocation of flat_map can not be found on the stream produced by the first invocation. Upon looking at the source, the following bound on FlatMap seems unnecessary and seems to be causing the issue.

The bound S::Item: IntoStream<IntoStream = U, Item = U::Item> states that for a given FlatMap<S, U, F> to be a stream, each item from the original stream S must be convertible to a stream U that produces the output type. This does not seem to be neccesary however, as this is the transformation the provided closure/function F: FnMut(S::Item) -> U performs.

I hope the above makes sense, and please do point me in the right direction if I'm just doing something horribly wrong.

@k-nasa
Copy link
Member

k-nasa commented Dec 29, 2019

@kiljacken You are right!

I submitted a PR to solve this.

Thanks for this issue.

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

No branches or pull requests

2 participants