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.

32 lines
1.3 KiB

5 years ago
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.cumpa = {}));
  5. }(this, function (exports) { 'use strict';
  6. /**
  7. * Similar to compose but performs from left-to-right function composition.<br/>
  8. * {@link https://30secondsofcode.org/function#composeright see also}
  9. * @param {...[function]} fns) - list of unary function
  10. * @returns {*} result of the computation
  11. */
  12. const composeRight = (...fns) => compose(...fns.reverse());
  13. /**
  14. * Performs right-to-left function composition.<br/>
  15. * Use Array.prototype.reduce() to perform right-to-left function composition.<br/>
  16. * The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.<br/>
  17. * {@link https://30secondsofcode.org/function#compose original source code}
  18. * @param {...[function]} fns) - list of unary function
  19. * @returns {*} result of the computation
  20. */
  21. function compose(...fns) {
  22. return fns.reduce((f, g) => (...args) => f(g(...args)))
  23. }
  24. exports.composeRight = composeRight;
  25. exports.default = compose;
  26. Object.defineProperty(exports, '__esModule', { value: true });
  27. }));