Skip to content

Commit

Permalink
Use a little more compelling example of for_each
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Jun 27, 2017
1 parent 4a8ddac commit e72ee6e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,17 @@ pub trait Iterator {
/// ```
/// #![feature(iterator_for_each)]
///
/// let mut v = vec![];
/// (0..5).for_each(|x| v.push(x * 100));
/// use std::sync::mpsc::channel;
///
/// let mut v2 = vec![];
/// for x in 0..5 { v2.push(x * 100); }
/// let (tx, rx) = channel();
/// (0..5).map(|x| x * 2 + 1)
/// .for_each(move |x| tx.send(x).unwrap());
///
/// assert_eq!(v, v2);
/// let v: Vec<_> = rx.iter().collect();
/// assert_eq!(v, vec![1, 3, 5, 7, 9]);
/// ```
///
/// For such a small example, the `for` loop is cleaner, but `for_each`
/// For such a small example, a `for` loop may be cleaner, but `for_each`
/// might be preferable to keep a functional style with longer iterators:
///
/// ```
Expand Down

0 comments on commit e72ee6e

Please sign in to comment.