Skip to content

Commit

Permalink
docs: better demonstrate that None values are skipped as many times a…
Browse files Browse the repository at this point in the history
…s needed
  • Loading branch information
tshepang committed Jul 17, 2020
1 parent 8534be7 commit 08b4b54
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/libcore/iter/traits/iterator.rs
Expand Up @@ -756,23 +756,21 @@ pub trait Iterator {
/// Basic usage:
///
/// ```
/// let a = ["1", "lol", "3", "NaN", "5"];
/// let a = ["1", "two", "NaN", "four", "5"];
///
/// let mut iter = a.iter().filter_map(|s| s.parse().ok());
///
/// assert_eq!(iter.next(), Some(1));
/// assert_eq!(iter.next(), Some(3));
/// assert_eq!(iter.next(), Some(5));
/// assert_eq!(iter.next(), None);
/// ```
///
/// Here's the same example, but with [`filter`] and [`map`]:
///
/// ```
/// let a = ["1", "lol", "3", "NaN", "5"];
/// let a = ["1", "two", "NaN", "four", "5"];
/// let mut iter = a.iter().map(|s| s.parse()).filter(|s| s.is_ok()).map(|s| s.unwrap());
/// assert_eq!(iter.next(), Some(1));
/// assert_eq!(iter.next(), Some(3));
/// assert_eq!(iter.next(), Some(5));
/// assert_eq!(iter.next(), None);
/// ```
Expand Down

0 comments on commit 08b4b54

Please sign in to comment.