convertToFP.cjs 553 B

1234567891011121314151617181920
  1. "use strict";
  2. exports.convertToFP = convertToFP;
  3. /**
  4. * Converts a function to a curried function that accepts arguments in reverse
  5. * order.
  6. *
  7. * @param fn - The function to convert to FP
  8. * @param arity - The arity of the function
  9. * @param curriedArgs - The curried arguments
  10. *
  11. * @returns FP version of the function
  12. *
  13. * @private
  14. */
  15. function convertToFP(fn, arity, curriedArgs = []) {
  16. return curriedArgs.length >= arity
  17. ? fn(...curriedArgs.slice(0, arity).reverse())
  18. : (...args) => convertToFP(fn, arity, curriedArgs.concat(args));
  19. }