about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Gregory <czipperz@gmail.com>2019-07-07 16:54:48 -0700
committerChris Gregory <czipperz@gmail.com>2019-07-09 21:26:49 -0700
commit76a8bc2473e60be35f96ecc268c6bb1d992ede78 (patch)
tree167da42753ef916c4053a893ee33682116d4d221
parent481068a707679257e2a738b40987246e0420e787 (diff)
downloadrust-76a8bc2473e60be35f96ecc268c6bb1d992ede78.tar.gz
rust-76a8bc2473e60be35f96ecc268c6bb1d992ede78.zip
Use fold in Iterator::last
Replace last impl with fold
-rw-r--r--src/libcore/iter/traits/iterator.rs4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs
index 30923c74145..d934b20a33f 100644
--- a/src/libcore/iter/traits/iterator.rs
+++ b/src/libcore/iter/traits/iterator.rs
@@ -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.