collectResults
Combine an array of Results into one Result. If every item succeeds, return its values in order. Otherwise return the original first failure in input order. Inspired by Rust's Iterator::collect into Result<Vec<T>, E>.
Usage
collectResults(results)
Parameters
The already-created Results to combine. Accepts readonly arrays and does not mutate inputs.
Returns
Result<T[], E>. Success creates a new array, preserving value references and order. Failure returns the first Err by reference, preserving its original error and custom fields. Distinct value and error types are inferred as unions; this helper does not preserve tuple positions or accept records.
Errors and partial successes
The output contains neither partial successes nor later errors. The input remains unchanged. Use partitionResults if every success and every error matters, such as validating imported rows.
Collection is not execution
map has already called parseRow for every row before collection starts. This helper cannot cancel that work or prevent exceptions thrown while creating the input. Use attempt at throwing boundaries. To stop running later operations after a failure, sequence individual Results with andThen instead.
Promises are not awaited. For independent asynchronous operations, await their Results first, for example collectResults(await Promise.all(tasks)); all tasks may already be running.
See also
partitionResults— retain every success and errorandThen— sequence dependent fallible operations- Result & Errors