co-dash
v1.0.71
Published
Lodash inspired library for generator functions
Downloads
14
Readme
co-dash
Lodash-inspired library for generators
Install
$ npm install co-dash
Usage
codash.once(fn)
const co = require('co');
const { once } = require('co-dash');
let getData = once(getData);
co(function*(){
let data1 = yield getData();
let data2 = yield getData();
// result is cached, getData is only called once
})
codash.filter(arr, fn)
const co = require('co');
const fs = require('co-fs');
const { filter } = require('co-dash');
co(function*(){
yield filter(['test1.log','test2.log'], fs.exists);
})
codash.map(arr, fn)
const co = require('co');
const fs = require('co-fs');
const { map } = require('co-dash');
co(function*(){
let files = yield map(['test1.log','test2.log'], fs.readFile);
//returns [ '...', '...' ]; array of files data
})
codash.each(arr, fn)
const co = require('co');
const fs = require('co-fs');
const { each } = require('co-dash');
co(function*(){
yield each(['test1.log','test2.log'], *function(fileName){
console.log(yield fs.stat(fileName))
});
})
codash.reduce(arr, fn, init)
const co = require('co');
const fs = require('co-fs');
const { reduce } = require('co-dash');
co(function*(){
let sum = yield reduce(['test1.log','test2.log'], *function(a, b){
return a + b
});
})
License
MIT