Skip to content

nthAsync

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

Defined in: packages/core/src/iterable/async/nth.ts:20

Returns the element at index, or undefined when the iterable is shorter than that.

The async counterpart of nth. Only counts forward; a negative index would mean buffering the whole tail, so it is rejected.

Time complexity: O(index). The iterator is closed as soon as the element is reached.

T extends DefinedValue

MaybeAsyncIterable<T>

The iterable to read from, sync or async.

number

The zero-based position to read. Must be a non-negative integer.

AbortSignal

Aborts the read.

Promise<T | undefined>

The element at index, or undefined if there is none.

If index is not a non-negative integer.