# reduce-iterable

> Applies a function to iterated values to reduce them to a single value.

Latest version **1.0.0** (published 2018-02-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install reduce-iterable
pnpm add reduce-iterable
yarn add reduce-iterable
bun add reduce-iterable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-02-06 |
| First published | 2018-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Lamansky |
| Maintainers | lamansky |
| Keywords | reduce, iterable, iterator |

## Links

- npm: https://www.npmjs.com/package/reduce-iterable
- Repository: https://github.com/lamansky/reduce-iterable
- Issues: https://github.com/lamansky/reduce-iterable/issues
- npm.io page: https://npm.io/package/reduce-iterable

## Dependencies (2)

- [sbo](https://npm.io/package/sbo.md) ^1.0.0
- [add-counter](https://npm.io/package/add-counter.md) ^1.0.0

## Recent versions

- 1.0.0 (latest) — 2018-02-06

## README

# reduce-iterable

Applies 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.

## Installation

Requires [Node.js](https://nodejs.org/) 6.0.0 or above.

```bash
npm i reduce-iterable
```

## API

The module exports a single function.

### Parameters

1. Bindable: `iter` (iterable)
2. `cb` (Function): A callback which is called for each iterated value.
    * Parameters
        1. `acc` (any): The accumulator.
        2. `x` (any): The iterated value.
        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`.
        4. `iter` (iterable): The original `iter`.
    * Return Value: The accumulator that should be passed to the next iteration.
3. Optional: `acc` (any): The initial value of the accumulator. Defaults to the first iterated value.

### Return Value

The final accumulator value.

## Example

```javascript
const reduce = require('reduce-iterable')

reduce([1, 2, 3], (acc, x) => acc + x) // 6

// Supports the bind operator
[1, 2, 3]::reduce((acc, x) => acc + x) // 6
```

## Related

* [filter-iter](https://github.com/lamansky/filter-iter): Filters an iterable object so that it only yields values which pass a test function.
* [partition-iterable](https://github.com/lamansky/partition-iterable): Divides iterated values into those that match a filter and those that don’t.
* [unique-iterable](https://github.com/lamansky/unique-iterable): Filters an iterable object so it doesn’t yield the same value more than once.
* [unique-iterable-by](https://github.com/lamansky/unique-iterable-by): Filters yielded values by testing uniqueness with an index, key, or callback.

---
_Source: https://npm.io/package/reduce-iterable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
