summaryrefslogtreecommitdiff
path: root/build-es/seq.js
diff options
context:
space:
mode:
Diffstat (limited to 'build-es/seq.js')
-rw-r--r--build-es/seq.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/build-es/seq.js b/build-es/seq.js
new file mode 100644
index 0000000..c9e02c1
--- /dev/null
+++ b/build-es/seq.js
@@ -0,0 +1,28 @@
+'use strict';
+
+import noop from 'lodash-es/noop';
+import rest from 'lodash-es/rest';
+import reduce from './reduce';
+
+export default function seq( /* functions... */ ) {
+ var fns = arguments;
+ return rest(function(args) {
+ var that = this;
+
+ var cb = args[args.length - 1];
+ if (typeof cb == 'function') {
+ args.pop();
+ } else {
+ cb = noop;
+ }
+
+ reduce(fns, args, function(newargs, fn, cb) {
+ fn.apply(that, newargs.concat([rest(function(err, nextargs) {
+ cb(err, nextargs);
+ })]));
+ },
+ function(err, results) {
+ cb.apply(that, [err].concat(results));
+ });
+ });
+}