Skip to content

Commit 340b7e2

Browse files
committed
---
yaml --- r: 149616 b: refs/heads/try2 c: a09a4b8 h: refs/heads/master v: v3
1 parent 3c3326b commit 340b7e2

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 43bc6fcc62e3ad92c76ea8f160a6189ac86618f2
8+
refs/heads/try2: a09a4b882d415ea764f58816b963de0203c4e9f0
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)