From 5e9ca5b25530ab58f9d0b09662884928b054f271 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 3 Dec 2014 19:43:25 -0500 Subject: [PATCH] libcore: use unboxed closures in `IteratorExt` methods --- src/libcore/iter.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 51ae0f47029..e886dfadb47 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -521,7 +521,7 @@ pub trait IteratorExt: Iterator { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn fold(mut self, init: B, f: |B, A| -> B) -> B { + fn fold(mut self, init: B, mut f: F) -> B where F: FnMut(B, A) -> B { let mut accum = init; for x in self { accum = f(accum, x); @@ -555,7 +555,7 @@ pub trait IteratorExt: Iterator { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn all(mut self, f: |A| -> bool) -> bool { + fn all(mut self, mut f: F) -> bool where F: FnMut(A) -> bool { for x in self { if !f(x) { return false; } } true } @@ -573,7 +573,7 @@ pub trait IteratorExt: Iterator { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn any(&mut self, f: |A| -> bool) -> bool { + fn any(&mut self, mut f: F) -> bool where F: FnMut(A) -> bool { for x in *self { if f(x) { return true; } } false } @@ -583,7 +583,7 @@ pub trait IteratorExt: Iterator { /// Does not consume the iterator past the first found element. #[inline] #[unstable = "waiting for unboxed closures"] - fn find(&mut self, predicate: |&A| -> bool) -> Option { + fn find

(&mut self, mut predicate: P) -> Option where P: FnMut(&A) -> bool { for x in *self { if predicate(&x) { return Some(x) } } @@ -593,7 +593,7 @@ pub trait IteratorExt: Iterator { /// Return the index of the first element satisfying the specified predicate #[inline] #[unstable = "waiting for unboxed closures"] - fn position(&mut self, predicate: |A| -> bool) -> Option { + fn position

(&mut self, mut predicate: P) -> Option where P: FnMut(A) -> bool { let mut i = 0; for x in *self { if predicate(x) { @@ -617,7 +617,7 @@ pub trait IteratorExt: Iterator { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn max_by(self, f: |&A| -> B) -> Option { + fn max_by(self, mut f: F) -> Option where F: FnMut(&A) -> B { self.fold(None, |max: Option<(A, B)>, x| { let x_val = f(&x); match max { @@ -644,7 +644,7 @@ pub trait IteratorExt: Iterator { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn min_by(self, f: |&A| -> B) -> Option { + fn min_by(self, mut f: F) -> Option where F: FnMut(&A) -> B { self.fold(None, |min: Option<(A, B)>, x| { let x_val = f(&x); match min {