5 fn foldl<T, U, F>(values: &[T],
9 U: Clone+Debug, T:Debug,
12 &[ref head, ref tail @ ..] =>
13 foldl(tail, function(initial, head), function),
16 let res = initial.clone(); res
21 fn foldr<T, U, F>(values: &[T],
29 &[ref head @ .., ref tail] =>
30 foldr(head, function(tail, initial), function),
33 let res = initial.clone(); res
39 let x = &[1, 2, 3, 4, 5];
41 let product = foldl(x, 1, |a, b| a * *b);
42 assert_eq!(product, 120);
44 let sum = foldr(x, 0, |a, b| *a + b);