File tree 1 file changed +2
-10
lines changed
1 file changed +2
-10
lines changed Original file line number Diff line number Diff line change @@ -103,21 +103,13 @@ fn main() {
103
103
* Collect our intermediate results, and combine them into a final result
104
104
************************************************************************/
105
105
106
- // collect each thread's intermediate results into a new Vec
107
- let mut intermediate_sums = vec![];
108
- for child in children {
109
- // collect each child thread's return-value
110
- let intermediate_sum = child.join().unwrap();
111
- intermediate_sums.push(intermediate_sum);
112
- }
113
-
114
- // combine all intermediate sums into a single final sum.
106
+ // combine each thread's intermediate results into a single final sum.
115
107
//
116
108
// we use the "turbofish" ::<> to provide sum() with a type hint.
117
109
//
118
110
// TODO: try without the turbofish, by instead explicitly
119
111
// specifying the type of final_result
120
- let final_result = intermediate_sums.iter( ).sum::<u32>();
112
+ let final_result = children.into_iter().map(|c| c.join().unwrap() ).sum::<u32>();
121
113
122
114
println!("Final sum result: {}", final_result);
123
115
}
You can’t perform that action at this time.
0 commit comments