import { Results } from "https://deno.land/x/eitherway@0.10.0/lib/core/result.ts";
const { any } = Results;
Use this to obtain the first found Ok<T>
from an Array<Result<T,E>>
or
Iterable<Result<T,E>>
.
If no Ok<T>
value is found, the Err<E>
values are collected into an
array and returned.
This function also works on variadic tuples and preserves the individual types of the tuple members.
Examples
Example 1
Example 1
import { assert } from "./assert.ts";
import { Result, Results } from "./mod.ts";
const str = "thing" as string | TypeError;
const num = 5 as number | RangeError;
const bool = true as boolean | ReferenceError;
const tuple = [ Result(str), Result(num), Result(bool) ] as const;
const res: Result<
string | number | boolean,
readonly [TypeError, RangeError, ReferenceError]
> = Results.any(tuple);
assert(res.isOk());
Type Parameters
R extends Readonly<ArrayLike<Result<unknown, unknown>>>
Parameters
results: R