Handle fallible computations with `into_optional()` and `into_fallible()`
mainThe library provides first-class support for fallible parallel flows. You can transform a pipeline to handle Option<T> or Result<T, E> types, allowing you to write only the success path. Any failure in the pipeline will cause an early exit (short-circuiting).
- Use
.into_optional()forOption<T>pipelines. - Use
.into_fallible()forResult<T, E>pipelines.
use orx_parallel::*;
fn total_price(rows: &[&str]) -> Option<u64> {
rows.par()
.map(|row| parse_qty_and_price(row)) // ← some might return None
.into_optional() // ← ascend
.filter(|(qty, _)| *qty >= 2) // ← focus only on success path
.map(|(qty, unit_price)| qty * unit_price) // ← success path
.sum()
}