diff --git a/lib/internal/filter.js b/lib/internal/filter.js index aa5580c1e..35527e20a 100644 --- a/lib/internal/filter.js +++ b/lib/internal/filter.js @@ -1,7 +1,10 @@ import arrayMap from 'lodash/_arrayMap'; import property from 'lodash/_baseProperty'; +import noop from 'lodash/noop'; +import once from './once'; export default function _filter(eachfn, arr, iteratee, callback) { + callback = once(callback || noop); var results = []; eachfn(arr, function (x, index, callback) { iteratee(x, function (err, v) { diff --git a/lib/mapValuesLimit.js b/lib/mapValuesLimit.js index bced0346e..f6e72ff43 100644 --- a/lib/mapValuesLimit.js +++ b/lib/mapValuesLimit.js @@ -1,5 +1,8 @@ import eachOfLimit from './eachOfLimit'; +import noop from 'lodash/noop'; +import once from './internal/once'; + /** * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a * time. @@ -21,6 +24,7 @@ import eachOfLimit from './eachOfLimit'; * transformed values from the `obj`. Invoked with (err, result). */ export default function mapValuesLimit(obj, limit, iteratee, callback) { + callback = once(callback || noop); var newObj = {}; eachOfLimit(obj, limit, function(val, key, next) { iteratee(val, key, function (err, result) { diff --git a/lib/reduce.js b/lib/reduce.js index 8145db793..47186310d 100644 --- a/lib/reduce.js +++ b/lib/reduce.js @@ -1,4 +1,6 @@ import eachOfSeries from './eachOfSeries'; +import noop from 'lodash/noop'; +import once from './internal/once'; /** * Reduces `coll` into a single value using an async `iteratee` to return each @@ -41,6 +43,7 @@ import eachOfSeries from './eachOfSeries'; * }); */ export default function reduce(coll, memo, iteratee, callback) { + callback = once(callback || noop); eachOfSeries(coll, function(x, i, callback) { iteratee(memo, x, function(err, v) { memo = v; diff --git a/lib/sortBy.js b/lib/sortBy.js index ab6c4206e..9b8ffe663 100644 --- a/lib/sortBy.js +++ b/lib/sortBy.js @@ -17,7 +17,7 @@ import map from './map'; * The iteratee is passed a `callback(err, sortValue)` which must be called once * it has completed with an error (which can be `null`) and a value to use as * the sort criteria. Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the + * @param {Function} callback - A callback which is called after all the * `iteratee` functions have finished, or an error occurs. Results is the items * from the original `coll` sorted by the values returned by the `iteratee` * calls. Invoked with (err, results). diff --git a/lib/transform.js b/lib/transform.js index 609852200..175ad8527 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -1,6 +1,8 @@ import isArray from 'lodash/isArray'; +import noop from 'lodash/noop'; import eachOf from './eachOf'; +import once from './internal/once'; /** * A relative of `reduce`. Takes an Object or Array, and iterates over each @@ -53,6 +55,7 @@ export default function transform (coll, accumulator, iteratee, callback) { iteratee = accumulator; accumulator = isArray(coll) ? [] : {}; } + callback = once(callback || noop); eachOf(coll, function(v, k, cb) { iteratee(accumulator, v, k, cb);