Skip to main content

parallel_try_collect

Function parallel_try_collect 

Source
pub fn parallel_try_collect<T, E, I, F, R>(
    items: I,
    process: F,
) -> (Vec<R>, Vec<E>)
where T: Send, E: Send, R: Send, I: ParallelIterator<Item = T>, F: Fn(T) -> Result<R, E> + Sync + Send,
Expand description

Collect results with errors separated.

Processes items in parallel, collecting successful results and errors into separate vectors. This is useful for batch operations where you want to continue processing even if some items fail.

ยงExample

use grafeo_core::execution::parallel::fold::parallel_try_collect;
use rayon::prelude::*;

let items = vec!["1", "two", "3", "four"];
let (successes, errors) = parallel_try_collect(
    items.into_par_iter(),
    |s| s.parse::<i32>().map_err(|e| e.to_string()),
);

assert_eq!(successes.len(), 2);
assert_eq!(errors.len(), 2);