Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use fold in Iterator::last
Replace last impl with fold
  • Loading branch information
czipperz committed Jul 10, 2019
1 parent 481068a commit 76a8bc2
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/libcore/iter/traits/iterator.rs
Expand Up @@ -263,9 +263,7 @@ pub trait Iterator {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn last(self) -> Option<Self::Item> where Self: Sized {
let mut last = None;
for x in self { last = Some(x); }
last
self.fold(None, |_, x| Some(x))
}

/// Returns the `n`th element of the iterator.
Expand Down

0 comments on commit 76a8bc2

Please sign in to comment.