Skip to content

True Myth / result / all

Function: all() ​

Call Signature ​

all(results): Result<[], never>

Given an array of results, return a new Ok result if all results are Ok or a new Err result if some result is Err.

Examples ​

If all results are Ok, return a new Ok result containing an array of all given Ok values:

ts
import Result, { all } from 'true-myth/result';

let result = all([
  Result.ok(10),
  Result.ok(100),
  Result.ok(1000)
]);

console.log(result.toString()); // Ok(10,100,1000)

If any result is Err, return a new Err result containing the first Err encountered:

ts
import Result, { all } from 'true-myth/result';

let result = all([
  Result.ok(10),
  Result.ok("something went wrong"),
  Result.err("something else went wrong")
]);

console.log(result.toString()); // Err(something went wrong)

Parameters ​

results ​

readonly []

The list of results.

Returns ​

Result<[], never>

A new Result containing an array of all Ok values if all results are Ok, or a new Err result containing the first Err encountered.

Call Signature ​

all<A>(results): All<A>

Given an array of results, return a new Ok result if all results are Ok or a new Err result if some result is Err.

Examples ​

If all results are Ok, return a new Ok result containing an array of all given Ok values:

ts
import Result, { all } from 'true-myth/result';

let result = all([
  Result.ok(10),
  Result.ok(100),
  Result.ok(1000)
]);

console.log(result.toString()); // Ok(10,100,1000)

If any result is Err, return a new Err result containing the first Err encountered:

ts
import Result, { all } from 'true-myth/result';

let result = all([
  Result.ok(10),
  Result.ok("something went wrong"),
  Result.err("something else went wrong")
]);

console.log(result.toString()); // Err(something went wrong)

Type Parameters ​

A ​

A extends readonly AnyResult[]

The type of the array or tuple of results.

Parameters ​

results ​

A

The list of results.

Returns ​

All<A>

A new Result containing an array of all Ok values if all results are Ok, or a new Err result containing the first Err encountered.