source: node_modules/ramda/src/internal/_curryN.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1var _arity =
2/*#__PURE__*/
3require("./_arity.js");
4
5var _isPlaceholder =
6/*#__PURE__*/
7require("./_isPlaceholder.js");
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 var hasPlaceholder = false;
27
28 while (combinedIdx < received.length || argsIdx < arguments.length) {
29 var result;
30
31 if (combinedIdx < received.length && (!_isPlaceholder(received[combinedIdx]) || argsIdx >= arguments.length)) {
32 result = received[combinedIdx];
33 } else {
34 result = arguments[argsIdx];
35 argsIdx += 1;
36 }
37
38 combined[combinedIdx] = result;
39
40 if (!_isPlaceholder(result)) {
41 left -= 1;
42 } else {
43 hasPlaceholder = true;
44 }
45
46 combinedIdx += 1;
47 }
48
49 return !hasPlaceholder && left <= 0 ? fn.apply(this, combined) : _arity(Math.max(0, left), _curryN(length, combined, fn));
50 };
51}
52
53module.exports = _curryN;
Note: See TracBrowser for help on using the repository browser.