Skip to content

results-ts


results-ts / AsyncOption

Interface: AsyncOption<T> ​

Defined in: async-option.ts:19

An awaitable wrapper around Option<T> with chainable methods.

and, or, xor, and zip accept sync or promise-like operands. Async operands resolve concurrently with the receiver. Either rejection propagates.

AsyncOption omits insert, getOrInsert, getOrInsertWith, getOrInsertWithAsync, take, takeIf, and replace. Await the wrapper to get an Option, then call its mutation methods.

Methods that throw on Option reject on AsyncOption. For example, unwrap rejects on None, and flatten rejects a non-nested value.

Extends ​

Type Parameters ​

T ​

T

Methods ​

and() ​

and<U>(optb): AsyncOption<U>

Defined in: async-option.ts:139

Returns None if the option is None, otherwise returns optb.

Type Parameters ​

U ​

U

Parameters ​

optb ​

Option<U> | PromiseLike<Option<U>>

Returns ​

AsyncOption<U>


andThen() ​

andThen<U>(f): AsyncOption<U>

Defined in: async-option.ts:144

Returns None if the option is None, otherwise calls f with the wrapped value and returns the result.

Type Parameters ​

U ​

U

Parameters ​

f ​

(val) => Option<U>

Returns ​

AsyncOption<U>


andThenAsync() ​

andThenAsync<U>(f): AsyncOption<U>

Defined in: async-option.ts:149

Async version of andThen. Returns None if the option is None, otherwise calls async f with the wrapped value and returns the result.

Type Parameters ​

U ​

U

Parameters ​

f ​

(val) => PromiseLike<Option<U>>

Returns ​

AsyncOption<U>


expect() ​

expect(msg): Promise<T>

Defined in: async-option.ts:51

Returns the contained Some value.

Parameters ​

msg ​

string

Returns ​

Promise<T>

Throws ​

Rejects with PanicError if the value is a None with a custom panic message provided by msg.


filter() ​

filter(predicate): AsyncOption<T>

Defined in: async-option.ts:156

Returns None if the option is None, otherwise calls predicate with the wrapped value and returns:

  • Some(t) if predicate returns true (where t is the wrapped value), and
  • None if predicate returns false.

Parameters ​

predicate ​

(val) => boolean

Returns ​

AsyncOption<T>


filterAsync() ​

filterAsync(predicate): AsyncOption<T>

Defined in: async-option.ts:163

Async version of filter. Returns None if the option is None, otherwise calls async predicate with the wrapped value and returns:

  • Some(t) if predicate resolves to true (where t is the wrapped value), and
  • None if predicate resolves to false.

Parameters ​

predicate ​

(val) => PromiseLike<boolean>

Returns ​

AsyncOption<T>


flatten() ​

flatten<U>(this): AsyncOption<U>

Defined in: async-option.ts:191

Converts from AsyncOption<Option<T>> to AsyncOption<T>.

Async note: If the inner value is not an Option, this produces a rejected Promise with FlattenError rather than a synchronous throw.

Type Parameters ​

U ​

U

Parameters ​

this ​

AsyncOption<Option<U>>

Returns ​

AsyncOption<U>


inspect() ​

inspect(f): AsyncOption<T>

Defined in: async-option.ts:90

Calls f with the Some value and returns the original option.

Returns the original option.

Parameters ​

f ​

(val) => void

Returns ​

AsyncOption<T>


inspectAsync() ​

inspectAsync(f): AsyncOption<T>

Defined in: async-option.ts:95

Awaits f with the Some value and returns the original option.

Parameters ​

f ​

(val) => PromiseLike<void>

Returns ​

AsyncOption<T>


isNone() ​

isNone(): Promise<boolean>

Defined in: async-option.ts:39

Returns a Promise that resolves to true if the option is a None value.

Returns ​

Promise<boolean>


isNoneOr() ​

isNoneOr(f): Promise<boolean>

Defined in: async-option.ts:44

Returns a Promise that resolves to true if the option is a None or its value matches the predicate.

Parameters ​

f ​

(val) => boolean

Returns ​

Promise<boolean>


isSome() ​

isSome(): Promise<boolean>

Defined in: async-option.ts:29

Returns a Promise that resolves to true if the option is a Some value.

Returns ​

Promise<boolean>


isSomeAnd() ​

isSomeAnd(f): Promise<boolean>

Defined in: async-option.ts:34

Returns a Promise that resolves to true if the option is a Some and its value matches the predicate.

Parameters ​

f ​

(val) => boolean

Returns ​

Promise<boolean>


iter() ​

iter(): AsyncIterableIterator<Awaited<T>, undefined, unknown>

Defined in: async-option.ts:134

Returns an async iterator that yields the Some value once, or nothing for None. Promise-like payloads are awaited. Source and payload rejections propagate.

Returns ​

AsyncIterableIterator<Awaited<T>, undefined, unknown>


map() ​

map<U>(f): AsyncOption<U>

Defined in: async-option.ts:78

Maps an AsyncOption<T> to AsyncOption<U> by applying a function to a contained value.

Type Parameters ​

U ​

U

Parameters ​

f ​

(val) => U

Returns ​

AsyncOption<U>


mapAsync() ​

mapAsync<U>(f): AsyncOption<U>

Defined in: async-option.ts:83

Async version of map. Maps an AsyncOption<T> to AsyncOption<U> by applying an async function to a contained value.

Type Parameters ​

U ​

U

Parameters ​

f ​

(val) => PromiseLike<U>

Returns ​

AsyncOption<U>


mapOr() ​

mapOr<U>(defaultVal, f): Promise<U>

Defined in: async-option.ts:100

Returns the fallback on None, or calls f with the Some value.

Type Parameters ​

U ​

U

Parameters ​

defaultVal ​

U

f ​

(val) => U

Returns ​

Promise<U>


mapOrElse() ​

mapOrElse<U>(defaultF, f): Promise<U>

Defined in: async-option.ts:105

Calls defaultF on None, or calls f with the Some value.

Type Parameters ​

U ​

U

Parameters ​

defaultF ​

() => U

f ​

(val) => U

Returns ​

Promise<U>


mapOrElseAsync() ​

mapOrElseAsync<U>(defaultF, f): Promise<U>

Defined in: async-option.ts:110

Awaits defaultF on None, or awaits f with the Some value.

Type Parameters ​

U ​

U

Parameters ​

defaultF ​

() => PromiseLike<U>

f ​

(val) => PromiseLike<U>

Returns ​

Promise<U>


match() ​

match<U>(handlers): Promise<U>

Defined in: async-option.ts:219

Matches the Option with two functions, one for each variant.

Type Parameters ​

U ​

U

Parameters ​

handlers ​
None ​

() => U

Some ​

(val) => U

Returns ​

Promise<U>


okOr() ​

okOr<E>(err): AsyncResult<T, E>

Defined in: async-option.ts:118

Transforms the AsyncOption<T> into an AsyncResult<T, E>, mapping Some(v) to Ok(v) and None to Err(err).

Type Parameters ​

E ​

E

Parameters ​

err ​

E

Returns ​

AsyncResult<T, E>


okOrElse() ​

okOrElse<E>(errF): AsyncResult<T, E>

Defined in: async-option.ts:123

Transforms the AsyncOption<T> into an AsyncResult<T, E>, mapping Some(v) to Ok(v) and None to Err(err()).

Type Parameters ​

E ​

E

Parameters ​

errF ​

() => E

Returns ​

AsyncResult<T, E>


okOrElseAsync() ​

okOrElseAsync<E>(errF): AsyncResult<T, E>

Defined in: async-option.ts:128

Async version of okOrElse. Transforms the AsyncOption<T> into an AsyncResult<T, E>, mapping Some(v) to Ok(v) and None to Err(await errF()).

Type Parameters ​

E ​

E

Parameters ​

errF ​

() => PromiseLike<E>

Returns ​

AsyncResult<T, E>


or() ​

or<T2>(optb): AsyncOption<T | T2>

Defined in: async-option.ts:168

Returns the option if it contains a value, otherwise returns optb.

Type Parameters ​

T2 ​

T2

Parameters ​

optb ​

Option<T2> | PromiseLike<Option<T2>>

Returns ​

AsyncOption<T | T2>


orElse() ​

orElse<T2>(f): AsyncOption<T | T2>

Defined in: async-option.ts:173

Returns the option if it contains a value, otherwise calls f and returns the result.

Type Parameters ​

T2 ​

T2

Parameters ​

f ​

() => Option<T2>

Returns ​

AsyncOption<T | T2>


orElseAsync() ​

orElseAsync<T2>(f): AsyncOption<T | T2>

Defined in: async-option.ts:178

Async version of orElse. Returns the option if it contains a value, otherwise calls async f and returns the result.

Type Parameters ​

T2 ​

T2

Parameters ​

f ​

() => PromiseLike<Option<T2>>

Returns ​

AsyncOption<T | T2>


toString() ​

toString(): Promise<string>

Defined in: async-option.ts:24

Resolves to the contained option's string representation. Call with await option.toString(); implicit string conversion does not await it.

Returns ​

Promise<string>


transpose() ​

transpose<T, E>(this): AsyncResult<Option<T>, E>

Defined in: async-option.ts:199

Transposes an AsyncOption of a Result into an AsyncResult of an Option.

Async note: If the inner value is not a Result, this produces a rejected Promise with TransposeError rather than a synchronous throw.

Type Parameters ​

T ​

T

E ​

E

Parameters ​

this ​

AsyncOption<Result<T, E>>

Returns ​

AsyncResult<Option<T>, E>


unwrap() ​

unwrap(): Promise<T>

Defined in: async-option.ts:58

Returns the contained Some value.

Returns ​

Promise<T>

Throws ​

Rejects with PanicError if the self value equals None.


unwrapOr() ​

unwrapOr(defaultVal): Promise<T>

Defined in: async-option.ts:63

Returns the contained Some value or a provided default.

Parameters ​

defaultVal ​

T

Returns ​

Promise<T>


unwrapOrElse() ​

unwrapOrElse(f): Promise<T>

Defined in: async-option.ts:68

Returns the contained Some value, or calls f on None.

Parameters ​

f ​

() => T

Returns ​

Promise<T>


unwrapOrElseAsync() ​

unwrapOrElseAsync(f): Promise<T>

Defined in: async-option.ts:73

Returns the Some value, or awaits f on None.

Parameters ​

f ​

() => PromiseLike<T>

Returns ​

Promise<T>


unzip() ​

unzip<T, U>(this): [AsyncOption<T>, AsyncOption<U>]

Defined in: async-option.ts:214

Unzips an AsyncOption containing a tuple of two values.

Returns two async options. They resolve to Some(a) and Some(b) for Some([a, b]), or both resolve to None for None.

Type Parameters ​

T ​

T

U ​

U

Parameters ​

this ​

AsyncOption<[T, U]>

Returns ​

[AsyncOption<T>, AsyncOption<U>]


xor() ​

xor<T2>(optb): AsyncOption<T | T2>

Defined in: async-option.ts:183

Returns Some if exactly one of this, optb is Some, otherwise returns None.

Type Parameters ​

T2 ​

T2

Parameters ​

optb ​

Option<T2> | PromiseLike<Option<T2>>

Returns ​

AsyncOption<T | T2>


zip() ​

zip<U>(other): AsyncOption<[T, U]>

Defined in: async-option.ts:206

Combines the resolved option with another option into a tuple of their values.

Resolves to Some([a, b]) if both options are Some, otherwise resolves to None.

Type Parameters ​

U ​

U

Parameters ​

other ​

Option<U> | PromiseLike<Option<U>>

Returns ​

AsyncOption<[T, U]>