Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / globule / node_modules / lodash / _createRecurry.js
1 var isLaziable = require('./_isLaziable'),
2     setData = require('./_setData'),
3     setWrapToString = require('./_setWrapToString');
4
5 /** Used to compose bitmasks for function metadata. */
6 var BIND_FLAG = 1,
7     BIND_KEY_FLAG = 2,
8     CURRY_BOUND_FLAG = 4,
9     CURRY_FLAG = 8,
10     PARTIAL_FLAG = 32,
11     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 & 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 ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
38   bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
39
40   if (!(bitmask & CURRY_BOUND_FLAG)) {
41     bitmask &= ~(BIND_FLAG | 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;