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.

33 lines
1023 B

4 years ago
  1. var createWrap = require('./_createWrap'),
  2. flatRest = require('./_flatRest');
  3. /** Used to compose bitmasks for function metadata. */
  4. var WRAP_REARG_FLAG = 256;
  5. /**
  6. * Creates a function that invokes `func` with arguments arranged according
  7. * to the specified `indexes` where the argument value at the first index is
  8. * provided as the first argument, the argument value at the second index is
  9. * provided as the second argument, and so on.
  10. *
  11. * @static
  12. * @memberOf _
  13. * @since 3.0.0
  14. * @category Function
  15. * @param {Function} func The function to rearrange arguments for.
  16. * @param {...(number|number[])} indexes The arranged argument indexes.
  17. * @returns {Function} Returns the new function.
  18. * @example
  19. *
  20. * var rearged = _.rearg(function(a, b, c) {
  21. * return [a, b, c];
  22. * }, [2, 0, 1]);
  23. *
  24. * rearged('b', 'c', 'a')
  25. * // => ['a', 'b', 'c']
  26. */
  27. var rearg = flatRest(function(func, indexes) {
  28. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  29. });
  30. module.exports = rearg;