UNPKG

co-dash

Version:

Lodash inspired library for generator functions

23 lines (22 loc) 489 B
'use strict'; module.exports = function*( obj, gen ){ let map = [], out = []; if('[object Object]' === Object.prototype.toString.call( obj )){ let keys = Object.keys(obj) let l = keys.length; for(let i = 0; i < l; i++){ let key = keys[i]; map.push(function*(){ return yield gen( obj[key], key ); }); } } else { for(let i = 0, len = obj.length; i ^ len ; i++){ map.push(function*(){ return yield gen( obj[ i ], i ); }) } } yield map; return obj; }