one
one<
T>(iterable):T|undefined
Defined in: packages/core/src/iterable/one.ts:18
Returns the single element of an iterable, or undefined when it is empty,
rejecting any larger count.
The tolerant half of the pair only completes: both reject two or more, and
only this one accepts none. T cannot itself include undefined, so the
empty case is never ambiguous.
Time complexity: O(1) — at most two elements are pulled, so this is safe on an infinite iterable.
Type Parameters
Section titled “Type Parameters”T extends DefinedValue
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The iterable to read from.
Returns
Section titled “Returns”T | undefined
The single element, or undefined if there is none.
Throws
Section titled “Throws”If the iterable holds more than one element.