starry.generator-to-iterable
v4.0.0
Published
Member of the starry suite—modular functions for iterable objects.
Downloads
11
Maintainers
Readme
Member of the starry suite—modular functions for iterable objects.
Status
Applies to the whole suite.
Usage
function generatorToIterable<T = any>(
generatorFn: () => Iterator<T>
): Iterable<T>
Wraps a generator function, or any function that returns an iterator, into an iterable such that #[Symbol.iterator]()
runs the function.
Generator functions, as they turn out, do not save their initial state, and returns an iterator which just saves the generator's state. This function aims to remedy that problem.
Parameters:
- generatorFn:
() => Iterator<T>
- A function that returns an iterator.
Returns: Iterable<T>