Skip to content

Instantly share code, notes, and snippets.

@elijahboston
Created June 3, 2020 15:53
Show Gist options
  • Save elijahboston/af785ff6308c5d6621a6d4e046ceb0c2 to your computer and use it in GitHub Desktop.
Save elijahboston/af785ff6308c5d6621a6d4e046ceb0c2 to your computer and use it in GitHub Desktop.
Generic Array Generator
/**
* A generic generator that returns the next item in the array each time it's called.
* @param arr An array of items
*/
function* arrayGenerator<T>(arr: T[] | undefined) {
if (!arr) {
return undefined;
}
for (const item of arr) {
yield item;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment