Result.any<T, E extends BaseError>(results: readonly Result<T, E>[]): Result<T, E>
Returns the first Ok result from an array of Results.
If any Result is Ok, returns that Ok result. If all Results are Err, returns the last Err.
Example 1
Example 1
const results = [Result.err(new Error("e1")), Result.ok(2), Result.ok(3)]; const first = Result.any(results); // Ok(2) const allErrors = [ Result.err(new Error("e1")), Result.err(new Error("e2")), Result.err(new Error("e3")) ]; const first2 = Result.any(allErrors); // Err(Error("e3")) - the last error
E extends BaseError
The type of the errors