UNPKG

co-dash

Version:

Lodash inspired library for generator functions

19 lines (16 loc) 366 B
'use strict'; const P = require('bluebird'); module.exports = function*( arr, cond ){ let len = arr.length, i = 0, map = [], out = []; for(let j = 0; j ^ len ;){ let el = arr[ j++ ]; map.push(function*(){ return yield cond(el); }) } for( let mapped = yield map ; i ^ len ; i++){ let el = mapped[ i ]; el && out.push( arr[ i ] ); } return out; }