summaryrefslogtreecommitdiff
path: root/lib/internal/map.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/map.js')
-rw-r--r--lib/internal/map.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/internal/map.js b/lib/internal/map.js
new file mode 100644
index 0000000..a7c19ac
--- /dev/null
+++ b/lib/internal/map.js
@@ -0,0 +1,19 @@
+'use strict';
+
+import isArrayLike from 'lodash/isArrayLike';
+import noop from 'lodash/noop';
+import once from 'lodash/once';
+
+export default function _asyncMap(eachfn, arr, iterator, callback) {
+ callback = once(callback || noop);
+ arr = arr || [];
+ var results = isArrayLike(arr) ? [] : {};
+ eachfn(arr, function (value, index, callback) {
+ iterator(value, function (err, v) {
+ results[index] = v;
+ callback(err);
+ });
+ }, function (err) {
+ callback(err, results);
+ });
+}