only
only<
T>(iterable):T
Defined in: packages/core/src/iterable/only.ts:14
Returns the single element of an iterable, rejecting any other count.
Boundary validation, and the readable form of items.length === 1 ? items[0] : throw. Use one where an empty iterable is acceptable.
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
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The iterable to read from.
Returns
Section titled “Returns”T
The single element.
Throws
Section titled “Throws”If the iterable is empty or holds more than one element.