Function ensureNonEmptyIterable
Type Parameters
- T
Returns Iterable<T, any, any>
A restartable iterable containing all values, or
undefinedif the input was not iterable or contained no items.Example
const iter = ensureNonEmptyIterable(['a', 'b']);
// `iter` is an iterable yielding 'a', 'b'.
const empty = ensureNonEmptyIterable([]);
// `undefined`
const gen = ensureNonEmptyIterable((function*(){ yield 1; yield 2; })());
// Safe: returns an iterable yielding 1, 2 without consuming the generator.
Ensures that a given value is a non-empty iterable.
This function is ideal when you need a safe, non-empty iterable for iteration but cannot consume or trust the original iterable’s internal iterator state.