| 1 |
var isLaziable = require('./_isLaziable'), |
| 2 |
setData = require('./_setData'), |
| 3 |
setWrapToString = require('./_setWrapToString'); |
| 4 |
|
| 5 |
/** Used to compose bitmasks for function metadata. */ |
| 6 |
var WRAP_BIND_FLAG = 1, |
| 7 |
WRAP_BIND_KEY_FLAG = 2, |
| 8 |
WRAP_CURRY_BOUND_FLAG = 4, |
| 9 |
WRAP_CURRY_FLAG = 8, |
| 10 |
WRAP_PARTIAL_FLAG = 32, |
| 11 |
WRAP_PARTIAL_RIGHT_FLAG = 64; |
| 12 |
|
| 13 |
/** |
| 14 |
* Creates a function that wraps `func` to continue currying. |
| 15 |
* |
| 16 |
* @private |
| 17 |
* @param {Function} func The function to wrap. |
| 18 |
* @param {number} bitmask The bitmask flags. See `createWrap` for more details. |
| 19 |
* @param {Function} wrapFunc The function to create the `func` wrapper. |
| 20 |
* @param {*} placeholder The placeholder value. |
| 21 |
* @param {*} [thisArg] The `this` binding of `func`. |
| 22 |
* @param {Array} [partials] The arguments to prepend to those provided to |
| 23 |
* the new function. |
| 24 |
* @param {Array} [holders] The `partials` placeholder indexes. |
| 25 |
* @param {Array} [argPos] The argument positions of the new function. |
| 26 |
* @param {number} [ary] The arity cap of `func`. |
| 27 |
* @param {number} [arity] The arity of `func`. |
| 28 |
* @returns {Function} Returns the new wrapped function. |
| 29 |
*/ |
| 30 |
function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { |
| 31 |
var isCurry = bitmask & WRAP_CURRY_FLAG, |
| 32 |
newHolders = isCurry ? holders : undefined, |
| 33 |
newHoldersRight = isCurry ? undefined : holders, |
| 34 |
newPartials = isCurry ? partials : undefined, |
| 35 |
newPartialsRight = isCurry ? undefined : partials; |
| 36 |
|
| 37 |
bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG); |
| 38 |
bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG); |
| 39 |
|
| 40 |
if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) { |
| 41 |
bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG); |
| 42 |
} |
| 43 |
var newData = [ |
| 44 |
func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, |
| 45 |
newHoldersRight, argPos, ary, arity |
| 46 |
]; |
| 47 |
|
| 48 |
var result = wrapFunc.apply(undefined, newData); |
| 49 |
if (isLaziable(func)) { |
| 50 |
setData(result, newData); |
| 51 |
} |
| 52 |
result.placeholder = placeholder; |
| 53 |
return setWrapToString(result, func, bitmask); |
| 54 |
} |
| 55 |
|
| 56 |
module.exports = createRecurry; |