Returns the first element from an iterable if it's the only element, undefined if there are no elements, or throws an error if there are multiple elements.
Type of values in the iterable
The input iterable
The single element if it exists, or undefined if the iterable is empty
Error if there are more than one elements
single for a version that throws when there are no elements
G.pipe( [42], G.maybeSingle) // 42G.pipe( [], G.maybeSingle) // undefined// This would throw an Error:// G.pipe([1, 2, 3], G.maybeSingle) Copy
G.pipe( [42], G.maybeSingle) // 42G.pipe( [], G.maybeSingle) // undefined// This would throw an Error:// G.pipe([1, 2, 3], G.maybeSingle)
Returns the first element from an iterable if it's the only element, undefined if there are no elements, or throws an error if there are multiple elements.