Skip to content

Commit 91ee4c7

Browse files
committed
doc: Add stream unzip doc
1 parent 603b3c5 commit 91ee4c7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/stream/stream/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,33 @@ extension_trait! {
17191719
Zip::new(self, other)
17201720
}
17211721

1722+
#[doc = r#"
1723+
Converts an stream of pairs into a pair of containers.
1724+
1725+
unzip() consumes an entire stream of pairs, producing two collections: one from the left elements of the pairs, and one from the right elements.
1726+
1727+
This function is, in some sense, the opposite of [`zip`].
1728+
1729+
[`zip`]: trait.Stream.html#method.zip
1730+
1731+
# Example
1732+
1733+
```
1734+
# fn main() { async_std::task::block_on(async {
1735+
#
1736+
use async_std::prelude::*;
1737+
use async_std::stream;
1738+
1739+
let s = stream::from_iter(vec![(1,2), (3,4)]);
1740+
1741+
let (left, right): (Vec<_>, Vec<_>) = s.unzip().await;
1742+
1743+
assert_eq!(left, [1, 3]);
1744+
assert_eq!(right, [2, 4]);
1745+
#
1746+
# }) }
1747+
```
1748+
"#]
17221749
#[cfg(feature = "unstable")]
17231750
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
17241751
fn unzip<A, B, FromA, FromB>(self) -> impl Future<Output = (FromA, FromB)> [UnzipFuture<Self, FromA, FromB>]

0 commit comments

Comments
 (0)