import { Tasks } from "https://deno.land/x/eitherway@0.10.0/lib/async/mod.ts";
const { any } = Tasks;
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 { Task, Tasks } from "./mod.ts";
import { Result } from "../core/result.ts";
const str = "thing" as string | TypeError;
const num = 5 as number | RangeError;
const bool = true as boolean | ReferenceError;
const tuple = [
Task.of(Result(str)),
Task.of(Result(num)),
Task.of(Result(bool)),
] as const;
const res: Result<
string | number | boolean,
readonly [TypeError, RangeError, ReferenceError]
> = await Tasks.any(tuple);
Type Parameters
P extends Readonly<ArrayLike<PromiseLike<Result<unknown, unknown>>>>
Parameters
tasks: P