Skip to content

Commit c78fb62

Browse files
Andrew Banchichwooster0
Andrew Banchich
andcommitted
Improve std::iter::zip example.
Update library/core/src/iter/adapters/zip.rs Co-authored-by: r00ster <r00ster91@protonmail.com> Update library/core/src/iter/adapters/zip.rs Co-authored-by: r00ster <r00ster91@protonmail.com>
1 parent 3b263ce commit c78fb62

File tree

1 file changed

+14
-6
lines changed
  • library/core/src/iter/adapters

1 file changed

+14
-6
lines changed

library/core/src/iter/adapters/zip.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,23 @@ impl<A: Iterator, B: Iterator> Zip<A, B> {
4545
///
4646
/// let xs = [1, 2, 3];
4747
/// let ys = [4, 5, 6];
48-
/// for (x, y) in zip(&xs, &ys) {
49-
/// println!("x:{}, y:{}", x, y);
50-
/// }
48+
///
49+
/// let mut iter = zip(xs, ys);
50+
///
51+
/// assert_eq!(iter.next().unwrap(), (1, 4));
52+
/// assert_eq!(iter.next().unwrap(), (2, 5));
53+
/// assert_eq!(iter.next().unwrap(), (3, 6));
54+
/// assert!(iter.next().is_none());
5155
///
5256
/// // Nested zips are also possible:
5357
/// let zs = [7, 8, 9];
54-
/// for ((x, y), z) in zip(zip(&xs, &ys), &zs) {
55-
/// println!("x:{}, y:{}, z:{}", x, y, z);
56-
/// }
58+
///
59+
/// let mut iter = zip(zip(xs, ys), zs);
60+
///
61+
/// assert_eq!(iter.next().unwrap(), ((1, 4), 7));
62+
/// assert_eq!(iter.next().unwrap(), ((2, 5), 8));
63+
/// assert_eq!(iter.next().unwrap(), ((3, 6), 9));
64+
/// assert!(iter.next().is_none());
5765
/// ```
5866
#[unstable(feature = "iter_zip", issue = "83574")]
5967
pub fn zip<A, B>(a: A, b: B) -> Zip<A::IntoIter, B::IntoIter>

0 commit comments

Comments
 (0)