1var baseFlatten = require('../internal/baseFlatten'), 2 createWrapper = require('../internal/createWrapper'), 3 restParam = require('./restParam'); 4 5/** Used to compose bitmasks for wrapper metadata. */ 6var REARG_FLAG = 256; 7 8/** 9 * Creates a function that invokes `func` with arguments arranged according 10 * to the specified indexes where the argument value at the first index is 11 * provided as the first argument, the argument value at the second index is 12 * provided as the second argument, and so on. 13 * 14 * @static 15 * @memberOf _ 16 * @category Function 17 * @param {Function} func The function to rearrange arguments for. 18 * @param {...(number|number[])} indexes The arranged argument indexes, 19 * specified as individual indexes or arrays of indexes. 20 * @returns {Function} Returns the new function. 21 * @example 22 * 23 * var rearged = _.rearg(function(a, b, c) { 24 * return [a, b, c]; 25 * }, 2, 0, 1); 26 * 27 * rearged('b', 'c', 'a') 28 * // => ['a', 'b', 'c'] 29 * 30 * var map = _.rearg(_.map, [1, 0]); 31 * map(function(n) { 32 * return n * 3; 33 * }, [1, 2, 3]); 34 * // => [3, 6, 9] 35 */ 36var rearg = restParam(function(func, indexes) { 37 return createWrapper(func, REARG_FLAG, null, null, null, baseFlatten(indexes)); 38}); 39 40module.exports = rearg; 41 42