# asyncreduce

> Reduce an array of values via an asynchronous function.

Latest version **0.1.4** (published 2013-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install asyncreduce
pnpm add asyncreduce
yarn add asyncreduce
bun add asyncreduce
```

## 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.4 |
| Published | 2013-07-27 |
| First published | 2013-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Thorsten Lorenz |
| Maintainers | thlorenz |
| Keywords | async, reduce, accumulate, accumulator, browser, browserify, iterate, iterator, initial |

## Links

- npm: https://www.npmjs.com/package/asyncreduce
- Repository: https://github.com/thlorenz/asyncreduce
- Issues: https://github.com/thlorenz/asyncreduce/issues
- npm.io page: https://npm.io/package/asyncreduce

## Dependencies (1)

- [runnel](https://npm.io/package/runnel.md) ~0.5.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2013-07-27
- 0.1.3 — 2013-07-27
- 0.1.2 — 2013-07-19
- 0.1.1 — 2013-07-19
- 0.1.0 — 2013-07-19
- 0.0.1 — 2013-07-19

## README

# asyncreduce [![build status](https://secure.travis-ci.org/thlorenz/asyncreduce.png)](http://travis-ci.org/thlorenz/asyncreduce)

[![testling badge](https://ci.testling.com/thlorenz/asyncreduce.png)](https://ci.testling.com/thlorenz/asyncreduce)

Reduce an array of values via an asynchronous function.

```js
var fs = require('fs');
var path = require('path');
var asyncReduce = require('asyncreduce');

asyncReduce(
    [ '.gitignore', '.jshintrc', '.travis.yml', 'index.js', 'Readme.md' ]
  , {}
  , function size (acc, file, cb) {
      var p = path.join(__dirname, '..', file);

      fs.stat(p, function (err, stat) {
        if (err) return cb(err);

        acc[file] = stat.size;
        cb(null, acc);
      });
    }
  , function done (err, acc) {
      if (err) return console.error(err);
      console.log('sizes:\n', acc);
    }
);
```

```
sizes:
 { '.gitignore': 97,
  '.jshintrc': 249,
  '.travis.yml': 48,
  'index.js': 1534,
  'Readme.md': 2160 }
```

## Features

- super small library built on top of also quite small [runnel](https://github.com/thlorenz/runnel)
- since runnel `try/catch`es and bubbles errors and reports with detailed stack traces, so does asyncreduce

## Installation

    npm install asyncreduce

### In the browser

#### With [browserify](https://github.com/substack/node-browserify)

You are all good.

#### Without browserify

Two options:

- run [browserify --standalone](https://github.com/substack/node-browserify#usage) after installing this package via
  npm
- download the [asyncreduce standalone version](http://wzrd.in.nyud.net/standalone/asyncreduce), powered by
  [browserify as a service](http://wzrd.in.nyud.net)

## API

### *function asyncReduce (items, seed, iterator, done)*

```
/**
 * Calls provided async iterator function with the accumulator and each item.
 * When all items have been iterated over calls done with a possible error or the final value of the accumulator.
 *
 * @name exports
 * @function
 * @param items {Array} the items to be reduced
 * @param seed {T} the initial value that can be of any type and is passed along as the accumulator (acc) each time the iterator is called
 * @param iterator {Function} function (acc, item, callback) {} - the iterator called for each item
 * @param done {Function} function (err, acc) {} - called with final accumulated value or an error if one occurred
 */
```

## License

MIT

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