co-lodash

0.2.0 • Public • Published

co-lodash

Extend lodash to make it work with co.

API

  • _.extendProperties(target, src)
  • _.isGenerator(obj)
  • _.isAsyncFunction(obj)
  • _.sleep(mill)
  • _.coEach(collection, fn) // fn params (item, index, collection)
  • _.coMap(collection, fn) // fn params (item, index, collection)
  • _.coReduce(collection, fn, memo) // fn params (memo, item, index, collection)

Example

var _ = require('co-lodash'); // yes, it can do exactly the same as lodash, because it is lodash with some extendsions.
 
console.log(_.extendProperties({}, { get foo() { return 1; }}));
 
co(function *() {
    yield* _.coEach([1,2,3,4,5], function* (v) {
        console.log('each:', v);
        yield _.sleep(1000);
    });
 
    console.log(yield* _.coMap([1,2,3,4,5], function *(v) {
        console.log('map:', v);
        yield _.sleep(1000);
        return v * 2;
    }));
 
    console.log(yield* _.coReduce([1,2,3,4,5], function*(m, v) {
        console.log('reduce:', v);
        yield _.sleep(1000);
        return m + v;
    }, 0));
 
    console.log(yield* _.coFilter([1,2,3,4,5], function*(v) {
        yield _.sleep(1000);
        return v % 2;
    }, 0));
});

Readme

Keywords

none

Package Sidebar

Install

npm i co-lodash

Weekly Downloads

1,982

Version

0.2.0

License

MIT

Last publish

Collaborators

  • talrasha007