Skip to content

Commit 605bc1b

Browse files
committed
adjuste doc of map_while
Fix doc of `Iterator::map_while` so it would be clearer that it isn't fused.
1 parent a834041 commit 605bc1b

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/libcore/iter/traits/iterator.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,6 @@ pub trait Iterator {
10361036
/// closure on each element of the iterator, and yield elements
10371037
/// while it returns [`Some(_)`][`Some`].
10381038
///
1039-
/// After [`None`] is returned, `map_while()`'s job is over, and the
1040-
/// rest of the elements are ignored.
1041-
///
10421039
/// # Examples
10431040
///
10441041
/// Basic usage:
@@ -1078,15 +1075,14 @@ pub trait Iterator {
10781075
/// #![feature(iter_map_while)]
10791076
/// use std::convert::TryFrom;
10801077
///
1081-
/// let a = [0, -1, 1, -2];
1078+
/// let a = [0, 1, 2, -3, 4, 5, -6];
10821079
///
1083-
/// let mut iter = a.iter().map_while(|x| u32::try_from(*x).ok());
1080+
/// let iter = a.iter().map_while(|x| u32::try_from(*x).ok());
1081+
/// let vec = iter.collect::<Vec<_>>();
10841082
///
1085-
/// assert_eq!(iter.next(), Some(0u32));
1086-
///
1087-
/// // We have more elements that are fit in u32, but since we already
1088-
/// // got a None, map_while() isn't used any more
1089-
/// assert_eq!(iter.next(), None);
1083+
/// // We have more elements which could fit in u32 (4, 5), but `map_while`
1084+
/// // has stopped on the first `None` from predicate (when working with `-3`)
1085+
/// assert_eq!(vec, vec![0, 1, 2]);
10901086
/// ```
10911087
///
10921088
/// Because `map_while()` needs to look at the value in order to see if it

0 commit comments

Comments
 (0)