Skip to content

Commit dad93ac

Browse files
committed
---
yaml --- r: 14246 b: refs/heads/try c: 3edad35 h: refs/heads/master v: v3
1 parent c214924 commit dad93ac

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 85175d639f0b40062d2741f4918df48aee3ef758
5+
refs/heads/try: 3edad3555e1f5c01572f32e84480383c1ae2b472
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/iter.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ fn reverse<A:copy,IA:iterable<A>>(self: IA, blk: fn(A)) {
8282
vec::riter(to_list(self), blk)
8383
}
8484

85+
fn count<A,IA:iterable<A>>(self: IA, x: A) -> uint {
86+
foldl(self, 0u) {|count, value|
87+
if value == x {
88+
count + 1u
89+
} else {
90+
count
91+
}
92+
}
93+
}
94+
8595
fn repeat(times: uint, blk: fn()) {
8696
let i = 0u;
8797
while i < times {
@@ -223,4 +233,9 @@ fn test_max_empty() {
223233
#[test]
224234
fn test_reverse() {
225235
assert to_list(bind reverse([1, 2, 3], _)) == [3, 2, 1];
236+
}
237+
238+
#[test]
239+
fn test_count() {
240+
assert count([1, 2, 1, 2, 1], 1) == 3u;
226241
}

0 commit comments

Comments
 (0)