result
Api Code Documentation / Exports / result
#
Table of contents#
Type aliases#
Functions#
Type aliases#
TypeƬ Type<T
>: Result
<T
>
Type {@link Result} that can either contain a given type T or an Error
#
Type parametersName |
---|
T |
#
Defined in#
Functions#
isErrâ–¸ isErr<T
>(result
): result is Error
Checks if the given result is an error
#
Type parametersName |
---|
T |
#
ParametersName | Type | Description |
---|---|---|
result | Result <T > | an object wrapped in a {@link Result} that might be an error |
#
Returnsresult is Error
a boolean indicating if the given result is an error or not
#
Defined in#
isOkâ–¸ isOk<T
>(result
): result is T
Checks if the given result is Ok
#
Type parametersName |
---|
T |
#
ParametersName | Type | Description |
---|---|---|
result | Result <T > | an object wrapped in a {@link Result} that might be an error |
#
Returnsresult is T
a boolean indicating if the given result is ok or not
#
Defined in#
mapâ–¸ map<T
, U
>(result
, fn
): Result
<U
>
Maps the result to an error or applies the desired function on the result
#
Type parametersName |
---|
T |
U |
#
ParametersName | Type | Description |
---|---|---|
result | Result <T > | an element wrapped in a {@link Result} |
fn | MapFn <T , U > | a callback function that should be applied to the result |
#
ReturnsResult
<U
>
the result of the function or an error
#
Defined in#
mapErrâ–¸ mapErr<T
>(result
, fn
): Result
<T
>
Applies a function to an error or returns the result
#
Type parametersName |
---|
T |
#
ParametersName | Type | Description |
---|---|---|
result | Result <T > | an element wrapped in a {@link Result} |
fn | MapFn <Error , Error > | a callback function that should be applied to the result |
#
ReturnsResult
<T
>
the result of the function if the element is an error or the given element otherwise
#
Defined in#
unwrapâ–¸ unwrap<T
>(result
, message?
): T
| never
Unwraps the result or throws an error
#
Type parametersName |
---|
T |
#
ParametersName | Type | Description |
---|---|---|
result | Result <T > | an element wrapped in a {@link Result} |
message? | string | an optional message to be used when throwing the error |
#
ReturnsT
| never
the unwrapped result
#
Defined in#
unwrapErrâ–¸ unwrapErr<T
>(result
, message?
): Error
| never
Unwraps the error or throws an error
#
Type parametersName |
---|
T |
#
ParametersName | Type | Description |
---|---|---|
result | Result <T > | an element wrapped in a {@link Result} |
message? | string | an optional message to be used when throwing the error |
#
ReturnsError
| never
the unwrapped error if the given element was indeed an error
#
Defined in#
unwrapOrâ–¸ unwrapOr<T
, U
>(result
, defaultValue
): T
| U
Unwraps the result or returns a default value
#
Type parametersName |
---|
T |
U |
#
ParametersName | Type | Description |
---|---|---|
result | Result <T > | an element wrapped in a {@link Result} |
defaultValue | U | default value |
#
ReturnsT
| U
the unwrapped result or the default value in case the given element is an error