Created
April 18, 2019 22:37
-
-
Save gregberns/f5fac3df9d5790c03647e014a91fdbbd to your computer and use it in GitHub Desktop.
Rust implementation for `partition` function for `Result`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn partition<A,B>(list: Vec<Result<A,B>>) -> (Vec<A>, Vec<B>) { | |
let mut aa = vec!(); | |
let mut bb = vec!(); | |
for i in list { | |
match i { | |
Ok(a) => aa.push(a), | |
Err(b) => bb.push(b), | |
}; | |
} | |
(aa, bb) | |
} | |
fn main() { | |
let rows_result: Vec<Result<String, i32>> = | |
vec!(Ok("abc".to_string()), Err(123)); | |
let (rows, row_parse_errors): (Vec<String>, Vec<i32>) = | |
partition(rows_result); | |
assert_eq!(rows, vec!("abc".to_string())); | |
assert_eq!(row_parse_errors, vec!(123)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment