Skip to content

Commit 84a5626

Browse files
committed
---
yaml --- r: 106476 b: refs/heads/try c: a09a4b8 h: refs/heads/master v: v3
1 parent d674e8b commit 84a5626

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
5-
refs/heads/try: 43bc6fcc62e3ad92c76ea8f160a6189ac86618f2
5+
refs/heads/try: a09a4b882d415ea764f58816b963de0203c4e9f0
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcollections/list.rs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,6 @@ impl<T> List<T> {
5353
}
5454
}
5555

56-
/**
57-
* Left fold
58-
*
59-
* Applies `f` to `u` and the first element in the list, then applies `f` to
60-
* the result of the previous call and the second element, and so on,
61-
* returning the accumulated result.
62-
*
63-
* # Arguments
64-
*
65-
* * list - The list to fold
66-
* * z - The initial value
67-
* * f - The function to apply
68-
*/
69-
pub fn foldl<T:Clone,U>(z: T, list: @List<U>, f: |&T, &U| -> T) -> T {
70-
let mut accum: T = z;
71-
iter(list, |element| accum = f(&accum, element));
72-
accum
73-
}
74-
7556
/**
7657
* Search for an element that matches a given predicate
7758
*
@@ -258,21 +239,17 @@ mod tests {
258239
}
259240

260241
#[test]
261-
fn test_foldl() {
262-
fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); }
263-
let list = @List::from_vec([0, 1, 2, 3, 4]);
264-
let empty = @list::Nil::<int>;
265-
assert_eq!(list::foldl(0u, list, add), 10u);
266-
assert_eq!(list::foldl(0u, empty, add), 0u);
267-
}
242+
fn test_fold() {
243+
fn add_(a: uint, b: &uint) -> uint { a + *b }
244+
fn subtract_(a: uint, b: &uint) -> uint { a - *b }
268245

269-
#[test]
270-
fn test_foldl2() {
271-
fn sub(a: &int, b: &int) -> int {
272-
*a - *b
273-
}
274-
let list = @List::from_vec([1, 2, 3, 4]);
275-
assert_eq!(list::foldl(0, list, sub), -10);
246+
let empty = Nil::<uint>;
247+
assert_eq!(empty.iter().fold(0u, add_), 0u);
248+
assert_eq!(empty.iter().fold(10u, subtract_), 10u);
249+
250+
let list = List::from_vec([0u, 1u, 2u, 3u, 4u]);
251+
assert_eq!(list.iter().fold(0u, add_), 10u);
252+
assert_eq!(list.iter().fold(10u, subtract_), 0u);
276253
}
277254

278255
#[test]

0 commit comments

Comments
 (0)