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

Add stream::Chain trait #62

Open
4 of 5 tasks
yoshuawuyts opened this issue Nov 13, 2022 · 0 comments
Open
4 of 5 tasks

Add stream::Chain trait #62

yoshuawuyts opened this issue Nov 13, 2022 · 0 comments
Labels
api design Relates to the user-facing API

Comments

@yoshuawuyts
Copy link
Owner

yoshuawuyts commented Nov 13, 2022

This is a core iteration "order of execution" operation, enabling people to author:

before

// Manual sequential iteration.
for await n in 0..10 { dbg!(n); }
for await n in 11..20 { dbg!(n); }

after

// The same semantics using `chain`.
for await n in ((0..10), (11..20)).chain() {
    dbg!(n)
}

This is particularly useful to do things like "send one last message after EOF".

Design

pub trait Chain {
    /// What's the return type of our stream?
    type Item;

    /// What stream do we return?
    type Stream: Stream<Item = Self::Item>;

    /// Combine multiple streams into a single stream.
    fn chain(self) -> Self::Stream;
}

Tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api design Relates to the user-facing API
Projects
None yet
Development

No branches or pull requests

1 participant