Function: toTuple()
Call Signature
toTuple<
R
>(result
):ResultTuple
<R
>
Defined in: index.ts:773
Transforms the result into a tuple where the first value is data (for successful results) and the second value is error (for error results). Useful when you want to safely unwrap a result without additional unwrapping logic.
Type Parameters
R
R
extends Result
<any
, any
>
The input Result type
Parameters
result
NonPromise
<R
>
The Result to match on
Returns
ResultTuple
<R
>
A tuple with unwrapped result data and error
Example
function divide(a: number, b: number) {
return b === 0 ? err('division_by_zero') : ok(a / b);
}
const [data, error] = toTuple(divide(10, 2));
if (!error) {
console.log(`Division result is: ${data}`);
}
Call Signature
toTuple<
R
>(result
):Promise
<ResultTuple
<R
>>
Defined in: index.ts:774
Transforms the result into a tuple where the first value is data (for successful results) and the second value is error (for error results). Useful when you want to safely unwrap a result without additional unwrapping logic.
Type Parameters
R
R
extends Result
<any
, any
>
The input Result type
Parameters
result
OrPromise
<R
>
The Result to match on
Returns
Promise
<ResultTuple
<R
>>
A tuple with unwrapped result data and error
Example
function divide(a: number, b: number) {
return b === 0 ? err('division_by_zero') : ok(a / b);
}
const [data, error] = toTuple(divide(10, 2));
if (!error) {
console.log(`Division result is: ${data}`);
}