pub(crate) fn try_fold_ordered<T: Send, A: Send, E: Send>(
items: Vec<T>,
parallel: bool,
identity: impl Fn() -> A + Sync + Send,
fold: impl Fn(A, usize, T) -> Result<A, E> + Sync + Send,
combine: impl Fn(A, A) -> A + Sync + Send,
) -> Result<A, E>Expand description
Fold items into one result whose bits do not depend on the thread count.
The items are split into at most REDUCTION_CHUNKS consecutive chunks, with
boundaries set by the number of items alone. Each chunk folds its items in index
order from identity(), with fold(partial, index, item), and the chunk results
are combined in chunk order with combine(left, right), starting from the first
chunk’s result. The calling thread runs the same chunks when parallel is false
or the budget is one thread, so every schedule adds the same partial results in
the same order; one chunk reproduces a plain sequential fold.
The error is that of the first failing item in index order, as in a sequential loop.