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 | |
---|
1 | import _arity from "./_arity.js";
|
---|
2 | import _isPlaceholder from "./_isPlaceholder.js";
|
---|
3 | /**
|
---|
4 | * Internal curryN function.
|
---|
5 | *
|
---|
6 | * @private
|
---|
7 | * @category Function
|
---|
8 | * @param {Number} length The arity of the curried function.
|
---|
9 | * @param {Array} received An array of arguments received thus far.
|
---|
10 | * @param {Function} fn The function to curry.
|
---|
11 | * @return {Function} The curried function.
|
---|
12 | */
|
---|
13 |
|
---|
14 | export default function _curryN(length, received, fn) {
|
---|
15 | return function () {
|
---|
16 | var combined = [];
|
---|
17 | var argsIdx = 0;
|
---|
18 | var left = length;
|
---|
19 | var combinedIdx = 0;
|
---|
20 | var hasPlaceholder = false;
|
---|
21 |
|
---|
22 | while (combinedIdx < received.length || argsIdx < arguments.length) {
|
---|
23 | var result;
|
---|
24 |
|
---|
25 | if (combinedIdx < received.length && (!_isPlaceholder(received[combinedIdx]) || argsIdx >= arguments.length)) {
|
---|
26 | result = received[combinedIdx];
|
---|
27 | } else {
|
---|
28 | result = arguments[argsIdx];
|
---|
29 | argsIdx += 1;
|
---|
30 | }
|
---|
31 |
|
---|
32 | combined[combinedIdx] = result;
|
---|
33 |
|
---|
34 | if (!_isPlaceholder(result)) {
|
---|
35 | left -= 1;
|
---|
36 | } else {
|
---|
37 | hasPlaceholder = true;
|
---|
38 | }
|
---|
39 |
|
---|
40 | combinedIdx += 1;
|
---|
41 | }
|
---|
42 |
|
---|
43 | return !hasPlaceholder && left <= 0 ? fn.apply(this, combined) : _arity(Math.max(0, left), _curryN(length, combined, fn));
|
---|
44 | };
|
---|
45 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.