{"id":22021596,"url":"https://github.com/lamansky/reduce-iterable","last_synced_at":"2026-04-13T17:02:16.459Z","repository":{"id":57350019,"uuid":"120328778","full_name":"lamansky/reduce-iterable","owner":"lamansky","description":"[Node.js] Applies a function to iterated values to reduce them to a single value.","archived":false,"fork":false,"pushed_at":"2018-02-06T22:06:00.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-23T09:43:48.581Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-05T16:12:29.000Z","updated_at":"2018-02-06T22:06:01.000Z","dependencies_parsed_at":"2022-09-16T02:11:42.650Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/reduce-iterable","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Freduce-iterable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Freduce-iterable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Freduce-iterable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Freduce-iterable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/reduce-iterable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245085097,"owners_count":20558332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-30T06:13:10.646Z","updated_at":"2026-04-13T17:02:16.449Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reduce-iterable\n\nApplies a function to iterated values to reduce them to a single value. It’s like [`Array.prototype.reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) but it works for any iterable object.\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 6.0.0 or above.\n\n```bash\nnpm i reduce-iterable\n```\n\n## API\n\nThe module exports a single function.\n\n### Parameters\n\n1. Bindable: `iter` (iterable)\n2. `cb` (Function): A callback which is called for each iterated value.\n    * Parameters\n        1. `acc` (any): The accumulator.\n        2. `x` (any): The iterated value.\n        3. `i` (integer): The number of values iterated so far. Starts at `0` if the accumulator was given a starting value; otherwise starts at `1`.\n        4. `iter` (iterable): The original `iter`.\n    * Return Value: The accumulator that should be passed to the next iteration.\n3. Optional: `acc` (any): The initial value of the accumulator. Defaults to the first iterated value.\n\n### Return Value\n\nThe final accumulator value.\n\n## Example\n\n```javascript\nconst reduce = require('reduce-iterable')\n\nreduce([1, 2, 3], (acc, x) =\u003e acc + x) // 6\n\n// Supports the bind operator\n[1, 2, 3]::reduce((acc, x) =\u003e acc + x) // 6\n```\n\n## Related\n\n* [filter-iter](https://github.com/lamansky/filter-iter): Filters an iterable object so that it only yields values which pass a test function.\n* [partition-iterable](https://github.com/lamansky/partition-iterable): Divides iterated values into those that match a filter and those that don’t.\n* [unique-iterable](https://github.com/lamansky/unique-iterable): Filters an iterable object so it doesn’t yield the same value more than once.\n* [unique-iterable-by](https://github.com/lamansky/unique-iterable-by): Filters yielded values by testing uniqueness with an index, key, or callback.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Freduce-iterable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Freduce-iterable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Freduce-iterable/lists"}