pipe.js 611 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. var noop_1 = require('./noop');
  3. /* tslint:enable:max-line-length */
  4. function pipe() {
  5. var fns = [];
  6. for (var _i = 0; _i < arguments.length; _i++) {
  7. fns[_i - 0] = arguments[_i];
  8. }
  9. return pipeFromArray(fns);
  10. }
  11. exports.pipe = pipe;
  12. /* @internal */
  13. function pipeFromArray(fns) {
  14. if (!fns) {
  15. return noop_1.noop;
  16. }
  17. if (fns.length === 1) {
  18. return fns[0];
  19. }
  20. return function piped(input) {
  21. return fns.reduce(function (prev, fn) { return fn(prev); }, input);
  22. };
  23. }
  24. exports.pipeFromArray = pipeFromArray;
  25. //# sourceMappingURL=pipe.js.map