Created
June 20, 2022 15:33
-
-
Save Integralist/0f0a549adc4af44167a7222725767eb6 to your computer and use it in GitHub Desktop.
[Rust flatten vector of Results] #rust
This file contains 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
use std::result::Result::{Ok, Err}; | |
fn main() { | |
let v = vec![Ok("foo"), Ok("bar"), Err("whoops"), Ok("baz")]; // Err should be skipped | |
for r in v.into_iter().flatten() { | |
println!("{:#?}", r); | |
} | |
} | |
/* | |
"foo" | |
"bar" | |
"baz" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment