Created
June 3, 2020 15:53
-
-
Save elijahboston/af785ff6308c5d6621a6d4e046ceb0c2 to your computer and use it in GitHub Desktop.
Generic Array Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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