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.

26 lines
807 B

5 years ago
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = global || self, global.curri = factory());
  5. }(this, function () { 'use strict';
  6. /**
  7. * Function to curry any javascript method
  8. * @param {Function} fn - the target function we want to curry
  9. * @param {...[args]} acc - initial arguments
  10. * @returns {Function|*} it will return a function until the target function
  11. * will receive all of its arguments
  12. */
  13. function curry(fn, ...acc) {
  14. return (...args) => {
  15. args = [...acc, ...args];
  16. return args.length < fn.length ?
  17. curry(fn, ...args) :
  18. fn(...args)
  19. }
  20. }
  21. return curry;
  22. }));