Function: unwrapOr()
Call Signature
unwrapOr<
R
,ErrReturn
>(result
,onErr
):ErrReturn
|UnwrapOk
<R
>
Defined in: index.ts:373
Unwraps a Result, returning the data for Ok results and handling Err results in a provided way. The second argument can be a static value or a function that receives the error and returns a value.
Type Parameters
R
R
extends Result
<any
, any
>
Type of the Result to unwrap
ErrReturn
ErrReturn
Type of the value returned for Err results
Parameters
result
NonPromise
<R
>
The Result to unwrap
onErr
(error
) => NonPromise
<ErrReturn
>
The value or function that determines the value returned for Err results
Returns
ErrReturn
| UnwrapOk
<R
>
Data from the Ok result or provided/computed value for Err results
Example
unwrapOr(ok("hello"), "default"); // "hello"
unwrapOr(err("error"), "default"); // "default"
unwrapOr(err("error"), (error) => `Failed: ${error}`); // "Failed: error"
unwrapOr(Promise.resolve(err("error")), "default"); // Promise<"default">
Call Signature
unwrapOr<
R
,ErrReturn
>(result
,onErr
):ErrReturn
|UnwrapOk
<R
>
Defined in: index.ts:377
Unwraps a Result, returning the data for Ok results and handling Err results in a provided way. The second argument can be a static value or a function that receives the error and returns a value.
Type Parameters
R
R
extends Result
<any
, any
>
Type of the Result to unwrap
ErrReturn
ErrReturn
Type of the value returned for Err results
Parameters
result
NonPromise
<R
>
The Result to unwrap
onErr
NonPromise
<ErrReturn
>
The value or function that determines the value returned for Err results
Returns
ErrReturn
| UnwrapOk
<R
>
Data from the Ok result or provided/computed value for Err results
Example
unwrapOr(ok("hello"), "default"); // "hello"
unwrapOr(err("error"), "default"); // "default"
unwrapOr(err("error"), (error) => `Failed: ${error}`); // "Failed: error"
unwrapOr(Promise.resolve(err("error")), "default"); // Promise<"default">
Call Signature
unwrapOr<
R
,ErrReturn
>(result
,onErr
):Promise
<ErrReturn
|UnwrapOk
<R
>>
Defined in: index.ts:381
Unwraps a Result, returning the data for Ok results and handling Err results in a provided way. The second argument can be a static value or a function that receives the error and returns a value.
Type Parameters
R
R
extends OrPromise
<Result
<any
, any
>>
Type of the Result to unwrap
ErrReturn
ErrReturn
Type of the value returned for Err results
Parameters
result
R
The Result to unwrap
onErr
OrFunction
<OrPromise
<ErrReturn
>, [UnwrapErr
<R
>]>
The value or function that determines the value returned for Err results
Returns
Promise
<ErrReturn
| UnwrapOk
<R
>>
Data from the Ok result or provided/computed value for Err results
Example
unwrapOr(ok("hello"), "default"); // "hello"
unwrapOr(err("error"), "default"); // "default"
unwrapOr(err("error"), (error) => `Failed: ${error}`); // "Failed: error"
unwrapOr(Promise.resolve(err("error")), "default"); // Promise<"default">