Skip to content

Commit 76a8bc2

Browse files
committed
Use fold in Iterator::last
Replace last impl with fold
1 parent 481068a commit 76a8bc2

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/libcore/iter/traits/iterator.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ pub trait Iterator {
263263
#[inline]
264264
#[stable(feature = "rust1", since = "1.0.0")]
265265
fn last(self) -> Option<Self::Item> where Self: Sized {
266-
let mut last = None;
267-
for x in self { last = Some(x); }
268-
last
266+
self.fold(None, |_, x| Some(x))
269267
}
270268

271269
/// Returns the `n`th element of the iterator.

0 commit comments

Comments
 (0)