Skip to content

Commit bf2d555

Browse files
committed
---
yaml --- r: 14247 b: refs/heads/try c: d679c0e h: refs/heads/master i: 14245: c214924 14243: 4d51533 14239: c87d1d9 v: v3
1 parent dad93ac commit bf2d555

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-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: 3edad3555e1f5c01572f32e84480383c1ae2b472
5+
refs/heads/try: d679c0eb3486408ca7575eb70a0fc55a0d3de235
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/iter.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ fn foldl<A,B:copy,IA:iterable<A>>(self: IA, b0: B, blk: fn(B, A) -> B) -> B {
7373
ret b;
7474
}
7575

76+
fn foldr<A:copy,B:copy,IA:iterable<A>>(
77+
self: IA, b0: B, blk: fn(A, B) -> B) -> B {
78+
79+
let b = b0;
80+
reverse(self) {|a|
81+
b = blk(a, b);
82+
}
83+
ret b;
84+
}
85+
7686
fn to_list<A:copy,IA:iterable<A>>(self: IA) -> [A] {
7787
foldl::<A,[A],IA>(self, [], {|r, a| r + [a]})
7888
}
@@ -238,4 +248,13 @@ fn test_reverse() {
238248
#[test]
239249
fn test_count() {
240250
assert count([1, 2, 1, 2, 1], 1) == 3u;
251+
}
252+
253+
#[test]
254+
fn test_foldr() {
255+
fn sub(&&a: int, &&b: int) -> int {
256+
a - b
257+
}
258+
let sum = foldr([1, 2, 3, 4], 0, sub);
259+
assert sum == -2;
241260
}

0 commit comments

Comments
 (0)