2016-07-24 09:52:04 -07:00
|
|
|
define(['./_createWrap'], function(createWrap) {
|
2015-01-08 00:37:01 -08:00
|
|
|
|
2015-12-16 17:52:15 -08:00
|
|
|
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
|
|
|
|
var undefined;
|
|
|
|
|
|
2016-07-24 09:52:04 -07:00
|
|
|
/** Used to compose bitmasks for function metadata. */
|
2016-11-13 22:49:46 -08:00
|
|
|
var WRAP_ARY_FLAG = 128;
|
2015-01-08 00:37:01 -08:00
|
|
|
|
|
|
|
|
/**
|
2016-04-01 23:28:48 -07:00
|
|
|
* Creates a function that invokes `func`, with up to `n` arguments,
|
|
|
|
|
* ignoring any additional arguments.
|
2015-01-08 00:37:01 -08:00
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf _
|
2016-03-26 00:00:01 -07:00
|
|
|
* @since 3.0.0
|
2015-01-08 00:37:01 -08:00
|
|
|
* @category Function
|
|
|
|
|
* @param {Function} func The function to cap arguments for.
|
|
|
|
|
* @param {number} [n=func.length] The arity cap.
|
2016-03-26 00:00:01 -07:00
|
|
|
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
2016-05-07 11:49:46 -07:00
|
|
|
* @returns {Function} Returns the new capped function.
|
2015-01-08 00:37:01 -08:00
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* _.map(['6', '8', '10'], _.ary(parseInt, 1));
|
|
|
|
|
* // => [6, 8, 10]
|
|
|
|
|
*/
|
|
|
|
|
function ary(func, n, guard) {
|
2015-12-16 17:53:20 -08:00
|
|
|
n = guard ? undefined : n;
|
|
|
|
|
n = (func && n == null) ? func.length : n;
|
2016-11-13 22:49:46 -08:00
|
|
|
return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
|
2015-01-08 00:37:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
|
});
|