und

underpromise

Functionally handle promises

Showing:

Popularity

Downloads/wk

1

GitHub Stars

16

Maintenance

Last Commit

7yrs ago

Contributors

1

Package

Dependencies

5

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

lag

Functional promises. It's like lodash/underscore for promises.

Using promises as functional values allows the developer to write asynchronous code in a synchronous way.

Method signature

lag.methodName(function, promise_array)

Lag uses the "function first" method signature in order to take advantage of the functional approach to programming.

If you prefer the put the values first and the method second, you can call the lag.promiseFirst() method to switch the parameter order to lag.methodName(promise_array, function).

Install

NPM

npm install lag --save

Bower

bower install lag --save

Example Usage

var _ = require('lag');
var xhr = require('xhr');

var promises = [
  _.asPromise(123),
  _.asPromise(456),
  _.promise(function (resolve, reject) {
    http.get('http://someapi.com', function (err, res) {
      if (err) return reject(err);
      resolve(res)
    });
  })
];

_.map(_.add(1), promises)
.then(_.filter(_.lessThan(400)))
.then(function (values) {
    // values === [124]
});

Methods

Arrays

each(fn, promises)

each.series(fn, promises)

map(fn, promises)

map.series(fn, promises)

filter(fn, promises)

filter.series(fn, promises)

reject(fn, promises)

reject.series(fn, promises)

find(fn, promises)

find.series(fn, promises)

reduce(fn, promises)

reduceRight(fn, promises)

first(promises)

first.value(promise)

last(promises)

last.value(promise)

initial(promises)

initial.values(promise)

tail(promises)

tail.values(promise)

reverse(promises)

reverse.values(promise)

compact(promises)

Collections

where(object, promises)

findWhere(object, promises)

pluck(keys, promises)

every(promises)

some(promises)

contains(keys, promises)

Objects

keys(promise)

values(promise)

extend(promise[, object1, objectn, ...])

defaults(defaults[, promise1, promisen, ...])

pick(key1[, keyn, ...], promise)

omit(key1[, keyn, ...], promise)

Nubmers

greaterThan(number, promise)

lessThan(number, promise)

equal(promise1, promise2)

add(number, promise)

subtract(number, promise)

Strings

prepend(promise)

append(promise)

Utilities

promise(function)

asPromise(value)

all(promise1[, promise2, promisen, ...])

when(promise1[, promise2, promisen, ...])

partial(function[, value1, valuen, ...])

boolean(value)

inverseBoolean(value)

compose(method1[, method2, methodn, ...])

Build

npm install
npm run build

Run Tests

npm install
npm test

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial