about summary refs log tree commit diff
diff options
context:
space:
mode:
authormdinger <mdinger.bugzilla@gmail.com>2015-05-22 21:37:11 -0400
committermdinger <mdinger.bugzilla@gmail.com>2015-05-22 21:37:11 -0400
commit5b443b204e0a2e5f4f24fb6563ebff497e2565df (patch)
tree87f9380da4c24fb2b6ab199dc174852729ac0d6f
parentc3d60aba6c86883c79055c1a3923d4db116b644e (diff)
downloadrust-5b443b204e0a2e5f4f24fb6563ebff497e2565df.tar.gz
rust-5b443b204e0a2e5f4f24fb6563ebff497e2565df.zip
Simplify flat_map example
-rw-r--r--src/libcore/iter.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index ed7cdbbb6e2..892d6d4fb26 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -452,20 +452,19 @@ pub trait Iterator {
         Scan{iter: self, f: f, state: initial_state}
     }
 
-    /// Creates an iterator that maps each element to an iterator,
-    /// and yields the elements of the produced iterators.
+    /// Takes a function that maps each element to a new iterator and yields
+    /// all the elements of the produced iterators.
+    ///
+    /// This is useful for unraveling nested structures.
     ///
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
-    /// let xs = [2, 3];
-    /// let ys = [0, 1, 0, 1, 2];
-    /// let it = xs.iter().flat_map(|&x| (0..).take(x));
-    /// // Check that `it` has the same elements as `ys`
-    /// for (i, x) in it.enumerate() {
-    ///     assert_eq!(x, ys[i]);
-    /// }
+    /// let words = ["alpha", "beta", "gamma"];
+    /// let merged: String = words.iter()
+    ///                           .flat_map(|s| s.chars())
+    ///                           .collect();
+    /// assert_eq!(merged, "alphabetagamma");
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]