diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-09-25 17:39:22 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-09-25 22:13:05 -0700 |
| commit | e19e628b19af2921fc29818009496bc430640f76 (patch) | |
| tree | 9e4d4d161b7de4b33cd4335dbe8355fa93bd8463 /src/libcore/iter.rs | |
| parent | 473a866733b085419b41b2d2f2708a49c079f89e (diff) | |
| download | rust-e19e628b19af2921fc29818009496bc430640f76.tar.gz rust-e19e628b19af2921fc29818009496bc430640f76.zip | |
Demode iter-trait
Diffstat (limited to 'src/libcore/iter.rs')
| -rw-r--r-- | src/libcore/iter.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 8af4ce3d0b1..dade851473b 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -23,8 +23,8 @@ trait ExtendedIter<A> { } trait EqIter<A:Eq> { - pure fn contains(x: A) -> bool; - pure fn count(x: A) -> uint; + pure fn contains(x: &A) -> bool; + pure fn count(x: &A) -> uint; } trait Times { @@ -66,11 +66,11 @@ trait Buildable<A> { builder: fn(push: pure fn(+v: A))) -> self; } -pure fn eachi<A,IA:BaseIter<A>>(self: IA, blk: fn(uint, v: &A) -> bool) { - let mut i = 0u; +pure fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: fn(uint, v: &A) -> bool) { + let mut i = 0; for self.each |a| { if !blk(i, a) { break; } - i += 1u; + i += 1; } } @@ -130,17 +130,17 @@ pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: IA) -> ~[A] { foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy r, ~[a])) } -pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: A) -> bool { +pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: &A) -> bool { for self.each |a| { - if *a == x { return true; } + if *a == *x { return true; } } return false; } -pure fn count<A:Eq,IA:BaseIter<A>>(self: IA, x: A) -> uint { - do foldl(self, 0u) |count, value| { - if value == x { - count + 1u +pure fn count<A:Eq,IA:BaseIter<A>>(self: IA, x: &A) -> uint { + do foldl(self, 0) |count, value| { + if value == *x { + count + 1 } else { count } |
