2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2014-10-02 21:48:07 -05:00
|
|
|
fn each<'a,T,F:FnMut(&'a T)>(x: &'a [T], mut f: F) {
|
2015-01-31 11:20:46 -06:00
|
|
|
for val in x {
|
2014-07-23 14:43:29 -05:00
|
|
|
f(val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 02:42:26 -06:00
|
|
|
let mut sum = 0;
|
|
|
|
let elems = [ 1, 2, 3, 4, 5 ];
|
2015-03-25 19:06:52 -05:00
|
|
|
each(&elems, |val: &usize| sum += *val);
|
2014-07-23 14:43:29 -05:00
|
|
|
assert_eq!(sum, 15);
|
|
|
|
}
|