{"id":38161165,"url":"https://github.com/yknx4/async-iterators","last_synced_at":"2026-01-16T23:15:04.684Z","repository":{"id":47651399,"uuid":"122541124","full_name":"yknx4/async-iterators","owner":"yknx4","description":"Classic iterators (each, map, reduce) with support for Async functions","archived":false,"fork":false,"pushed_at":"2021-08-19T16:07:57.000Z","size":202,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-19T07:51:13.821Z","etag":null,"topics":["async","helper","iterators","javascript","typescript","utilities"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yknx4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-22T22:07:44.000Z","updated_at":"2019-04-17T16:44:43.000Z","dependencies_parsed_at":"2022-09-26T19:43:10.953Z","dependency_job_id":null,"html_url":"https://github.com/yknx4/async-iterators","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/yknx4/async-iterators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yknx4%2Fasync-iterators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yknx4%2Fasync-iterators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yknx4%2Fasync-iterators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yknx4%2Fasync-iterators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yknx4","download_url":"https://codeload.github.com/yknx4/async-iterators/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yknx4%2Fasync-iterators/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28487405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T22:54:02.790Z","status":"ssl_error","status_checked_at":"2026-01-16T22:50:10.344Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","helper","iterators","javascript","typescript","utilities"],"created_at":"2026-01-16T23:15:02.759Z","updated_at":"2026-01-16T23:15:04.661Z","avatar_url":"https://github.com/yknx4.png","language":"TypeScript","funding_links":["https://paypal.me/yknx4"],"categories":[],"sub_categories":[],"readme":"[![Dev dependencies][dependencies-badge]][dependencies]\n[![Node.js version][nodejs-badge]][nodejs]\n[![NPM version][npm-badge]][npm]\n[![Build Status][travis-badge]][travis-ci]\n[![Coverage Status](https://coveralls.io/repos/github/yknx4/async-iterators/badge.svg?branch=master)](https://coveralls.io/github/yknx4/async-iterators?branch=master)\n\n[![Apache-2.0][license-badge]][LICENSE]\n[![PRs Welcome][prs-badge]][prs]\n[![Donate][donate-badge]][donate]\n\n[![Watch on GitHub][github-watch-badge]][github-watch]\n[![Star on GitHub][github-star-badge]][github-star]\n\n# async-iterators \n\nClassic iterators (each, map, reduce) with support for Async functions (or Promise based functions). It automatically waits for functions to resolve if they are asynchronous. They work pretty much the same as lodash ones.\n\nNo dependencies! Tested on Node/LTS and Node stable!\n\n## Use case\n\n### Problem\n```javascript\n  const ids = [1,2,3,4,5...1000]\n  /** \n   ** reallyExpensiveFetchFunction is going run as soon as you call the function\n   ** about 1000 times at the same, probably crashing/slowing your app, db, etc...\n   ** imagine with millions or records\n   **/\n  const promises = ids.map(id =\u003e reallyExpensiveAsyncFunction(id)) \n  const result = await Promise.all(promises)\n  // result will contain a 1000 results\n```\n### Solution\n**Vanilla js #1**\n```javascript\n  const ids = [1,2,3,4,5...1000]\n  /** \n   ** It works but it is unredable and looks hackish\n   **/\n  const result = await ids.reduce((p, id) =\u003e {\n             return p.then(id =\u003e reallyExpensiveAsyncFunction(id));\n         }, Promise.resolve())\n  // result will contain a 1000 results\n```\n**Vanilla js #2**\n```javascript\n  const ids = [1,2,3,4,5...1000]\n  /** \n   ** It is readable, but still kind of verbose, and it gets messier when \n   ** simulating a reduce iterator.\n   **/\n  const result = []\n  for(const id of ids) {\n    result.push(await reallyExpensiveAsyncFunction(id));\n  }\n  // result will contain a 1000 results\n```\n\n**async-iterators**\n```javascript\n  const {mapAsync} = require('async-function-iterators')\n  const ids = [1,2,3,4,5...1000]\n  /** \n   ** same readibility and simplicity as array.map(fn) or lodash's map(array, fn)\n   ** runs the reallyExpensiveAsyncFunction in series, thus not overloading your\n   ** system \n   **/\n  const result = await mapAsync(ids, id =\u003e reallyExpensiveAsyncFunction(id))\n  // result will contain a 1000 results\n```\n\n## Quick start\n\nThis project is intended to be used with \u003e=v8 (requires support for async/await) release of [Node.js][nodejs] or newer \n\n### Install with yarn\n```sh\nyarn add async-function-iterators\n```\n\n### Install with npm \n\n```sh\nnpm install --save async-function-iterators\n```\n\n## Docs\n\n### Index \n\n* [eachAsync](#eachasync)\n* [eachRightAsync](#eachrightasync)\n* [mapAsync](#mapasync)\n* [mapRightAsync](#maprightasync)\n* [reduceAsync](#reduceasync)\n* [reduceRightAsync](#reducerightasync)\n\n\n\n---\n### Functions\n\u003ca id=\"eachasync\"\u003e\u003c/a\u003e\n\n###  eachAsync\n\n► **eachAsync**(array: *`any`[]*, iteratee: *`Function`*): `Promise`.\u003c`void`\u003e\n\n\n\n\n\n\nIterates over elements of `array` and invokes `iteratee` for each element. The iteratee is invoked with three arguments: (value, index|key, collection), and it is awaited if it is async.\n*__see__*: eachRightAsync\n\n*__example__*: async function asyncFn(value) { return value * 2 }\n\nawait eachAsync([1, 2], value =\u003e { const result = await asyncFn(value) console.log(result) }) // =\u003e Logs `2` then `4`.\n\n\n\n**Parameters:**\n\n| Param | Type | Description |\n| ------ | ------ | ------ |\n| array | `any`[]   |  The array to iterate over. |\n| iteratee | `Function`   |  The function invoked per iteration. (It may be async function). |\n\n\n\n\n\n**Returns:** `Promise`.\u003c`void`\u003e\nReturns a Promise that resolves when all the calls have been done or rejects when the first one fails.\n\n\n\n\n\n___\n\n\u003ca id=\"eachrightasync\"\u003e\u003c/a\u003e\n\n###  eachRightAsync\n\n► **eachRightAsync**(array: *`any`[]*, iteratee: *`Function`*): `Promise`.\u003c`void`\u003e\n\n\n\n\n\n\nIterates over elements of `array` and invokes `iteratee` for each element in reverse order. The iteratee is invoked with three arguments: (value, index|key, collection), and it is awaited if it is async.\n*__see__*: eachAsync\n\n*__example__*: async function asyncFn(value) { return value * 2 }\n\nawait eachRightAsync([1, 2], value =\u003e { const result = await asyncFn(value) console.log(result) }) // =\u003e Logs `4` then `2`.\n\n\n\n**Parameters:**\n\n| Param | Type | Description |\n| ------ | ------ | ------ |\n| array | `any`[]   |  The array to iterate over. |\n| iteratee | `Function`   |  The function invoked per iteration. (It may be async function). |\n\n\n\n\n\n**Returns:** `Promise`.\u003c`void`\u003e\nReturns a Promise that resolves when all the calls have been done or rejects when the first one fails.\n\n\n\n\n\n___\n\n\u003ca id=\"mapasync\"\u003e\u003c/a\u003e\n\n###  mapAsync\n\n► **mapAsync**(array: *`any`[]*, iteratee: *`Function`*): `Promise`.\u003c`any`[]\u003e\n\n\n\n\n\n\nCreates Promise that resolves with an array of values by running each element of `array` thru `iteratee`. The iteratee is invoked with three arguments: (value, index, array), and it is awaited if it is async.\n*__see__*: mapRightAsync\n\n*__example__*: async function square(n) { return n * n }\n\nawait mapAsync([4, 8], square) // =\u003e [16, 64]\n\n\n\n**Parameters:**\n\n| Param | Type | Description |\n| ------ | ------ | ------ |\n| array | `any`[]   |  The array to iterate over. |\n| iteratee | `Function`   |  The function invoked per iteration. (It may be async function) |\n\n\n\n\n\n**Returns:** `Promise`.\u003c`any`[]\u003e\nReturns a promise that resolves into the new mapped array.\n\n\n\n\n\n___\n\n\u003ca id=\"maprightasync\"\u003e\u003c/a\u003e\n\n###  mapRightAsync\n\n► **mapRightAsync**(array: *`any`[]*, iteratee: *`Function`*): `Promise`.\u003c`any`[]\u003e\n\n\n\n\n\n\nCreates Promise that resolves with an array of values by running each element of `array` thru `iteratee` in reverse order. The iteratee is invoked with three arguments: (value, index, array), and it is awaited if it is async.\n*__see__*: mapAsync\n\n*__example__*: async function square(n) { return n * n }\n\nawait mapRightAsync([4, 8], square) // =\u003e [64, 16]\n\n\n\n**Parameters:**\n\n| Param | Type | Description |\n| ------ | ------ | ------ |\n| array | `any`[]   |  The array to iterate over. |\n| iteratee | `Function`   |  The function invoked per iteration. (It may be async function) |\n\n\n\n\n\n**Returns:** `Promise`.\u003c`any`[]\u003e\nReturns a promise that resolves into the new mapped array.\n\n\n\n\n\n___\n\n\u003ca id=\"reduceasync\"\u003e\u003c/a\u003e\n\n###  reduceAsync\n\n► **reduceAsync**(array: *`any`[]*, iteratee: *`Function`*, accumulator?: *`any`*): `Promise`.\u003c`any`\u003e\n\n\n\n\n\n\nReduces `collection` to a value which is the accumulated result of running each element in `collection` thru `iteratee` and awaited, where each successive invocation is supplied the return value of the previous. If `accumulator` is not given, the first element of `collection` is used as the initial value. The iteratee is invoked with four arguments: (accumulator, value, index|key, collection).\n*__see__*: reduceRightAsync\n\n*__example__*: await reduceAsync([1, 2], async (sum, n) =\u003e sum + n, 0) // =\u003e 3\n\nawait reduceAsync({ 'a': 1, 'b': 2, 'c': 1 }, async (result, value, key) =\u003e { (result[value] || (result[value] = [])).push(key) return result }, {}) // =\u003e { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)\n\n\n\n**Parameters:**\n\n| Param | Type | Description |\n| ------ | ------ | ------ |\n| array | `any`[]   |  The collection to iterate over. |\n| iteratee | `Function`   |  The function invoked per iteration. (It may be async function) |\n| accumulator | `any`   |  - |\n\n\n\n\n\n**Returns:** `Promise`.\u003c`any`\u003e\nReturns the accumulated value.\n\n\n\n\n\n___\n\n\u003ca id=\"reducerightasync\"\u003e\u003c/a\u003e\n\n###  reduceRightAsync\n\n► **reduceRightAsync**(array: *`any`[]*, iteratee: *`Function`*, accumulator?: *`any`*): `Promise`.\u003c`any`\u003e\n\n\n\n\n\n\nReduces `collection` in reverse order to a value which is the accumulated result of running each element in `collection` thru `iteratee` and awaited, where each successive invocation is supplied the return value of the previous. If `accumulator` is not given, the first element of `collection` is used as the initial value. The iteratee is invoked with four arguments: (accumulator, value, index|key, collection).\n*__see__*: reduceAsync\n\n*__example__*: await reduceRightAsync(array, async (flattened, other) =\u003e flattened.concat(other), []) // =\u003e [4, 5, 2, 3, 0, 1]\n\n\n\n**Parameters:**\n\n| Param | Type | Description |\n| ------ | ------ | ------ |\n| array | `any`[]   |  The collection to iterate over. |\n| iteratee | `Function`   |  The function invoked per iteration. (It may be async function) |\n| accumulator | `any`   |  - |\n\n\n\n\n\n**Returns:** `Promise`.\u003c`any`\u003e\nReturns the accumulated value.\n\n\n\n\n\n___\n\n\n\n\n\n\n## Available scripts\n\n+ `clean` - remove coverage data, Jest cache and transpiled files,\n+ `build` - transpile TypeScript to ES6,\n+ `watch` - interactive watch mode to automatically transpile source files, \n+ `lint` - lint source files and tests,\n+ `test` - run tests,\n+ `test:watch` - interactive watch mode to automatically re-run tests\n\n## License\nLicensed under the Apache-2.0. See the [LICENSE](https://github.com/yknx4/async-iterators/blob/master/LICENSE) file for details.\n\n[dependencies-badge]: https://david-dm.org/yknx4/async-iterators/dev-status.svg\n[dependencies]: https://david-dm.org/yknx4/async-iterators?type=dev\n[nodejs-badge]: https://img.shields.io/badge/node-\u003e=%208.9-blue.svg\n[nodejs]: https://nodejs.org/dist/latest-v6.x/docs/api/\n[npm-badge]: https://img.shields.io/badge/npm-\u003e=%205.5.1-blue.svg\n[npm]: https://docs.npmjs.com/\n[travis-badge]: https://travis-ci.org/yknx4/async-iterators.svg?branch=master\n[travis-ci]: https://travis-ci.org/yknx4/async-iterators\n[typescript]: https://www.typescriptlang.org/\n[typescript-27]: https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#typescript-27\n[license-badge]: https://img.shields.io/badge/license-APLv2-blue.svg\n[license]: https://github.com/yknx4/async-iterators/blob/master/LICENSE\n[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg\n[prs]: https://github.com/yknx4/async-iterators/compare\n[donate-badge]: https://img.shields.io/badge/$-support-green.svg\n[donate]: https://paypal.me/yknx4\n[github-watch-badge]: https://img.shields.io/github/watchers/yknx4/async-iterators.svg?style=social\n[github-watch]: https://github.com/yknx4/async-iterators/watchers\n[github-star-badge]: https://img.shields.io/github/stars/yknx4/async-iterators.svg?style=social\n[github-star]: https://github.com/yknx4/async-iterators/stargazers\n[jest]: https://facebook.github.io/jest/\n[tslint]: https://palantir.github.io/tslint/\n[tslint-microsoft-contrib]: https://github.com/Microsoft/tslint-microsoft-contrib\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyknx4%2Fasync-iterators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyknx4%2Fasync-iterators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyknx4%2Fasync-iterators/lists"}