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.

15 lines
486 B

4 years ago
  1. /**
  2. * Function to curry any javascript method
  3. * @param {Function} fn - the target function we want to curry
  4. * @param {...[args]} acc - initial arguments
  5. * @returns {Function|*} it will return a function until the target function
  6. * will receive all of its arguments
  7. */
  8. export default function curry(fn, ...acc) {
  9. return (...args) => {
  10. args = [...acc, ...args]
  11. return args.length < fn.length ?
  12. curry(fn, ...args) :
  13. fn(...args)
  14. }
  15. }