doc: provide an actual equivalent to filter_map

This commit is contained in:
Tshepang Lekhonkhobe 2017-07-22 23:22:01 +02:00
parent a1f180bde3
commit fc90064546

View File

@ -637,16 +637,15 @@ pub trait Iterator {
/// let a = ["1", "2", "lol"];
///
/// let mut iter = a.iter()
/// .map(|s| s.parse().ok())
/// .filter(|s| s.is_some());
/// .map(|s| s.parse())
/// .filter(|s| s.is_ok())
/// .map(|s| s.unwrap());
///
/// assert_eq!(iter.next(), Some(Some(1)));
/// assert_eq!(iter.next(), Some(Some(2)));
/// assert_eq!(iter.next(), Some(1));
/// assert_eq!(iter.next(), Some(2));
/// assert_eq!(iter.next(), None);
/// ```
///
/// There's an extra layer of [`Some`] in there.
///
/// [`Option<T>`]: ../../std/option/enum.Option.html
/// [`Some`]: ../../std/option/enum.Option.html#variant.Some
/// [`None`]: ../../std/option/enum.Option.html#variant.None