convertToFP.js 510 B

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