Skip to content

first

first<T>(iterable): T | undefined

Defined in: packages/core/src/iterable/first.ts:14

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

T cannot itself include undefined, so the absent case is never ambiguous. Use compact first when the source may carry nullish elements.

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

T extends DefinedValue

Iterable<T>

The iterable to read from.

T | undefined

The first element, or undefined if there is none.