Skip to content

Instantly share code, notes, and snippets.

@myobie
Created April 10, 2020 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myobie/9638b10df8f6152f6003b038b89cfe57 to your computer and use it in GitHub Desktop.
Save myobie/9638b10df8f6152f6003b038b89cfe57 to your computer and use it in GitHub Desktop.
Wrap an async generator with index generation
/**
* @template T
* @param {AsyncGenerator<T, void, void>} gen
* @returns {AsyncGenerator<[T, number], void, void>}
*/
export async function * genIndexes (gen) {
let i = 0
for await (const item of gen) {
yield [item, i]
i++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment