asyncreduce
Reduce an array of values via an asynchronous function.
Last updated 7 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install asyncreduce 
SYNC missed versions from official npm registry.

asyncreduce build status

Reduce an array of values via an asynchronous function.

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);
    }
);

Features

  • super small library built on top of also quite small runnel
  • since runnel try/catches and bubbles errors and reports with detailed stack traces, so does asyncreduce

Installation

npm install asyncreduce

In the browser

With browserify

You are all good.

Without browserify

Two options:

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

Current Tags

  • 0.1.4                                ...           latest (7 years ago)

6 Versions

  • 0.1.4                                ...           7 years ago
  • 0.1.3                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 4
This Month 0
Last Day 4
Last Week 24
Last Month 105
Dependencies (1)
Dev Dependencies (5)

Copyright 2014 - 2016 © taobao.org |