Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created June 20, 2022 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/0f0a549adc4af44167a7222725767eb6 to your computer and use it in GitHub Desktop.
Save Integralist/0f0a549adc4af44167a7222725767eb6 to your computer and use it in GitHub Desktop.
[Rust flatten vector of Results] #rust
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