{"_id":"p-reduce","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"dist-tags":{"latest":"3.0.0"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"description":"Reduce a list of values using promises into a promise for a value","readme":"# p-reduce\n\n> Reduce a list of values using promises into a promise for a value\n\nUseful when you need to calculate some accumulated value based on async resources.\n\n## Install\n\n```\n$ npm install p-reduce\n```\n\n## Usage\n\n```js\nimport pReduce from 'p-reduce';\nimport humanInfo from 'human-info'; // Not a real module\n\nconst names = [\n\tgetUser('sindresorhus').then(info => info.name),\n\t'Addy Osmani',\n\t'Pascal Hartig',\n\t'Stephen Sawchuk'\n];\n\nconst totalAge = await pReduce(names, async (total, name) => {\n\tconst info = await humanInfo(name);\n\treturn total + info.age;\n}, 0);\n\nconsole.log(totalAge);\n//=> 125\n```\n\n## API\n\n### pReduce(input, reducer, initialValue?)\n\nReturns a `Promise` that is fulfilled when all promises in `input` and ones returned from `reducer` are fulfilled, or rejects if any of the promises reject. The fulfilled value is the result of the reduction.\n\n#### input\n\nType: `Iterable<Promise|any>`\n\nIterated over serially in the `reducer` function.\n\n#### reducer(previousValue, currentValue, index)\n\nType: `Function`\n\nExpected to return a value. If a `Promise` is returned, it's awaited before continuing with the next iteration.\n\n#### initialValue\n\nType: `unknown`\n\nValue to use as `previousValue` in the first `reducer` invocation.\n\n## Related\n\n- [p-each-series](https://github.com/sindresorhus/p-each-series) - Iterate over promises serially\n- [p-map-series](https://github.com/sindresorhus/p-map-series) - Map over promises serially\n- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently\n- [More…](https://github.com/sindresorhus/promise-fun)\n\n---\n\n<div align=\"center\">\n\t<b>\n\t\t<a href=\"https://tidelift.com/subscription/pkg/npm-p-reduce?utm_source=npm-p-reduce&utm_medium=referral&utm_campaign=readme\">Get professional support for this package with a Tidelift subscription</a>\n\t</b>\n\t<br>\n\t<sub>\n\t\tTidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.\n\t</sub>\n</div>\n","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"users":{"flumpus-dev":true},"bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"license":"MIT","versions":{"2.0.0":{"name":"p-reduce","version":"2.0.0","description":"Reduce a list of values using promises into a promise for a value","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"devDependencies":{"ava":"^1.3.1","delay":"^4.1.0","tsd-check":"^0.3.0","xo":"^0.24.0"},"gitHead":"44439fb758f74506b45863488abef8d3d8762629","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"homepage":"https://github.com/sindresorhus/p-reduce#readme","_id":"p-reduce@2.0.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-VcNNEqiYIkRCGeUHELY5dUrnQHCRwL6eIH/L9oSbl/PsvyHQXD1ws/MFwuEb+6dgH/URCfROVUqOYL37eHi2kQ==","shasum":"365a26916213650711124881a6bdc4e32c2bfe36","tarball":"https://devel.data-in-motion.biz/nexus/repository/npm-group/p-reduce/-/p-reduce-2.0.0.tgz","fileCount":5,"unpackedSize":5183,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJchz/HCRA9TVsSAnZWagAApiEP/RrtDqK03NEBn7aHLY9d\nSYDyQcbfqGD8d57l79luuRIFlk325el+A3PQ0DMz9w+yEkaTDFCDGXlUdwSY\nRN6wUr71jne7GcvL00eHmnjxZLmqgGBZm3BF4345+x7HI+G6knVzGURxdgWe\nL0KYFCuhcg3jbSxJCt3UrAfj5Y5fQZmTOETtHKlDV2S0DXuHqtiUr2Wch4a9\nQ1qj0lRqsDDcZU5qbKyZnBn8i5rNbS3NaY0bVNYJHlzlQQ3laLKfHxTpNQDk\nWgkwRbSAefldtiD9Yom0qT7AxA2XJAR7XMlESMyJCNSsNSOElssZ8HMbp4bs\nBmgzL3cH3qIZC/LUa1DjV1xxt4jwQsSnCvQXUM9rtTZ049yJ8VYrhXcqb7u3\nlRpBLHDxYWAIIhDQdZXa9IjDE1W8D4Kyf8KQHR4UXxEvKKh8TWmTKqLsq77t\nLX0vcc8lwhvmjIvsMuerWpEtLHM7E3BQ0PXmBBc+Ygo+f3AmTuAEvxZCH/tN\nbuUotTorGG3N5aboPQ7RKmIyhJa38FKt0hk6d4FJ6FJSzRJvpK39qZ09es5G\ndI8V5lF0pnh4kWHpYTvRAPnSaPin5LeyF/LHZJOx+qS3AB33KDcq0hgq2uQK\nqm+EBQ/WGdpqATtSvOjNTqiLMePesojjEgu4GfAtU+cNO9aM2RuNr0Xxxnc8\n335Y\r\n=BDJY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG/VB9bM5HiQfOw8qNdxitHxnlHa3inm9z3/ZNCZUgmbAiBzrKNpZ3SON8A6dA/glJp7ZzHjh8TvowNrHqtxbrkZBw=="}]},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reduce_2.0.0_1552367558654_0.1055260822991213"},"_hasShrinkwrap":false},"2.1.0":{"name":"p-reduce","version":"2.1.0","description":"Reduce a list of values using promises into a promise for a value","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"devDependencies":{"ava":"^1.4.1","delay":"^4.1.0","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"cb9d053d05194221f010fcd0dfa9d0c203aa26d7","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"homepage":"https://github.com/sindresorhus/p-reduce#readme","_id":"p-reduce@2.1.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-2USApvnsutq8uoxZBGbbWM0JIYLiEMJ9RlaN7fAzVNb9OZN0SHjjTTfIcb667XynS5Y1VhwDJVDa72TnPzAYWw==","shasum":"09408da49507c6c274faa31f28df334bc712b64a","tarball":"https://devel.data-in-motion.biz/nexus/repository/npm-group/p-reduce/-/p-reduce-2.1.0.tgz","fileCount":5,"unpackedSize":6142,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcpY7KCRA9TVsSAnZWagAA7TUP/Rbv3p69jzfUtG/DOBw7\n5J6zxfGm2lYrNcR9L7bvKXR4RQHKrQqHayNeBumJ87mFiexk3C1PXTxc/193\n4TZ09LIHCZsv7RtA311qvsmRzlcxjZI6VSKNBUztoBhe8JDgZT3j1IVxQ3Bh\njN7ABBofo7y1tbi4arRJ6A49n7e9GvbBNoqyP80Fq+O+rN75zLDFfV6l06wx\n/JPcepVpgyJInCU4bsts7pO86WVQZswDX19WcKn1cjX09Mt+Yk7krSy0DajX\njKDWRNkxUOPw+16cdUhAH6pLAdv6Zr6ZB42vNAIw75U8Zi1AiihJrZ6DQPi6\nJv5FxqqlhRAR4aQt62M4WEQmPhvOunegY8LmT6j7GEBO+rCOk+CyyqXo4NiV\nJcOTjGncKkn17qqNS+wZXK1+U3UMb0Pifu+rdz2/TMWQq3QkHpTwXmKTe4FG\nI8HZAKCZ/IdO4QSUquhPN0x8PFo9s6BuUUkcm+fAc1dcV109dcG/Psp1WSC+\n3rg2cNh/zQDhjv2/XMYt1LZa6sBFkGKQ2yTO2lAUlXapGrpI2aPvRIb3JPzP\nU5HElYWEHeJCLdTCRQhtyO3B0Ep1s/NWLuc1BtZkXPvIP1O9w7t44x//tgAm\n4NE4eDqKL/zcuHDo1kv5/qc+AE6PSK4qg47VtN8r5Wu9Yx4akheqT/gZQlIg\ngQal\r\n=uxuQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHsj6Gy6R55jyn7/5WkUYPI229plhPWQDgd+vqjzrwpIAiBSmUXXR5Kif7DeWfqihqxVhQYuUci/8ty1OYxujgV+6A=="}]},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reduce_2.1.0_1554353865830_0.3691561520970803"},"_hasShrinkwrap":false},"3.0.0":{"name":"p-reduce","version":"3.0.0","description":"Reduce a list of values using promises into a promise for a value","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"devDependencies":{"ava":"^3.15.0","delay":"^5.0.0","tsd":"^0.14.0","xo":"^0.38.2"},"gitHead":"b8cfa3dd34304384501d4e5243c44131998c4ee5","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"homepage":"https://github.com/sindresorhus/p-reduce#readme","_id":"p-reduce@3.0.0","_nodeVersion":"15.12.0","_npmVersion":"6.14.10","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-xsrIUgI0Kn6iyDYm9StOpOeK29XM1aboGji26+QEortiFST1hGZaUQOLhtEbqHErPpGW/aSz6allwK2qcptp0Q==","shasum":"f11773794792974bd1f7a14c72934248abff4160","tarball":"https://devel.data-in-motion.biz/nexus/repository/npm-group/p-reduce/-/p-reduce-3.0.0.tgz","fileCount":5,"unpackedSize":5894,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgb0kRCRA9TVsSAnZWagAAgM0QAKHXGRsH0zNLVmKNAXo4\n/mi0YASoGgXdWf4vx71GFc2ODjeInfhSrvtDoOt+DbF44VpEhHrpBvPQZ49e\nEkrU62K2t+jOY+C+YGl/ZxGTM8Z+8LSxssUaeIa49Cbt5H5JQUySj8N1pjj9\ni1bxk6xWa44pc8VoFZeWXS4K8HrWJLNZLcJac0qbeW2mzIGpqR8rNV2HyTej\n6fakPJJlkNcxdmYuBMXtKpKLvgX9lJ45ohNkFNky0LHxSOrRz7rKBeVsirGR\nZkPdn+VDLXxgIUDS4P7J0dVTq5CleMNibnOUTba3677d99FtNv7EIXbdbWmL\n85lsaOCNN66N3mk5GC1FfVJ3gAMjDIZOmMyE0dXA9JcQ7QLl5ilsSlLKrR5B\nWxceJa1RZFVBo9wJKaf5d3eGm8+k73G1NpVmgDayHwxb2APkKAtZ+tBltsix\ns9QwfBGSl7hCELaHSgjO4fuM1rhrPmhdS/FpFZTBNHHpKNUFdNRXriP5Vjkf\nIIwQdttBpZda4XP9wVmia83MEZLObX86Vro6Pk5RBxIk11FMy6NU2U7i0+kk\nxuwxcX+P6xDVsvDM8shYcOVoaXeDWHzv7elyL8Up1HBtK65N9L9D86Twlolq\nwdXGXKPs5pLnMi1/9TbaHidT8ZDDXOvQ1y8+NQYrMT8KojdfUIniNQwC7eGs\nrcNu\r\n=t5gQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBpoexnQRZaV72DVQLOYyULcH+8zMOyJlGZn1aqbUa6gAiEA182g1PzH4WGn6fnaU0gDi3KAJ5pVKNPwL5HOYmiRG8Y="}]},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reduce_3.0.0_1617905936908_0.15612528844177098"},"_hasShrinkwrap":false},"1.0.0":{"name":"p-reduce","version":"1.0.0","description":"Reduce a list of values using promises into a promise for a value","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"devDependencies":{"ava":"*","delay":"^1.3.1","xo":"*"},"xo":{"esnext":true},"gitHead":"fa526a9b6b51a3c4811c61954328218a4636871d","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"homepage":"https://github.com/sindresorhus/p-reduce#readme","_id":"p-reduce@1.0.0","_shasum":"18c2b0dd936a4690a529f8231f58a0fdb6a47dfa","_from":".","_npmVersion":"2.15.9","_nodeVersion":"4.6.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"18c2b0dd936a4690a529f8231f58a0fdb6a47dfa","tarball":"https://devel.data-in-motion.biz/nexus/repository/npm-group/p-reduce/-/p-reduce-1.0.0.tgz","integrity":"sha512-3Tx1T3oM1xO/Y8Gj0sWyE78EIJZ+t+aEmXUdvQgvGmSMri7aPTHoovbXEreWKkL5j21Er60XAWLTzKbAKYOujQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDhwzrF129k1LHq0mgEsfjWLaZoisl/64t5UFfDlNYYngIhANC5dpZc5O9RDv/UTAui0sed/I/29w2pHVIEruKPAG/F"}]},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/p-reduce-1.0.0.tgz_1477023867894_0.5352144201751798"},"directories":{}}},"name":"p-reduce","time":{"2.0.0":"2019-03-12T05:12:38.774Z","2.1.0":"2019-04-04T04:57:45.948Z","3.0.0":"2021-04-08T18:18:57.037Z","created":"2016-10-21T04:24:28.119Z","modified":"2025-04-26T11:32:52.214Z","1.0.0":"2016-10-21T04:24:28.119Z"},"readmeFilename":"readme.md","homepage":"https://github.com/sindresorhus/p-reduce#readme"}