Use fold in Iterator::last
Replace last impl with fold
This commit is contained in:
parent
481068a707
commit
76a8bc2473
1 changed files with 1 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue