Skip to main content

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 parameters#

Name
T

Defined in#

src/result.ts:11

Functions#

isErr#

isErr<T>(result): result is Error

Checks if the given result is an error

Type parameters#

Name
T

Parameters#

NameTypeDescription
resultResult<T>an object wrapped in a {@link Result} that might be an error

Returns#

result is Error

a boolean indicating if the given result is an error or not

Defined in#

src/result.ts:19


isOk#

isOk<T>(result): result is T

Checks if the given result is Ok

Type parameters#

Name
T

Parameters#

NameTypeDescription
resultResult<T>an object wrapped in a {@link Result} that might be an error

Returns#

result is T

a boolean indicating if the given result is ok or not

Defined in#

src/result.ts:29


map#

map<T, U>(result, fn): Result<U>

Maps the result to an error or applies the desired function on the result

Type parameters#

Name
T
U

Parameters#

NameTypeDescription
resultResult<T>an element wrapped in a {@link Result}
fnMapFn<T, U>a callback function that should be applied to the result

Returns#

Result<U>

the result of the function or an error

Defined in#

src/result.ts:44


mapErr#

mapErr<T>(result, fn): Result<T>

Applies a function to an error or returns the result

Type parameters#

Name
T

Parameters#

NameTypeDescription
resultResult<T>an element wrapped in a {@link Result}
fnMapFn<Error, Error>a callback function that should be applied to the result

Returns#

Result<T>

the result of the function if the element is an error or the given element otherwise

Defined in#

src/result.ts:59


unwrap#

unwrap<T>(result, message?): T | never

Unwraps the result or throws an error

Type parameters#

Name
T

Parameters#

NameTypeDescription
resultResult<T>an element wrapped in a {@link Result}
message?stringan optional message to be used when throwing the error

Returns#

T | never

the unwrapped result

Defined in#

src/result.ts:74


unwrapErr#

unwrapErr<T>(result, message?): Error | never

Unwraps the error or throws an error

Type parameters#

Name
T

Parameters#

NameTypeDescription
resultResult<T>an element wrapped in a {@link Result}
message?stringan optional message to be used when throwing the error

Returns#

Error | never

the unwrapped error if the given element was indeed an error

Defined in#

src/result.ts:93


unwrapOr#

unwrapOr<T, U>(result, defaultValue): T | U

Unwraps the result or returns a default value

Type parameters#

Name
T
U

Parameters#

NameTypeDescription
resultResult<T>an element wrapped in a {@link Result}
defaultValueUdefault value

Returns#

T | U

the unwrapped result or the default value in case the given element is an error

Defined in#

src/result.ts:108