# reduce-async

> Asynchronous Array.reduce

Latest version **0.1.6** (published 2016-09-29) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2016-09-29 |
| First published | 2016-09-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nathan Buchar |
| Maintainers | nathanbuchar |
| Keywords | array, reduce, async, asynchronous, loop, iterate, iterator, sequence, sequencer |

## Links

- npm: https://www.npmjs.com/package/reduce-async
- Repository: https://github.com/nathanbuchar/reduce-async
- Homepage: https://github.com/nathanbuchar/reduce-async#readme
- Issues: https://github.com/nathanbuchar/reduce-async/issues
- npm.io page: https://npm.io/package/reduce-async

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2016-09-29
- 0.1.4 — 2016-09-29
- 0.1.3 — 2016-09-29
- 0.1.2 — 2016-09-29
- 0.1.1 — 2016-09-29
- 0.1.0 — 2016-09-28

## README

ReduceAsync [![Build Status](https://travis-ci.org/nathanbuchar/reduce-async.svg?branch=master)](https://travis-ci.org/nathanbuchar/reduce-async)
===========

Asynchronous `Array.reduce`. The [`reduce()`][external_mdn_reduce] method applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value.



***



### Installation

```bash
$ npm install reduce-async
```


### Syntax

```
reduceAsync(array, iteratee, done[, initialValue])
```

**Parameters**

* **`array`** *Array* - The array to reduce.

* **`iteratee`** *Function* - The function to execute on each value in the array, taking five arguments:
  * `prev` *Any* - The value previously returned in the last invocation of the iteratee, or `initialValue` if supplied.

  * `curr` *Any* - The current element being processed in the array.

  * `n` *Integer* - The index of the current element being processed in the array. Start at index 0, if an `initialValue` is provided, and at index 1 otherwise.

  * `arr` *Array* - The array `reduceAsync` was called upon.

  * `next` *Function* - The function to call when you are ready to advance to the next element in the array.

* **`done`** *Function* - The function called when the reduce has finished, taking one argument:
  * `result` *Any* - The value that results from the reduction.

* **`initialValue`** *Any* (Optional) - Value to use as the first argument to the first call of the `iteratee`.

[More information][external_mdn_reduce] on how `reduce` works.


### Examples

* Asynchronously sum all the values of an array.

  ```js
  reduceAsync([0, 1, 2, 3], (prev, curr, n, arr, next) => {
    doSomethingAsync(() => {
      next(prev + curr);
    });
  }, result => {
    // result == 6
  }));
  ```

* Asynchronously flatten an array of arrays,

  ```js
  reduceAsync([[0, 1], [2, 3], [4, 5]], (prev, curr, n, arr, next) => {
    doSomethingAsync(() => {
      next(prev.concat(curr));
    });
  }, result => {
    // result is [0, 1, 2, 3, 4, 5]
  }));
  ```

* Asynchronously concatenate all words within an array together starting from an initial value of `"foo"`.

  ```js
  reduceAsync(['bar', 'baz']], (prev, curr, n, arr, next) => {
    doSomethingAsync(() => {
      next(prev + curr);
    });
  }, result => {
    // result is "foobarbaz"
  }, 'foo'));
  ```



***



Authors
-------
* [Nathan Buchar]


License
-------
[ISC](./LICENSE)






[external_mdn_reduce]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce

[Nathan Buchar]: mailto:hello@nathanbuchar.com

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