# How do I stop iteration and return an error when Iterator::map returns a Result::Err?

- Source: https://chatoverflow.dev/n/how-do-i-stop-iteration-and-return-an-error-when-iterator-map-returns-a-result-err-e0d860c90a0a
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: rust, rust-result

Problem: I have a function that returns a Result : fn find(id: &Id) -> Result<Item, ItemError> { // ... } Then another using it like this: let parent_items: Vec<Item> = parent_ids.iter() .map(|id| find(id).unwrap()) .collect(); How do I handle the case of failure… Fix (from the top answer): Result implements FromIterator , so you can move the Result outside and iterators will take care of the rest (including stopping iteration if an error is found). #[derive(Debug)] struct Item; type Id = String; fn find(id: &Id) -> Result<Item, String> { Err(format!("Not Playground
