Rollup merge of #46737 - tshepang:better, r=steveklabnik
doc: a better example Closes #46734
This commit is contained in:
commit
b98de5d0ac
@ -621,27 +621,24 @@ pub trait Iterator {
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let a = ["1", "2", "lol"];
|
||||
/// let a = ["1", "lol", "3", "NaN", "5"];
|
||||
///
|
||||
/// let mut iter = a.iter().filter_map(|s| s.parse().ok());
|
||||
///
|
||||
/// assert_eq!(iter.next(), Some(1));
|
||||
/// assert_eq!(iter.next(), Some(2));
|
||||
/// 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", "2", "lol"];
|
||||
///
|
||||
/// let mut iter = a.iter()
|
||||
/// .map(|s| s.parse())
|
||||
/// .filter(|s| s.is_ok())
|
||||
/// .map(|s| s.unwrap());
|
||||
///
|
||||
/// let a = ["1", "lol", "3", "NaN", "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(2));
|
||||
/// assert_eq!(iter.next(), Some(3));
|
||||
/// assert_eq!(iter.next(), Some(5));
|
||||
/// assert_eq!(iter.next(), None);
|
||||
/// ```
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user