True Myth / result / transposeAny
Function: transposeAny()
Call Signature
transposeAny(
results
):Result
<[],never
>
Given an array of results, return a new Ok
result if any of the results is Ok
, or a new Err
result if all the results are Err
.
Examples
When any result is Ok
, return a new Ok
result containing the value of the first Ok
result:
import { any } from 'true-myth/result';
let result = any([
Result.err("something went wrong"),
Result.ok(10),
Result.err("something else went wrong")
]);
console.log(result.toString()); // Ok(10);
When all results are Err
, return a new Err
result containing an array of all Err
encountered:
import { any } from 'true-myth/result';
let result = any([
Result.err("something went wrong"),
Result.err("something else went wrong"),
Result.err("even more went wrong")
]);
console.log(result.toString()); // Err(something went wrong,something else went wrong,even more went wrong)
Parameters
results
[]
The list of results to check.
Returns
Result
<[], never
>
A new Result
containing the value of the first Ok
result if any results are Ok
, or a new Err
result containing an array of all Err
encountered if all results are Err
.
Call Signature
transposeAny<
A
>(results
):Result
<{ -readonly [P in string | number | symbol]: OkFor<A[P<P>]> }, [...{ -readonly [P in string | number | symbol]: ErrFor<A[P<P>]> }[]]>
Given an array of results, return a new Ok
result if any of the results is Ok
, or a new Err
result if all the results are Err
.
Examples
When any result is Ok
, return a new Ok
result containing the value of the first Ok
result:
import { any } from 'true-myth/result';
let result = any([
Result.err("something went wrong"),
Result.ok(10),
Result.err("something else went wrong")
]);
console.log(result.toString()); // Ok(10);
When all results are Err
, return a new Err
result containing an array of all Err
encountered:
import { any } from 'true-myth/result';
let result = any([
Result.err("something went wrong"),
Result.err("something else went wrong"),
Result.err("even more went wrong")
]);
console.log(result.toString()); // Err(something went wrong,something else went wrong,even more went wrong)
Type Parameters
A
A
extends AnyResult
[]
The type of the array or tuple of tasks.
Parameters
results
A
The list of results to check.
Returns
Result
<{ -readonly [P in string | number | symbol]: OkFor<A[P<P>]> }, [...{ -readonly [P in string | number | symbol]: ErrFor<A[P<P>]> }[]]>
A new Result
containing the value of the first Ok
result if any results are Ok
, or a new Err
result containing an array of all Err
encountered if all results are Err
.