Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/eitherway/lib/core/result.ts>Results.all

Yet Another Option and Result Implementation - providing safe abstractions for fallible flows inspired by F# and Rust
Latest
function Results.all
import { Results } from "https://deno.land/x/eitherway@0.10.0/lib/core/result.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

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

Parameters

results: Readonly<Iterable<Result<T, E>>>