Skip to content

firstAsync

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

Defined in: packages/core/src/iterable/async/first.ts:16

Returns the first element, or undefined when the iterable is empty.

The async counterpart of first. T cannot itself include undefined, so the absent case is never ambiguous.

Time complexity: O(1). The iterator is closed without being drained.

T extends DefinedValue

MaybeAsyncIterable<T>

The iterable to read from, sync or async.

AbortSignal

Aborts the read.

Promise<T | undefined>

The first element, or undefined if there is none.