|
2972 | 2972 | * @returns {Function} Returns the new wrapped function. |
2973 | 2973 | */ function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { |
2974 | 2974 | var isAry = 128 & bitmask, isBind = 1 & bitmask, isBindKey = 2 & bitmask, isCurried = 24 & bitmask, isFlip = 512 & bitmask, Ctor = isBindKey ? undefined : createCtor(func); |
2975 | | - return function wrapper() { |
| 2975 | + function wrapper() { |
2976 | 2976 | for(var length = arguments.length, args = Array1(length), index = length; index--;)args[index] = arguments[index]; |
2977 | 2977 | if (isCurried) var placeholder = getHolder(wrapper), holdersCount = /** |
2978 | 2978 | * Gets the number of `placeholder` occurrences in `array`. |
|
3006 | 3006 | } |
3007 | 3007 | return array; |
3008 | 3008 | }(args, argPos) : isFlip && length > 1 && args.reverse(), isAry && ary < length && (args.length = ary), this && this !== root && this instanceof wrapper && (fn = Ctor || createCtor(fn)), fn.apply(thisBinding, args); |
3009 | | - }; |
| 3009 | + } |
| 3010 | + return wrapper; |
3010 | 3011 | } |
3011 | 3012 | /** |
3012 | 3013 | * Creates a function like `_.invertBy`. |
|
3268 | 3269 | (value = source[7]) && (data[7] = value), 128 & srcBitmask && (data[8] = null == data[8] ? source[8] : nativeMin(data[8], source[8])), null == data[9] && (data[9] = source[9]), // Use source `func` and merge bitmasks. |
3269 | 3270 | data[0] = source[0], data[1] = newBitmask; |
3270 | 3271 | } |
3271 | | - }(newData, data), func = newData[0], bitmask = newData[1], thisArg = newData[2], partials = newData[3], holders = newData[4], (arity = newData[9] = newData[9] === undefined ? isBindKey ? 0 : func.length : nativeMax(newData[9] - length, 0)) || !(24 & bitmask) || (bitmask &= -25), bitmask && 1 != bitmask) 8 == bitmask || 16 == bitmask ? (func1 = func, bitmask1 = bitmask, arity1 = arity, Ctor = createCtor(func1), result = function wrapper() { |
3272 | | - for(var length = arguments.length, args = Array1(length), index = length, placeholder = getHolder(wrapper); index--;)args[index] = arguments[index]; |
3273 | | - var holders = length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder ? [] : replaceHolders(args, placeholder); |
3274 | | - return (length -= holders.length) < arity1 ? createRecurry(func1, bitmask1, createHybrid, wrapper.placeholder, undefined, args, holders, undefined, undefined, arity1 - length) : apply(this && this !== root && this instanceof wrapper ? Ctor : func1, this, args); |
3275 | | - }) : 32 != bitmask && 33 != bitmask || holders.length ? result = createHybrid.apply(undefined, newData) : (func2 = func, bitmask2 = bitmask, thisArg1 = thisArg, partials1 = partials, isBind = 1 & bitmask2, Ctor1 = createCtor(func2), result = function wrapper() { |
3276 | | - for(var argsIndex = -1, argsLength = arguments.length, leftIndex = -1, leftLength = partials1.length, args = Array1(leftLength + argsLength), fn = this && this !== root && this instanceof wrapper ? Ctor1 : func2; ++leftIndex < leftLength;)args[leftIndex] = partials1[leftIndex]; |
| 3272 | + }(newData, data), func = newData[0], bitmask = newData[1], thisArg = newData[2], partials = newData[3], holders = newData[4], (arity = newData[9] = newData[9] === undefined ? isBindKey ? 0 : func.length : nativeMax(newData[9] - length, 0)) || !(24 & bitmask) || (bitmask &= -25), bitmask && 1 != bitmask) 8 == bitmask || 16 == bitmask ? result = /** |
| 3273 | + * Creates a function that wraps `func` to enable currying. |
| 3274 | + * |
| 3275 | + * @private |
| 3276 | + * @param {Function} func The function to wrap. |
| 3277 | + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. |
| 3278 | + * @param {number} arity The arity of `func`. |
| 3279 | + * @returns {Function} Returns the new wrapped function. |
| 3280 | + */ function(func, bitmask, arity) { |
| 3281 | + var Ctor = createCtor(func); |
| 3282 | + function wrapper() { |
| 3283 | + for(var length = arguments.length, args = Array1(length), index = length, placeholder = getHolder(wrapper); index--;)args[index] = arguments[index]; |
| 3284 | + var holders = length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder ? [] : replaceHolders(args, placeholder); |
| 3285 | + return (length -= holders.length) < arity ? createRecurry(func, bitmask, createHybrid, wrapper.placeholder, undefined, args, holders, undefined, undefined, arity - length) : apply(this && this !== root && this instanceof wrapper ? Ctor : func, this, args); |
| 3286 | + } |
| 3287 | + return wrapper; |
| 3288 | + }(func, bitmask, arity) : 32 != bitmask && 33 != bitmask || holders.length ? result = createHybrid.apply(undefined, newData) : (func1 = func, bitmask1 = bitmask, thisArg1 = thisArg, partials1 = partials, isBind = 1 & bitmask1, Ctor = createCtor(func1), result = function wrapper() { |
| 3289 | + for(var argsIndex = -1, argsLength = arguments.length, leftIndex = -1, leftLength = partials1.length, args = Array1(leftLength + argsLength), fn = this && this !== root && this instanceof wrapper ? Ctor : func1; ++leftIndex < leftLength;)args[leftIndex] = partials1[leftIndex]; |
3277 | 3290 | for(; argsLength--;)args[leftIndex++] = arguments[++argsIndex]; |
3278 | 3291 | return apply(fn, isBind ? thisArg1 : this, args); |
3279 | 3292 | }); |
3280 | | - else var func1, bitmask1, arity1, Ctor, func2, bitmask2, thisArg1, partials1, isBind, Ctor1, func3, bitmask3, thisArg2, isBind1, Ctor2, result = (func3 = func, bitmask3 = bitmask, thisArg2 = thisArg, isBind1 = 1 & bitmask3, Ctor2 = createCtor(func3), function wrapper() { |
3281 | | - return (this && this !== root && this instanceof wrapper ? Ctor2 : func3).apply(isBind1 ? thisArg2 : this, arguments); |
| 3293 | + else var func1, bitmask1, thisArg1, partials1, isBind, Ctor, func2, bitmask2, thisArg2, isBind1, Ctor1, result = (func2 = func, bitmask2 = bitmask, thisArg2 = thisArg, isBind1 = 1 & bitmask2, Ctor1 = createCtor(func2), function wrapper() { |
| 3294 | + return (this && this !== root && this instanceof wrapper ? Ctor1 : func2).apply(isBind1 ? thisArg2 : this, arguments); |
3282 | 3295 | }); |
3283 | 3296 | return setWrapToString((data ? baseSetData : setData)(result, newData), func, bitmask); |
3284 | 3297 | } |
|
4563 | 4576 | return createWrap(key, bitmask, object, partials, holders); |
4564 | 4577 | }); |
4565 | 4578 | /** |
| 4579 | + * Creates a function that accepts arguments of `func` and either invokes |
| 4580 | + * `func` returning its result, if at least `arity` number of arguments have |
| 4581 | + * been provided, or returns a function that accepts the remaining `func` |
| 4582 | + * arguments, and so on. The arity of `func` may be specified if `func.length` |
| 4583 | + * is not sufficient. |
| 4584 | + * |
| 4585 | + * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, |
| 4586 | + * may be used as a placeholder for provided arguments. |
| 4587 | + * |
| 4588 | + * **Note:** This method doesn't set the "length" property of curried functions. |
| 4589 | + * |
| 4590 | + * @static |
| 4591 | + * @memberOf _ |
| 4592 | + * @since 2.0.0 |
| 4593 | + * @category Function |
| 4594 | + * @param {Function} func The function to curry. |
| 4595 | + * @param {number} [arity=func.length] The arity of `func`. |
| 4596 | + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. |
| 4597 | + * @returns {Function} Returns the new curried function. |
| 4598 | + * @example |
| 4599 | + * |
| 4600 | + * var abc = function(a, b, c) { |
| 4601 | + * return [a, b, c]; |
| 4602 | + * }; |
| 4603 | + * |
| 4604 | + * var curried = _.curry(abc); |
| 4605 | + * |
| 4606 | + * curried(1)(2)(3); |
| 4607 | + * // => [1, 2, 3] |
| 4608 | + * |
| 4609 | + * curried(1, 2)(3); |
| 4610 | + * // => [1, 2, 3] |
| 4611 | + * |
| 4612 | + * curried(1, 2, 3); |
| 4613 | + * // => [1, 2, 3] |
| 4614 | + * |
| 4615 | + * // Curried with placeholders. |
| 4616 | + * curried(1)(_, 3)(2); |
| 4617 | + * // => [1, 2, 3] |
| 4618 | + */ function curry(func, arity, guard) { |
| 4619 | + arity = guard ? undefined : arity; |
| 4620 | + var result = createWrap(func, 8, undefined, undefined, undefined, undefined, undefined, arity); |
| 4621 | + return result.placeholder = curry.placeholder, result; |
| 4622 | + } |
| 4623 | + /** |
| 4624 | + * This method is like `_.curry` except that arguments are applied to `func` |
| 4625 | + * in the manner of `_.partialRight` instead of `_.partial`. |
| 4626 | + * |
| 4627 | + * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic |
| 4628 | + * builds, may be used as a placeholder for provided arguments. |
| 4629 | + * |
| 4630 | + * **Note:** This method doesn't set the "length" property of curried functions. |
| 4631 | + * |
| 4632 | + * @static |
| 4633 | + * @memberOf _ |
| 4634 | + * @since 3.0.0 |
| 4635 | + * @category Function |
| 4636 | + * @param {Function} func The function to curry. |
| 4637 | + * @param {number} [arity=func.length] The arity of `func`. |
| 4638 | + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. |
| 4639 | + * @returns {Function} Returns the new curried function. |
| 4640 | + * @example |
| 4641 | + * |
| 4642 | + * var abc = function(a, b, c) { |
| 4643 | + * return [a, b, c]; |
| 4644 | + * }; |
| 4645 | + * |
| 4646 | + * var curried = _.curryRight(abc); |
| 4647 | + * |
| 4648 | + * curried(3)(2)(1); |
| 4649 | + * // => [1, 2, 3] |
| 4650 | + * |
| 4651 | + * curried(2, 3)(1); |
| 4652 | + * // => [1, 2, 3] |
| 4653 | + * |
| 4654 | + * curried(1, 2, 3); |
| 4655 | + * // => [1, 2, 3] |
| 4656 | + * |
| 4657 | + * // Curried with placeholders. |
| 4658 | + * curried(3)(1, _)(2); |
| 4659 | + * // => [1, 2, 3] |
| 4660 | + */ function curryRight(func, arity, guard) { |
| 4661 | + arity = guard ? undefined : arity; |
| 4662 | + var result = createWrap(func, 16, undefined, undefined, undefined, undefined, undefined, arity); |
| 4663 | + return result.placeholder = curryRight.placeholder, result; |
| 4664 | + } |
| 4665 | + /** |
4566 | 4666 | * Creates a debounced function that delays invoking `func` until after `wait` |
4567 | 4667 | * milliseconds have elapsed since the last time the debounced function was |
4568 | 4668 | * invoked. The debounced function comes with a `cancel` method to cancel |
|
6596 | 6696 | */ function(prototype, properties) { |
6597 | 6697 | var result = baseCreate(prototype); |
6598 | 6698 | return null == properties ? result : baseAssign(result, properties); |
6599 | | - }, lodash.curry = /** |
6600 | | - * Creates a function that accepts arguments of `func` and either invokes |
6601 | | - * `func` returning its result, if at least `arity` number of arguments have |
6602 | | - * been provided, or returns a function that accepts the remaining `func` |
6603 | | - * arguments, and so on. The arity of `func` may be specified if `func.length` |
6604 | | - * is not sufficient. |
6605 | | - * |
6606 | | - * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, |
6607 | | - * may be used as a placeholder for provided arguments. |
6608 | | - * |
6609 | | - * **Note:** This method doesn't set the "length" property of curried functions. |
6610 | | - * |
6611 | | - * @static |
6612 | | - * @memberOf _ |
6613 | | - * @since 2.0.0 |
6614 | | - * @category Function |
6615 | | - * @param {Function} func The function to curry. |
6616 | | - * @param {number} [arity=func.length] The arity of `func`. |
6617 | | - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. |
6618 | | - * @returns {Function} Returns the new curried function. |
6619 | | - * @example |
6620 | | - * |
6621 | | - * var abc = function(a, b, c) { |
6622 | | - * return [a, b, c]; |
6623 | | - * }; |
6624 | | - * |
6625 | | - * var curried = _.curry(abc); |
6626 | | - * |
6627 | | - * curried(1)(2)(3); |
6628 | | - * // => [1, 2, 3] |
6629 | | - * |
6630 | | - * curried(1, 2)(3); |
6631 | | - * // => [1, 2, 3] |
6632 | | - * |
6633 | | - * curried(1, 2, 3); |
6634 | | - * // => [1, 2, 3] |
6635 | | - * |
6636 | | - * // Curried with placeholders. |
6637 | | - * curried(1)(_, 3)(2); |
6638 | | - * // => [1, 2, 3] |
6639 | | - */ function curry(func, arity, guard) { |
6640 | | - arity = guard ? undefined : arity; |
6641 | | - var result = createWrap(func, 8, undefined, undefined, undefined, undefined, undefined, arity); |
6642 | | - return result.placeholder = curry.placeholder, result; |
6643 | | - }, lodash.curryRight = /** |
6644 | | - * This method is like `_.curry` except that arguments are applied to `func` |
6645 | | - * in the manner of `_.partialRight` instead of `_.partial`. |
6646 | | - * |
6647 | | - * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic |
6648 | | - * builds, may be used as a placeholder for provided arguments. |
6649 | | - * |
6650 | | - * **Note:** This method doesn't set the "length" property of curried functions. |
6651 | | - * |
6652 | | - * @static |
6653 | | - * @memberOf _ |
6654 | | - * @since 3.0.0 |
6655 | | - * @category Function |
6656 | | - * @param {Function} func The function to curry. |
6657 | | - * @param {number} [arity=func.length] The arity of `func`. |
6658 | | - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. |
6659 | | - * @returns {Function} Returns the new curried function. |
6660 | | - * @example |
6661 | | - * |
6662 | | - * var abc = function(a, b, c) { |
6663 | | - * return [a, b, c]; |
6664 | | - * }; |
6665 | | - * |
6666 | | - * var curried = _.curryRight(abc); |
6667 | | - * |
6668 | | - * curried(3)(2)(1); |
6669 | | - * // => [1, 2, 3] |
6670 | | - * |
6671 | | - * curried(2, 3)(1); |
6672 | | - * // => [1, 2, 3] |
6673 | | - * |
6674 | | - * curried(1, 2, 3); |
6675 | | - * // => [1, 2, 3] |
6676 | | - * |
6677 | | - * // Curried with placeholders. |
6678 | | - * curried(3)(1, _)(2); |
6679 | | - * // => [1, 2, 3] |
6680 | | - */ function curryRight(func, arity, guard) { |
6681 | | - arity = guard ? undefined : arity; |
6682 | | - var result = createWrap(func, 16, undefined, undefined, undefined, undefined, undefined, arity); |
6683 | | - return result.placeholder = curryRight.placeholder, result; |
6684 | | - }, lodash.debounce = debounce, lodash.defaults = defaults, lodash.defaultsDeep = defaultsDeep, lodash.defer = defer, lodash.delay = delay, lodash.difference = difference, lodash.differenceBy = differenceBy, lodash.differenceWith = differenceWith, lodash.drop = /** |
| 6699 | + }, lodash.curry = curry, lodash.curryRight = curryRight, lodash.debounce = debounce, lodash.defaults = defaults, lodash.defaultsDeep = defaultsDeep, lodash.defer = defer, lodash.delay = delay, lodash.difference = difference, lodash.differenceBy = differenceBy, lodash.differenceWith = differenceWith, lodash.drop = /** |
6685 | 6700 | * Creates a slice of `array` with `n` elements dropped from the beginning. |
6686 | 6701 | * |
6687 | 6702 | * @static |
|
0 commit comments