Returns the single element in an iterable. Throws an error if the iterable contains zero or more than one element.
Element type
The input iterable
The single element in the iterable
If there are no elements in the iterable
If there is more than one element in the iterable
maybeSingle - Non-throwing variant that returns undefined for 0 or >1 elements
G.pipe( G.of([42]), G.single) // 42// Throws "Expected single element, got more."G.pipe( G.range(1, 2), G.single) Copy
G.pipe( G.of([42]), G.single) // 42// Throws "Expected single element, got more."G.pipe( G.range(1, 2), G.single)
Returns the single element in an iterable. Throws an error if the iterable contains zero or more than one element.