Function: unwrapOr()
Call Signature
unwrapOr<
R,ErrReturn>(onErr): (result) =>ErrReturn|UnwrapOk<R>
Defined in: fp.ts:21
Takes the error handler and returns a function that accepts a Result. The returned function unwraps the Result, returning the data for Ok results and handling Err results using the provided error handler.
Type Parameters
R
R extends Result
The input Result type
ErrReturn
ErrReturn
The type returned for Err results
Parameters
onErr
(error) => NonPromise<ErrReturn>
The value or function that determines the value returned for Err results
Returns
A function that takes a Result and returns either the Ok data or the error value
(
result):ErrReturn|UnwrapOk<R>
Parameters
result
NonPromise<R>
Returns
ErrReturn | UnwrapOk<R>
Example
const result1 = pipe(ok("hello"), unwrapOr("default")); // "hello"
const result2 = pipe(err("failed"), unwrapOr("default")); // "default"Call Signature
unwrapOr<
R,ErrReturn>(onErr): (result) =>ErrReturn|UnwrapOk<R>
Defined in: fp.ts:24
Takes the error handler and returns a function that accepts a Result. The returned function unwraps the Result, returning the data for Ok results and handling Err results using the provided error handler.
Type Parameters
R
R extends Result
The input Result type
ErrReturn
ErrReturn
The type returned for Err results
Parameters
onErr
NonPromise<ErrReturn>
The value or function that determines the value returned for Err results
Returns
A function that takes a Result and returns either the Ok data or the error value
(
result):ErrReturn|UnwrapOk<R>
Parameters
result
NonPromise<R>
Returns
ErrReturn | UnwrapOk<R>
Example
const result1 = pipe(ok("hello"), unwrapOr("default")); // "hello"
const result2 = pipe(err("failed"), unwrapOr("default")); // "default"Call Signature
unwrapOr<
R,ErrReturn>(onErr): (result) =>Promise<ErrReturn|UnwrapOk<R>>
Defined in: fp.ts:27
Takes the error handler and returns a function that accepts a Result. The returned function unwraps the Result, returning the data for Ok results and handling Err results using the provided error handler.
Type Parameters
R
R extends OrPromise<Result>
The input Result type
ErrReturn
ErrReturn
The type returned for Err results
Parameters
onErr
OrFunction<OrPromise<ErrReturn>, [UnwrapErr<R>]>
The value or function that determines the value returned for Err results
Returns
A function that takes a Result and returns either the Ok data or the error value
(
result):Promise<ErrReturn|UnwrapOk<R>>
Parameters
result
R
Returns
Promise<ErrReturn | UnwrapOk<R>>
Example
const result1 = pipe(ok("hello"), unwrapOr("default")); // "hello"
const result2 = pipe(err("failed"), unwrapOr("default")); // "default"