Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let vec: Vec<Result<i32, i32>> = vec![Ok(1), Err(2), Ok(1), Err(2)];
- let result: Result<Vec<i32>, i32> = vec.iter().cloned().collect();
- println!("collect res: {:?}", result);
- let (good, bad) = vec
- .iter()
- .cloned()
- .fold((vec![], vec![]), |(mut oks, mut errs), res| {
- match res {
- Ok(x) => oks.push(x),
- Err(e) => errs.push(e),
- };
- (oks, errs)
- });
- println!("fold: good {:?}, bad: {:?}", good, bad);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement