Skip to main content

Module: result/src

Interfaces

Type aliases

Maybe

Ƭ Maybe<T>: Some<T> | None

A type used to express a value that may or may not exist.

Type parameters

NameDescription
TThe value's type.

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:7


Option

Ƭ Option<T>: Some<T> | None

license MIT

copyright 2020 1Computer

A type that can express the lack of a value. Used in this library for when a generic type could be nullable.

Type parameters

NameDescription
TType of results.

Defined in

projects/utilities/packages/result/src/lib/Lexure.ts:51


Result

Ƭ Result<T, E>: Ok<T> | Err<E>

A type used to express computations that can fail.

Type parameters

NameDescription
TThe result's type.
EThe error's type.

Defined in

projects/utilities/packages/result/src/lib/Result.ts:8


UnwrapMaybeValue

Ƭ UnwrapMaybeValue<T>: T extends Some<infer V> ? V : never

Type parameters

NameType
Textends Maybe<unknown>

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:92

Functions

err

err(): Err<unknown>

Creates an Err with no error.

Returns

Err<unknown>

An erroneous Result.

Defined in

projects/utilities/packages/result/src/lib/Result.ts:31

err<E>(x): Err<E>

Creates an Err.

Type parameters

NameDescription
EThe error's type.

Parameters

NameTypeDescription
xEValue to use.

Returns

Err<E>

An erroneous Result.

Defined in

projects/utilities/packages/result/src/lib/Result.ts:39


from

from<T, E>(cb): Result<T, E>

Creates a Result out of a callback.

Type parameters

NameTypeDescription
TTThe result's type.
EunknownThe error's type.

Parameters

NameType
cb(...args: unknown[]) => T

Returns

Result<T, E>

Defined in

projects/utilities/packages/result/src/lib/Parsers.ts:8


fromAsync

fromAsync<T, E>(promiseOrCb): Promise<Result<T, E>>

Creates a Result out of a promise or async callback.

Type parameters

NameTypeDescription
TTThe result's type.
EunknownThe error's type.

Parameters

NameType
promiseOrCbAwaitable<T> | (...args: unknown[]) => Awaitable<T>

Returns

Promise<Result<T, E>>

Defined in

projects/utilities/packages/result/src/lib/Parsers.ts:21


isErr

isErr<T, E>(x): x is Err<E>

Determines whether or not a result is an Err.

Type parameters

NameDescription
TThe result's type.
EThe error's type.

Parameters

NameType
xResult<T, E>

Returns

x is Err<E>

Defined in

projects/utilities/packages/result/src/lib/Result.ts:58


isMaybe

isMaybe<T>(x): true

Type-safe helper to preserve the type parameter's type.

Type parameters

Name
T

Parameters

NameTypeDescription
xMaybe<T>The value to check.

Returns

true

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:81

isMaybe<T>(x): x is Maybe<T>

Determines whether or not an arbitrary value is a Maybe.

Type parameters

Name
T

Parameters

NameTypeDescription
xunknownThe value to check.

Returns

x is Maybe<T>

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:87


isNone

isNone<T>(x): x is None

Determines whether or not a Maybe is a None.

Type parameters

NameDescription
TThe value's type.

Parameters

NameType
xMaybe<T>

Returns

x is None

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:73


isOk

isOk<T, E>(x): x is Ok<T>

Determines whether or not a result is an Ok.

Type parameters

NameDescription
TThe result's type.
EThe error's type.

Parameters

NameType
xResult<T, E>

Returns

x is Ok<T>

Defined in

projects/utilities/packages/result/src/lib/Result.ts:49


isSome

isSome<T>(x): x is Some<T>

Determines whether or not a Maybe is a Some.

Type parameters

NameDescription
TThe value's type.

Parameters

NameType
xMaybe<T>

Returns

x is Some<T>

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:65


maybe

maybe<T, V>(value): V

Returns the maybe itself.

Type parameters

NameType
TT
Vextends Maybe<T>

Parameters

NameTypeDescription
valueVThe value to convert.

Returns

V

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:13

maybe(value): None

Creates a None from an existing None or a null.

Parameters

NameTypeDescription
valuenull | NoneThe value to convert.

Returns

None

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:19

maybe<T>(value): Maybe<T>

Creates a Some from a non-null value or an existing Some, or a None otherwise.

Type parameters

Name
T

Parameters

NameTypeDescription
valuenull | T | Maybe<T>The value to convert.

Returns

Maybe<T>

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:25

maybe<T>(value): Some<T>

Creates a Some from a non-null value or an existing Some.

Type parameters

Name
T

Parameters

NameTypeDescription
valueT | Some<T>The value to convert.

Returns

Some<T>

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:31


none

none(): None

Creates a None value.

Returns

None

A non-existing Maybe.

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:57


ok

ok(): Ok<unknown>

Creates an Ok with no value.

Returns

Ok<unknown>

A successful Result.

Defined in

projects/utilities/packages/result/src/lib/Result.ts:14

ok<T>(x): Ok<T>

Creates an Ok.

Type parameters

NameDescription
TThe result's type.

Parameters

NameTypeDescription
xTValue to use.

Returns

Ok<T>

A successful Result.

Defined in

projects/utilities/packages/result/src/lib/Result.ts:22


some

some(): Some<unknown>

Creates a None with no value.

Returns

Some<unknown>

An existing Maybe.

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:40

some<T>(x): Some<T>

Creates a None with a value.

Type parameters

NameDescription
TThe value's type.

Parameters

NameTypeDescription
xTValue to use.

Returns

Some<T>

An existing Maybe.

Defined in

projects/utilities/packages/result/src/lib/Maybe.ts:48