You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
415 B

4 years ago
  1. 'use strict';
  2. // TODO: Use rest/spread when targeting Node.js 6
  3. module.exports = function (input) {
  4. const args = Array.isArray(input) ? input : arguments;
  5. if (args.length === 0) {
  6. return Promise.reject(new Error('Expected at least one argument'));
  7. }
  8. return [].slice.call(args, 1).reduce((a, b) => {
  9. return function () {
  10. return Promise.resolve(a.apply(null, arguments)).then(b);
  11. };
  12. }, args[0]);
  13. };