-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Remove finished
flag from MapWhile
#68820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1036,9 +1036,6 @@ pub trait Iterator { | |
/// closure on each element of the iterator, and yield elements | ||
/// while it returns [`Some(_)`][`Some`]. | ||
/// | ||
/// After [`None`] is returned, `map_while()`'s job is over, and the | ||
/// rest of the elements are ignored. | ||
/// | ||
/// # Examples | ||
/// | ||
/// Basic usage: | ||
|
@@ -1078,15 +1075,14 @@ pub trait Iterator { | |
/// #![feature(iter_map_while)] | ||
/// use std::convert::TryFrom; | ||
/// | ||
/// let a = [0, -1, 1, -2]; | ||
/// let a = [0, 1, 2, -3, 4, 5, -6]; | ||
/// | ||
/// let mut iter = a.iter().map_while(|x| u32::try_from(*x).ok()); | ||
/// let iter = a.iter().map_while(|x| u32::try_from(*x).ok()); | ||
/// let vec = iter.collect::<Vec<_>>(); | ||
/// | ||
/// assert_eq!(iter.next(), Some(0u32)); | ||
/// | ||
/// // We have more elements that are fit in u32, but since we already | ||
/// // got a None, map_while() isn't used any more | ||
/// assert_eq!(iter.next(), None); | ||
/// // We have more elements which could fit in u32 (4, 5), but `map_while` | ||
/// // has stopped on the first `None` from predicate (when working with `-3`) | ||
/// assert_eq!(vec, vec![0, 1, 2]); | ||
/// ``` | ||
/// | ||
/// Because `map_while()` needs to look at the value in order to see if it | ||
|
@@ -1114,8 +1110,23 @@ pub trait Iterator { | |
/// The `-3` is no longer there, because it was consumed in order to see if | ||
/// the iteration should stop, but wasn't placed back into the iterator. | ||
/// | ||
/// Note that unlike [`take_while`] this iterator is **not** fused: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs to be documented. The lack of a Additionally I think that the behavior after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree in that I think mentioning this iterator not being fused in the docs is a good thing. The lack of impls, especially for marker traits, is easily overlooked. However, I agree that we probably don't want to specify the behavior after the first
|
||
/// | ||
/// ``` | ||
/// #![feature(iter_map_while)] | ||
/// use std::convert::identity; | ||
/// | ||
/// let mut iter = vec![Some(0), None, Some(1)].into_iter().map_while(identity); | ||
/// assert_eq!(iter.next(), Some(0)); | ||
/// assert_eq!(iter.next(), None); | ||
/// assert_eq!(iter.next(), Some(1)); | ||
/// ``` | ||
/// | ||
/// If you need fused iterator, use [`fuse`]. | ||
/// | ||
/// [`Some`]: ../../std/option/enum.Option.html#variant.Some | ||
/// [`None`]: ../../std/option/enum.Option.html#variant.None | ||
/// [`fuse`]: #method.fuse | ||
#[inline] | ||
#[unstable(feature = "iter_map_while", reason = "recently added", issue = "68537")] | ||
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P> | ||
|
Uh oh!
There was an error while loading. Please reload this page.