0.1.0 • Published 10 years ago

lag v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

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
0.1.0

10 years ago

0.0.13

11 years ago

0.0.12

11 years ago

0.0.11

11 years ago

0.0.10

11 years ago

0.0.9

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.1

11 years ago