UNPKG

1.16 kBJavaScriptView Raw
1var _arity =
2/*#__PURE__*/
3require("./_arity");
4
5var _isPlaceholder =
6/*#__PURE__*/
7require("./_isPlaceholder");
8/**
9 * Internal curryN function.
10 *
11 * @private
12 * @category Function
13 * @param {Number} length The arity of the curried function.
14 * @param {Array} received An array of arguments received thus far.
15 * @param {Function} fn The function to curry.
16 * @return {Function} The curried function.
17 */
18
19
20function _curryN(length, received, fn) {
21 return function () {
22 var combined = [];
23 var argsIdx = 0;
24 var left = length;
25 var combinedIdx = 0;
26
27 while (combinedIdx < received.length || argsIdx < arguments.length) {
28 var result;
29
30 if (combinedIdx < received.length && (!_isPlaceholder(received[combinedIdx]) || argsIdx >= arguments.length)) {
31 result = received[combinedIdx];
32 } else {
33 result = arguments[argsIdx];
34 argsIdx += 1;
35 }
36
37 combined[combinedIdx] = result;
38
39 if (!_isPlaceholder(result)) {
40 left -= 1;
41 }
42
43 combinedIdx += 1;
44 }
45
46 return left <= 0 ? fn.apply(this, combined) : _arity(left, _curryN(length, combined, fn));
47 };
48}
49
50module.exports = _curryN;
\No newline at end of file