use orx_parallel::*;
fn parse_line_total(row: &str) -> Result<usize, String> {
let mut parts = row.split(',');
let qty = parts
.next()
.ok_or("missing quantity")?
.parse::<usize>()
.map_err(|_| "invalid quantity".to_string())?;
let unit_price = parts
.next()
.ok_or("missing unit price")?
.parse::<usize>()
.map_err(|_| "invalid unit price".to_string())?;
Ok(qty * unit_price)
}
fn main() {
let good_rows = vec!["2,1500", "1,2300", "4,499", "5,1100"];
let total = good_rows
.par()
.map(|row| parse_line_total(row))
.into_fallible()
.filter(|line_total| *line_total >= 2_000)
.sum();
assert_eq!(total, Ok(2 * 1500 + 2300 + 5 * 1100));
let bad_rows = vec!["2,1500", "1,2300", "x,499", "5,1100"];
let total = bad_rows
.par()
.map(|row| parse_line_total(row))
.into_fallible()
.filter(|line_total| *line_total >= 2_000)
.sum();
assert!(total.is_err());
}