co-dash
Lodash inspired library for generator functions
Last updated 9 months ago by andrekulpin .
ISC · Original npm · Tarball
$ cnpm install co-dash 
SYNC missed versions from official npm registry.

co-dash

Lodash-inspired library for generators

Install

Install the package with npm:

$ 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

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |