Skip to content

Fix a number of documentation bugs in libstd/iter.rs #10533

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

Merged
merged 2 commits into from
Nov 18, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions src/libstd/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ pub trait Iterator<A> {
/// let a = [0];
/// let b = [1];
/// let mut it = a.iter().chain(b.iter());
/// assert_eq!(it.next().get(), &0);
/// assert_eq!(it.next().get(), &1);
/// assert_eq!(it.next().unwrap(), &0);
/// assert_eq!(it.next().unwrap(), &1);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -135,7 +135,7 @@ pub trait Iterator<A> {
/// let a = [0];
/// let b = [1];
/// let mut it = a.iter().zip(b.iter());
/// assert_eq!(it.next().get(), (&0, &1));
/// assert_eq!(it.next().unwrap(), (&0, &1));
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -151,8 +151,8 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [1, 2];
/// let mut it = a.iter().map(|&x| 2 * x);
/// assert_eq!(it.next().get(), 2);
/// assert_eq!(it.next().get(), 4);
/// assert_eq!(it.next().unwrap(), 2);
/// assert_eq!(it.next().unwrap(), 4);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -169,7 +169,7 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [1, 2];
/// let mut it = a.iter().filter(|&x| *x > 1);
/// assert_eq!(it.next().get(), &2);
/// assert_eq!(it.next().unwrap(), &2);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -186,7 +186,7 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [1, 2];
/// let mut it = a.iter().filter_map(|&x| if x > 1 {Some(2 * x)} else {None});
/// assert_eq!(it.next().get(), 4);
/// assert_eq!(it.next().unwrap(), 4);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -202,8 +202,8 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [100, 200];
/// let mut it = a.iter().enumerate();
/// assert_eq!(it.next().get(), (0, &100));
/// assert_eq!(it.next().get(), (1, &200));
/// assert_eq!(it.next().unwrap(), (0, &100));
/// assert_eq!(it.next().unwrap(), (1, &200));
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand Down Expand Up @@ -243,9 +243,9 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [1, 2, 3, 2, 1];
/// let mut it = a.iter().skip_while(|&a| *a < 3);
/// assert_eq!(it.next().get(), &3);
/// assert_eq!(it.next().get(), &2);
/// assert_eq!(it.next().get(), &1);
/// assert_eq!(it.next().unwrap(), &3);
/// assert_eq!(it.next().unwrap(), &2);
/// assert_eq!(it.next().unwrap(), &1);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -262,8 +262,8 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [1, 2, 3, 2, 1];
/// let mut it = a.iter().take_while(|&a| *a < 3);
/// assert_eq!(it.next().get(), &1);
/// assert_eq!(it.next().get(), &2);
/// assert_eq!(it.next().unwrap(), &1);
/// assert_eq!(it.next().unwrap(), &2);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -279,8 +279,8 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [1, 2, 3, 4, 5];
/// let mut it = a.iter().skip(3);
/// assert_eq!(it.next().get(), &4);
/// assert_eq!(it.next().get(), &5);
/// assert_eq!(it.next().unwrap(), &4);
/// assert_eq!(it.next().unwrap(), &5);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -296,9 +296,9 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [1, 2, 3, 4, 5];
/// let mut it = a.iter().take(3);
/// assert_eq!(it.next().get(), &1);
/// assert_eq!(it.next().get(), &2);
/// assert_eq!(it.next().get(), &3);
/// assert_eq!(it.next().unwrap(), &1);
/// assert_eq!(it.next().unwrap(), &2);
/// assert_eq!(it.next().unwrap(), &3);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand All @@ -319,11 +319,11 @@ pub trait Iterator<A> {
/// *fac = *fac * x;
/// Some(*fac)
/// });
/// assert_eq!(it.next().get(), 1);
/// assert_eq!(it.next().get(), 2);
/// assert_eq!(it.next().get(), 6);
/// assert_eq!(it.next().get(), 24);
/// assert_eq!(it.next().get(), 120);
/// assert_eq!(it.next().unwrap(), 1);
/// assert_eq!(it.next().unwrap(), 2);
/// assert_eq!(it.next().unwrap(), 6);
/// assert_eq!(it.next().unwrap(), 24);
/// assert_eq!(it.next().unwrap(), 120);
/// assert!(it.next().is_none());
/// ```
#[inline]
Expand Down Expand Up @@ -424,16 +424,13 @@ pub trait Iterator<A> {
ByRef{iter: self}
}

/// An adaptation of an external iterator to the for-loop protocol of rust.
/// Apply a function to each element, or stop iterating if the
/// function returns `false`.
///
/// # Example
///
/// ```rust
/// use std::iter::count;
///
/// for i in count(0, 10) {
/// println!("{}", i);
/// }
/// range(0, 5).advance(|x| {print!("{} ", x); true});
/// ```
#[inline]
fn advance(&mut self, f: &fn(A) -> bool) -> bool {
Expand Down Expand Up @@ -485,7 +482,7 @@ pub trait Iterator<A> {
/// ```rust
/// let a = [1, 2, 3, 4, 5];
/// let mut it = a.iter();
/// assert!(it.nth(2).get() == &3);
/// assert!(it.nth(2).unwrap() == &3);
/// assert!(it.nth(2) == None);
/// ```
#[inline]
Expand All @@ -506,7 +503,7 @@ pub trait Iterator<A> {
///
/// ```rust
/// let a = [1, 2, 3, 4, 5];
/// assert!(a.iter().last().get() == &5);
/// assert!(a.iter().last().unwrap() == &5);
/// ```
#[inline]
fn last(&mut self) -> Option<A> {
Expand Down Expand Up @@ -865,7 +862,7 @@ pub trait OrdIterator<A> {
///
/// ```rust
/// let a = [1, 2, 3, 4, 5];
/// assert!(a.iter().max().get() == &5);
/// assert!(a.iter().max().unwrap() == &5);
/// ```
fn max(&mut self) -> Option<A>;

Expand All @@ -875,7 +872,7 @@ pub trait OrdIterator<A> {
///
/// ```rust
/// let a = [1, 2, 3, 4, 5];
/// assert!(a.iter().min().get() == &1);
/// assert!(a.iter().min().unwrap() == &1);
/// ```
fn min(&mut self) -> Option<A>;
}
Expand Down