Skip to content

Instantly share code, notes, and snippets.

@dtipson
Last active January 5, 2024 16:00
Show Gist options
  • Save dtipson/c6e2ea388d29c23ff93b432a6c8257d5 to your computer and use it in GitHub Desktop.
Save dtipson/c6e2ea388d29c23ff93b432a6c8257d5 to your computer and use it in GitHub Desktop.
Spreading out a generator of arrays into a generator of items
// spreadBatchesAsyncGen :: Iterator[[...Promises]] -> AsyncGenerator[[...Promises]]
const spreadBatchesAsyncGen = async function* (iterableOfPromises) {
for (let array of iterableOfPromises) {
yield* await Promise.all(array)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment