API reference@evolu/commonResult › anyResult

function anyResult<T>(
  results: T,
): Result<InferOk<T[number]>, InferErr<T[number]>>;

Defined in: packages/common/src/Result.ts:751

Returns the first successful Result.

If all results fail, returns the last error.

Requires a non-empty array — there's no "first success" with zero participants. Use isNonEmptyArray to guard:

if (isNonEmptyArray(results)) {
  const result = anyResult(results);
}

Example

const results = [err("fail1"), ok(42), err("fail2")];
if (isNonEmptyArray(results)) {
  const result = anyResult(results);
  // ok(42)
}

const allFailed = [err("a"), err("b"), err("c")];
if (isNonEmptyArray(allFailed)) {
  const result = anyResult(allFailed);
  // err("c") — last error
}