Skip to content

Commit 5b443b2

Browse files
committed
Simplify flat_map example
1 parent c3d60ab commit 5b443b2

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/libcore/iter.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,20 +452,19 @@ pub trait Iterator {
452452
Scan{iter: self, f: f, state: initial_state}
453453
}
454454

455-
/// Creates an iterator that maps each element to an iterator,
456-
/// and yields the elements of the produced iterators.
455+
/// Takes a function that maps each element to a new iterator and yields
456+
/// all the elements of the produced iterators.
457+
///
458+
/// This is useful for unraveling nested structures.
457459
///
458460
/// # Examples
459461
///
460462
/// ```
461-
/// # #![feature(core)]
462-
/// let xs = [2, 3];
463-
/// let ys = [0, 1, 0, 1, 2];
464-
/// let it = xs.iter().flat_map(|&x| (0..).take(x));
465-
/// // Check that `it` has the same elements as `ys`
466-
/// for (i, x) in it.enumerate() {
467-
/// assert_eq!(x, ys[i]);
468-
/// }
463+
/// let words = ["alpha", "beta", "gamma"];
464+
/// let merged: String = words.iter()
465+
/// .flat_map(|s| s.chars())
466+
/// .collect();
467+
/// assert_eq!(merged, "alphabetagamma");
469468
/// ```
470469
#[inline]
471470
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)