From 88962eeed86631b6646fce0602acd7daae7a1ddc Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 11 Dec 2012 09:06:56 -0800 Subject: core: Add &self to core::iter methods --- src/libcore/vec.rs | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'src/libcore/vec.rs') diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index c568faccf89..912f9b1bf1b 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -2013,57 +2013,62 @@ pub mod bytes { // required in the slice. impl &[A]: iter::BaseIter { - pub pure fn each(blk: fn(v: &A) -> bool) { + pub pure fn each(&self, blk: fn(v: &A) -> bool) { // FIXME(#2263)---should be able to call each(self, blk) - for each(self) |e| { + for each(*self) |e| { if (!blk(e)) { return; } } } - pure fn size_hint() -> Option { Some(len(self)) } + pure fn size_hint(&self) -> Option { Some(len(*self)) } } impl &[A]: iter::ExtendedIter { - pub pure fn eachi(blk: fn(uint, v: &A) -> bool) { - iter::eachi(&self, blk) + pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) { + iter::eachi(self, blk) } - pub pure fn all(blk: fn(&A) -> bool) -> bool { iter::all(&self, blk) } - pub pure fn any(blk: fn(&A) -> bool) -> bool { iter::any(&self, blk) } - pub pure fn foldl(b0: B, blk: fn(&B, &A) -> B) -> B { - iter::foldl(&self, b0, blk) + pub pure fn all(&self, blk: fn(&A) -> bool) -> bool { + iter::all(self, blk) } - pub pure fn position(f: fn(&A) -> bool) -> Option { - iter::position(&self, f) + pub pure fn any(&self, blk: fn(&A) -> bool) -> bool { + iter::any(self, blk) + } + pub pure fn foldl(&self, b0: B, blk: fn(&B, &A) -> B) -> B { + iter::foldl(self, b0, blk) + } + pub pure fn position(&self, f: fn(&A) -> bool) -> Option { + iter::position(self, f) } } impl &[A]: iter::EqIter { - pub pure fn contains(x: &A) -> bool { iter::contains(&self, x) } - pub pure fn count(x: &A) -> uint { iter::count(&self, x) } + pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) } + pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) } } impl &[A]: iter::CopyableIter { - pure fn filter_to_vec(pred: fn(a: A) -> bool) -> ~[A] { - iter::filter_to_vec(&self, pred) + pure fn filter_to_vec(&self, pred: fn(a: A) -> bool) -> ~[A] { + iter::filter_to_vec(self, pred) } - pure fn map_to_vec(op: fn(v: A) -> B) -> ~[B] { - iter::map_to_vec(&self, op) + pure fn map_to_vec(&self, op: fn(v: A) -> B) -> ~[B] { + iter::map_to_vec(self, op) } - pure fn to_vec() -> ~[A] { iter::to_vec(&self) } + pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) } - pure fn flat_map_to_vec>(op: fn(A) -> IB) -> ~[B] { - iter::flat_map_to_vec(&self, op) + pure fn flat_map_to_vec>(&self, op: fn(A) -> IB) + -> ~[B] { + iter::flat_map_to_vec(self, op) } - pub pure fn find(p: fn(a: A) -> bool) -> Option { - iter::find(&self, p) + pub pure fn find(&self, f: fn(A) -> bool) -> Option { + iter::find(self, f) } } impl &[A]: iter::CopyableOrderedIter { - pure fn min() -> A { iter::min(&self) } - pure fn max() -> A { iter::max(&self) } + pure fn min(&self) -> A { iter::min(self) } + pure fn max(&self) -> A { iter::max(self) } } impl &[A] : iter::CopyableNonstrictIter { -- cgit 1.4.1-3-g733a5