1 | import apply from './_apply.js';
|
---|
2 | import createCtor from './_createCtor.js';
|
---|
3 | import createHybrid from './_createHybrid.js';
|
---|
4 | import createRecurry from './_createRecurry.js';
|
---|
5 | import getHolder from './_getHolder.js';
|
---|
6 | import replaceHolders from './_replaceHolders.js';
|
---|
7 | import root from './_root.js';
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Creates a function that wraps `func` to enable currying.
|
---|
11 | *
|
---|
12 | * @private
|
---|
13 | * @param {Function} func The function to wrap.
|
---|
14 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
---|
15 | * @param {number} arity The arity of `func`.
|
---|
16 | * @returns {Function} Returns the new wrapped function.
|
---|
17 | */
|
---|
18 | function createCurry(func, bitmask, arity) {
|
---|
19 | var Ctor = createCtor(func);
|
---|
20 |
|
---|
21 | function wrapper() {
|
---|
22 | var length = arguments.length,
|
---|
23 | args = Array(length),
|
---|
24 | index = length,
|
---|
25 | placeholder = getHolder(wrapper);
|
---|
26 |
|
---|
27 | while (index--) {
|
---|
28 | args[index] = arguments[index];
|
---|
29 | }
|
---|
30 | var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
|
---|
31 | ? []
|
---|
32 | : replaceHolders(args, placeholder);
|
---|
33 |
|
---|
34 | length -= holders.length;
|
---|
35 | if (length < arity) {
|
---|
36 | return createRecurry(
|
---|
37 | func, bitmask, createHybrid, wrapper.placeholder, undefined,
|
---|
38 | args, holders, undefined, undefined, arity - length);
|
---|
39 | }
|
---|
40 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
---|
41 | return apply(fn, this, args);
|
---|
42 | }
|
---|
43 | return wrapper;
|
---|
44 | }
|
---|
45 |
|
---|
46 | export default createCurry;
|
---|