import { Results } from "https://deno.land/x/eitherway@0.10.0/lib/core/mod.ts";
const { all } = Results;
Use this to collect all Ok<T>
values from an Array<Result<T,E>>
or
Iterable<Result<T,E>>
into an Ok<T[]>
.
Upon encountring the first Err<E>
value, this value is 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<
readonly [string, number, boolean],
TypeError | RangeError | ReferenceError
> = Results.all(tuple);
assert(res.isOk());
Type Parameters
R extends Readonly<ArrayLike<Result<unknown, unknown>>>
Parameters
results: R