node package manager


Eventual ES5 array operations using promises


Eventual ES5 array operations using promises

$ npm install avec

Think of it like using native ES5 Array.prototype methods on Promised arrays.

var documents = getPromisedArrayOfStuffFromDB()
avec(documents).forEach(function (document) {

  .then(function (aggregate) {
    console.log('we can string things together')
    // the neat thing about promises is that there's no `value()`
    // or finalizer method to call, since each step of the way
    // returns a valid promises/a `thenable` promise.

Begins a promise chain.

forEach, filter, map, reduce, reduceRight, every, some, concat, reverse, sort, indexOf, lastIndexOf, shift, unshift, pop, push, slice, splice

The return value for each of these is the a Promise of whatever the return value would be on a synchronous array.

like calling promise.then(continuation), except continuation's this is also set to the promise value. This allows for slightly more fluid syntax:

var document = getDocumentAsPromise(5)

avec(document, function () {
  console.log('We got ' + this.title)

This is pretty much an ergonomic function I wanted when writing scripts.

Like calling promise.then(function (val) { val.forEach(iterator) }), Use when you're expecting an array value that you want to iterate over.

Like calling promise.then(function (val) { return }). Returns a Promise

In package root directory:

$ npm install
$ npm test


MIT. (c) 2013 Agile Diagnosis See