std-method
Iterator::find_map — search and transform
Run a transformation until it yields Some. This fits inputs where only the first successful conversion is needed. Expected stdout (not executed): Some(24) Common mistake: Assuming conversion failures are returned as Result errors.
Formal Syntax & Structure
rust syntaxrust
fn find_map<B, F>(&mut self, f: F) -> Option<B> where Self: Sized, F: FnMut(Self::Item) -> Option<B>Working Example
Example Snippetrust
fn main() { let first = ["unknown", "24", "30"].into_iter().find_map(|s| s.parse::<u32>().ok()); println!("{first:?}");}