function createWrapper(func, bitmask, thisArg, partials, holders, argPos, arity) {
      var isBindKey = bitmask & BIND_KEY_FLAG;
      if (!isBindKey && !isFunction(func)) {
        throw new TypeError(FUNC_ERROR_TEXT);
      }
      var length = partials ? partials.length : 0;
      if (!length) {
        bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
        partials = holders = null;
      }
      if (partials && !holders) {
        holders = [];
      }
      var oldPartials = partials,
          oldHolders = holders,
          isPartial = bitmask & PARTIAL_FLAG,
          isPartialRight = bitmask & PARTIAL_RIGHT_FLAG;

      if (!isPartial) {
        var partialsRight = partials,
            holdersRight = holders;

        partials = holders = null;
      }
      var data = (data = !isBindKey && getData(func)) && data !== true && data;
      if (data) {
        var funcBitmask = data[1],
            funcIsBind = funcBitmask & BIND_FLAG,
            isBind = bitmask & BIND_FLAG;

        // use metadata `func` and merge bitmasks
        func = data[0];
        bitmask |= funcBitmask;

        // use metadata `thisArg` if available
        if (funcIsBind) {
          thisArg = data[2];
        }
        // set if currying a bound function
        if (!isBind && funcIsBind) {
          bitmask |= CURRY_BOUND_FLAG;
        }
        // compose partial arguments
        var value = data[3];
        if (value) {
          var funcHolders = data[4];
          partials = isPartial ? composeArgs(partials, value, funcHolders) : baseSlice(value);
          holders = isPartial ? replaceHolders(partials, PLACEHOLDER) : baseSlice(funcHolders);
        }
        // compose partial right arguments
        value = data[5];
        if (value) {
          funcHolders = data[6];
          partialsRight = isPartialRight ? composeArgsRight(partialsRight, value, funcHolders) : baseSlice(value);
          holdersRight = isPartialRight ? replaceHolders(partialsRight, PLACEHOLDER) : baseSlice(funcHolders);
        }
        // append argument positions
        value = data[7];
        if (value) {
          value = baseSlice(value);
          if (argPos) {
            push.apply(value, argPos);
          }
          argPos = value;
        }
        // use metadata `arity` if not provided
        if (arity == null) {
          arity = data[8];
        }
      }
      if (arity == null) {
        arity = isBindKey ? 0 : func.length;
      } else {
        arity = nativeMax(+arity || 0, 0);
      }
      if (oldPartials) {
        arity = nativeMax(arity - (oldPartials.length - oldHolders.length), 0);
      }
      if (bitmask == BIND_FLAG) {
        var result = createBindWrapper(func, thisArg);
      } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
        result = createPartialWrapper(func, bitmask, partials, thisArg);
      } else {
        result = createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, arity);
      }
      var setter = data ? baseSetData : setData;
      return setter(result, [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, arity]);
    }
Creates a function that either curries or invokes `func` with optional
`this` binding and partially applied arguments.

@private
@param {Function|string} func The function or method name to reference.
@param {number} bitmask The bitmask of flags.
 The bitmask may be composed of the following flags:
    1 - `_.bind`
    2 - `_.bindKey`
    4 - `_.curry`
    8 - `_.curryRight`
   16 - `_.curry` or `_.curryRight` of a bound function
   32 - `_.partial`
   64 - `_.partialRight`
  128 - `_.rearg`
@param {*} [thisArg] The `this` binding of `func`.
@param {Array} [partials] The arguments to be partially applied.
@param {Array} [holders] The `partialArgs` placeholder indexes.
@param {Array} [argPos] The argument positions of the new function.
@param {number} [arity] The arity of `func`.
@returns {Function} Returns the new wrapped function.