compose.js 640 B

1234567891011121314151617181920
  1. "use strict";
  2. var isValue = require("../../object/is-value")
  3. , callable = require("../../object/valid-callable")
  4. , aFrom = require("../../array/from");
  5. var apply = Function.prototype.apply
  6. , call = Function.prototype.call
  7. , callFn = function (arg, fn) { return call.call(fn, this, arg); };
  8. module.exports = function (fnIgnored/*, …fnn*/) {
  9. var fns, first;
  10. var args = aFrom(arguments);
  11. fns = isValue(this) ? [this].concat(args) : args;
  12. fns.forEach(callable);
  13. fns = fns.reverse();
  14. first = fns[0];
  15. fns = fns.slice(1);
  16. return function (argIgnored) { return fns.reduce(callFn, apply.call(first, this, arguments)); };
  17. };