Skip to content

Unnecesary trait bound on FlatMap? #649

Open
@kiljacken

Description

@kiljacken

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions