Skip to content

oneAsync

oneAsync<T>(iterable, description?, signal?): Promise<T | undefined>

Defined in: packages/core/src/iterable/async/one.ts:21

Returns the single element of an iterable, or undefined when it is empty, rejecting any larger count.

The async counterpart of one, and the tolerant half of the pair onlyAsync completes.

Time complexity: O(1) — at most two elements are pulled, so this is safe on an endless stream.

T extends DefinedValue

MaybeAsyncIterable<T>

The iterable to read from, sync or async.

string = "item"

What the iterable holds, used in the error message.

AbortSignal

Aborts the read.

Promise<T | undefined>

The single element, or undefined if there is none.

If the iterable holds more than one element.