make iter::position() not require Eq

This commit is contained in:
Niko Matsakis 2012-09-13 09:13:03 -07:00
parent 7e5661214a
commit 109055c7d3
3 changed files with 9 additions and 8 deletions

View File

@ -18,14 +18,14 @@ impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
iter::foldl(self, move b0, blk)
}
pure fn position(f: fn(A) -> bool) -> Option<uint> {
iter::position(self, f)
}
}
impl<A: Eq> IMPL_T<A>: iter::EqIter<A> {
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<uint> {
iter::position(self, f)
}
}
impl<A: Copy> IMPL_T<A>: iter::CopyableIter<A> {

View File

@ -13,12 +13,12 @@ trait ExtendedIter<A> {
pure fn all(blk: fn(A) -> bool) -> bool;
pure fn any(blk: fn(A) -> bool) -> bool;
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B;
pure fn position(f: fn(A) -> bool) -> Option<uint>;
}
trait EqIter<A:Eq> {
pure fn contains(x: A) -> bool;
pure fn count(x: A) -> uint;
pure fn position(f: fn(A) -> bool) -> Option<uint>;
}
trait Times {
@ -142,7 +142,8 @@ pure fn count<A:Eq,IA:BaseIter<A>>(self: IA, x: A) -> uint {
}
pure fn position<A,IA:BaseIter<A>>(self: IA, f: fn(A) -> bool)
-> Option<uint> {
-> Option<uint>
{
let mut i = 0;
for self.each |a| {
if f(a) { return Some(i); }

View File

@ -2019,14 +2019,14 @@ impl<A> &[A]: iter::ExtendedIter<A> {
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
iter::foldl(self, move b0, blk)
}
pure fn position(f: fn(A) -> bool) -> Option<uint> {
iter::position(self, f)
}
}
impl<A: Eq> &[A]: iter::EqIter<A> {
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<uint> {
iter::position(self, f)
}
}
impl<A: Copy> &[A]: iter::CopyableIter<A> {