Skip to content

Commit

Permalink
handle variadic and falsy results in concatLimit [fixes #1437]
Browse files Browse the repository at this point in the history
  • Loading branch information
hargasinski committed Jun 13, 2017
1 parent ee70042 commit 1382f30
Show file tree
Hide file tree
Showing 5 changed files with 446 additions and 88 deletions.
14 changes: 11 additions & 3 deletions lib/concatLimit.js
@@ -1,4 +1,6 @@
import noop from 'lodash/noop';
import wrapAsync from './internal/wrapAsync';
import slice from './internal/slice';
import mapLimit from './mapLimit';

/**
Expand All @@ -21,12 +23,18 @@ import mapLimit from './mapLimit';
*/
export default function(coll, limit, iteratee, callback) {
callback = callback || noop;
mapLimit(coll, limit, iteratee, function(err, mapResults) {
var _iteratee = wrapAsync(iteratee);
mapLimit(coll, limit, function(val, callback) {
_iteratee(val, function(err /*, ...args*/) {
if (err) return callback(err);
return callback(null, slice(arguments, 1));
});
}, function(err, mapResults) {
var result = [];

var _concat = Array.prototype.concat;
for (var i = 0; i < mapResults.length; i++) {
if (mapResults[i]) {
result = result.concat(mapResults[i]);
result = _concat.apply(result, mapResults[i]);
}
}

Expand Down

0 comments on commit 1382f30

Please sign in to comment.