Result type operations. auto-imported.
Transform the ok value using a function. If err, passes through unchanged.
result.map(ok(2), fn(x) => x * 10)
Transform the err value using a function. If ok, passes through unchanged.
result.map_err(err("fail"), fn(e) => "wrapped: " ++ e)
Chain a Result-returning function on the ok value. Flattens nested Results.
result.and_then(ok(5), fn(x) => if x > 0 then ok(x) else err("negative"))
Get the ok value, or return a default if err.
result.unwrap_or(err("fail"), 0)
Get the ok value, or compute a default from the error using a function.
result.unwrap_or_else(err("fail"), fn(e) => string.len(e))
Check if the Result is ok.
result.is_ok(ok(42))
Check if the Result is err.
result.is_err(err("fail"))
Convert ok to some, err to none. Discards the error value.
result.to_option(ok(42))
Convert err to some, ok to none. Discards the ok value.
result.to_err_option(err("fail"))
Collect a list of Results. All ok → ok(values), any err → err(all_errors).
result.collect([ok(1), ok(2), ok(3)]) // => ok([1, 2, 3])
Partition a list of Results into ok values and err values.
result.partition([ok(1), err("x"), ok(2)]) // => ([1, 2], ["x"])
Map a function over a list and collect Results. All ok → ok(values), any err → err(all_errors).
result.collect_map([1, 2, 3], fn(x) => if x > 0 then ok(x) else err("neg"))