From 109055c7d3831f0a5a771e6f946e876dd8434223 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 13 Sep 2012 09:13:03 -0700 Subject: [PATCH] make iter::position() not require Eq --- src/libcore/iter-trait.rs | 6 +++--- src/libcore/iter.rs | 5 +++-- src/libcore/vec.rs | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index 55a13fab8e4..27b525cba90 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -18,14 +18,14 @@ impl IMPL_T: iter::ExtendedIter { pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { iter::foldl(self, move b0, blk) } + pure fn position(f: fn(A) -> bool) -> Option { + iter::position(self, f) + } } impl IMPL_T: iter::EqIter { pure fn contains(x: A) -> bool { iter::contains(self, x) } pure fn count(x: A) -> uint { iter::count(self, x) } - pure fn position(f: fn(A) -> bool) -> Option { - iter::position(self, f) - } } impl IMPL_T: iter::CopyableIter { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 1e05965925c..66c5b2b234a 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -13,12 +13,12 @@ trait ExtendedIter { pure fn all(blk: fn(A) -> bool) -> bool; pure fn any(blk: fn(A) -> bool) -> bool; pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B; + pure fn position(f: fn(A) -> bool) -> Option; } trait EqIter { pure fn contains(x: A) -> bool; pure fn count(x: A) -> uint; - pure fn position(f: fn(A) -> bool) -> Option; } trait Times { @@ -142,7 +142,8 @@ pure fn count>(self: IA, x: A) -> uint { } pure fn position>(self: IA, f: fn(A) -> bool) - -> Option { + -> Option +{ let mut i = 0; for self.each |a| { if f(a) { return Some(i); } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 626cb886fb3..0f512b4ec56 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -2019,14 +2019,14 @@ impl &[A]: iter::ExtendedIter { pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { iter::foldl(self, move b0, blk) } + pure fn position(f: fn(A) -> bool) -> Option { + iter::position(self, f) + } } impl &[A]: iter::EqIter { pure fn contains(x: A) -> bool { iter::contains(self, x) } pure fn count(x: A) -> uint { iter::count(self, x) } - pure fn position(f: fn(A) -> bool) -> Option { - iter::position(self, f) - } } impl &[A]: iter::CopyableIter {