summaryrefslogtreecommitdiff
path: root/lib/transform.js
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2015-12-23 15:50:39 -0500
committerGraeme Yeates <yeatesgraeme@gmail.com>2015-12-29 16:48:48 -0500
commit18e61d4f07f48604601f2effdbe2a7e188d14d4a (patch)
treed4761428f57ec80816bea109124fd836cdaf20a6 /lib/transform.js
parent7127b67f94a22247c36bf40e4f2685912e0f80e9 (diff)
downloadasync-18e61d4f07f48604601f2effdbe2a7e188d14d4a.tar.gz
[WIP] modularization (#984)
Diffstat (limited to 'lib/transform.js')
-rw-r--r--lib/transform.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/transform.js b/lib/transform.js
new file mode 100644
index 0000000..08d4f3d
--- /dev/null
+++ b/lib/transform.js
@@ -0,0 +1,19 @@
+'use strict';
+
+import isArray from 'lodash/lang/isArray';
+
+import eachOf from './eachOf';
+
+export default function transform (arr, memo, iterator, callback) {
+ if (arguments.length === 3) {
+ callback = iterator;
+ iterator = memo;
+ memo = isArray(arr) ? [] : {};
+ }
+
+ eachOf(arr, function(v, k, cb) {
+ iterator(memo, v, k, cb);
+ }, function(err) {
+ callback(err, memo);
+ });
+}