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

[FEATURE] more combinators #184

Open
Niedzwiedzw opened this issue Apr 29, 2024 · 6 comments
Open

[FEATURE] more combinators #184

Niedzwiedzw opened this issue Apr 29, 2024 · 6 comments

Comments

@Niedzwiedzw
Copy link

Niedzwiedzw commented Apr 29, 2024

futures-util StreamExt and TryStreamExt provide bunch of very useful (addictive?) combinators. I wonder if introducing something like that would be accepted as a PR for this project.

@yoshuawuyts
Copy link
Owner

@Niedzwiedzw it depends – which combinators did you have in mind?

@Niedzwiedzw
Copy link
Author

Niedzwiedzw commented May 1, 2024

I heavily depend on stuff like .filter_map() .try_filter_map() .flat_map() .scan() .chain() .flatten() .try_flatten() .try_for_each() etc :) those are the ones that come to mind at least

@failable
Copy link

For me, that's a big missing part.

@nanoqsh
Copy link

nanoqsh commented Aug 20, 2024

@Niedzwiedzw @failable
I think the point of futures_concurrency crate is to provide combinators for concurrency and for other things are other crates with stream combinators like futures or futures_lite. They fit together perfectly, so far they don't have any conflicts and I hope there won't be any:

use {
    futures_concurrency::stream::StreamExt as _,
    futures_lite::{stream, StreamExt as _},
};

let a = stream::iter([1, 2, 3]);
let b = stream::iter([4, 5, 6]);
a
    .merge(b)
//   ^^^^^ merge from futures_concurrency
    .filter(|i| i % 2 == 0)
//   ^^^^^^ filter from futures_lite
    .for_each(|i| println!("{i}"))
    .await;

In my opinion, there is no need to overload the crate in any additionals.

But I wonder is it possible to use ConcurrentStream as a stream and use all this combinators on it?

@tyilo
Copy link
Contributor

tyilo commented Sep 23, 2024

@nanoqsh I don't know if this issue refers to StreamExt or ConcurrentStream, but I think it would make sense to add more functions to ConcurrentStream, which take an async function instead of futures::StreamExt where they take a normal function.

So that you can do .filter(|i| async { i % 2 == 0 }).for_each(|i| async { println!("{i}") }) (for_each already exists on ConcurrentStream, but filter does not).

@Niedzwiedzw
Copy link
Author

Niedzwiedzw commented Sep 23, 2024

could even be a separate extension trait, like futures-util does

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

5 participants