Skip to content

Commit 09b6dfe

Browse files
committed
impl chain,zip on stream ext
1 parent 5418488 commit 09b6dfe

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/stream/stream_ext.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::stream::{IntoStream, Merge};
22
use futures_core::Stream;
33

4-
use super::merge::tuple::Merge2;
4+
use super::{chain::tuple::Chain2, merge::tuple::Merge2, zip::tuple::Zip2, Chain, Zip};
55

66
/// An extension trait for the `Stream` trait.
77
pub trait StreamExt: Stream {
@@ -10,6 +10,18 @@ pub trait StreamExt: Stream {
1010
where
1111
Self: Stream<Item = T> + Sized,
1212
S2: IntoStream<Item = T>;
13+
14+
/// Takes two streams and creates a new stream over all in sequence
15+
fn chain<T, S2>(self, other: S2) -> Chain2<Self, S2::IntoStream>
16+
where
17+
Self: Stream<Item = T> + Sized,
18+
S2: IntoStream<Item = T>;
19+
20+
/// ‘Zips up’ multiple streams into a single stream of pairs.
21+
fn zip<T, S2>(self, other: S2) -> Zip2<Self, S2::IntoStream>
22+
where
23+
Self: Stream<Item = T> + Sized,
24+
S2: IntoStream<Item = T>;
1325
}
1426

1527
impl<S1> StreamExt for S1
@@ -23,4 +35,22 @@ where
2335
{
2436
Merge::merge((self, other))
2537
}
38+
39+
fn chain<T, S2>(self, other: S2) -> Chain2<Self, S2::IntoStream>
40+
where
41+
Self: Stream<Item = T> + Sized,
42+
S2: IntoStream<Item = T>,
43+
{
44+
// TODO(yosh): fix the bounds on the tuple impl
45+
Chain::chain((self, other.into_stream()))
46+
}
47+
48+
fn zip<T, S2>(self, other: S2) -> Zip2<Self, S2::IntoStream>
49+
where
50+
Self: Stream<Item = T> + Sized,
51+
S2: IntoStream<Item = T>,
52+
{
53+
// TODO(yosh): fix the bounds on the tuple impl
54+
Zip::zip((self, other.into_stream()))
55+
}
2656
}

0 commit comments

Comments
 (0)