diff --git a/src/stream/stream_ext.rs b/src/stream/stream_ext.rs index fcf25fb..3321735 100644 --- a/src/stream/stream_ext.rs +++ b/src/stream/stream_ext.rs @@ -1,7 +1,7 @@ use crate::stream::{IntoStream, Merge}; use futures_core::Stream; -use super::merge::tuple::Merge2; +use super::{chain::tuple::Chain2, merge::tuple::Merge2, zip::tuple::Zip2, Chain, Zip}; /// An extension trait for the `Stream` trait. pub trait StreamExt: Stream { @@ -10,6 +10,18 @@ pub trait StreamExt: Stream { where Self: Stream + Sized, S2: IntoStream; + + /// Takes two streams and creates a new stream over all in sequence + fn chain(self, other: S2) -> Chain2 + where + Self: Stream + Sized, + S2: IntoStream; + + /// ‘Zips up’ multiple streams into a single stream of pairs. + fn zip(self, other: S2) -> Zip2 + where + Self: Stream + Sized, + S2: IntoStream; } impl StreamExt for S1 @@ -23,4 +35,22 @@ where { Merge::merge((self, other)) } + + fn chain(self, other: S2) -> Chain2 + where + Self: Stream + Sized, + S2: IntoStream, + { + // TODO(yosh): fix the bounds on the tuple impl + Chain::chain((self, other.into_stream())) + } + + fn zip(self, other: S2) -> Zip2 + where + Self: Stream + Sized, + S2: IntoStream, + { + // TODO(yosh): fix the bounds on the tuple impl + Zip::zip((self, other.into_stream())) + } }