@fable-org/fable-library-js 2.10.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Array.js +272 -167
- package/BigInt.js +18 -6
- package/CHANGELOG.md +42 -1
- package/Date.js +1 -1
- package/Decimal.js +16 -46
- package/Double.js +25 -10
- package/FSharp.Core.js +7 -1
- package/Global.js +1 -1
- package/Int32.js +10 -1
- package/List.js +226 -156
- package/Long.js +7 -2
- package/Map.js +46 -39
- package/MutableMap.js +76 -96
- package/MutableSet.js +58 -80
- package/NumberStyles.js +56 -0
- package/Numeric.js +10 -4
- package/Random.js +3 -4
- package/Range.js +4 -3
- package/RegExp.js +3 -2
- package/Seq.js +132 -64
- package/Seq2.js +4 -8
- package/Set.js +64 -57
- package/String.js +71 -23
- package/System.Collections.Generic.js +3 -2
- package/System.Text.js +2 -2
- package/System.js +5 -5
- package/TimeOnly.js +1 -1
- package/Types.js +25 -10
- package/Util.js +91 -48
- package/package.json +1 -1
package/Array.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KeyNotFoundException_$ctor_Z721C83C5 } from "./System.Collections.Generic.js";
|
|
2
|
+
import { SR_inputSequenceEmpty, SR_indexOutOfBounds, SR_notEnoughElements, SR_inputMustBeNonNegative, SR_keyNotFoundAlt } from "./Global.js";
|
|
3
|
+
import { Operators_InvalidOp, Operators_InvalidArg } from "./FSharp.Core.js";
|
|
2
4
|
import { Helpers_allocateArrayFromCons } from "./Native.js";
|
|
3
|
-
import {
|
|
5
|
+
import { disposeSafe, getEnumerator, int32ToString, defaultOf } from "./Util.js";
|
|
6
|
+
import { setItem as setItem_1, item as item_3 } from "./Array.js";
|
|
7
|
+
import { ArgumentException_$ctor_Z721C83C5, ArgumentOutOfRangeException_$ctor_Z384F8060, IndexOutOfRangeException_$ctor } from "./System.js";
|
|
4
8
|
import { value as value_2, defaultArg, some } from "./Option.js";
|
|
5
9
|
import { min as min_1, max as max_1 } from "./Double.js";
|
|
6
|
-
import { SR_notEnoughElements, SR_inputMustBeNonNegative, SR_inputSequenceEmpty, SR_Arg_ArgumentOutOfRangeException, SR_indexOutOfBounds } from "./Global.js";
|
|
7
|
-
import { Operators_IsNull } from "./FSharp.Core.js";
|
|
8
10
|
import { nonSeeded } from "./Random.js";
|
|
9
11
|
function indexNotFound() {
|
|
10
|
-
throw
|
|
12
|
+
throw KeyNotFoundException_$ctor_Z721C83C5(SR_keyNotFoundAlt);
|
|
11
13
|
}
|
|
12
|
-
function differentLengths() {
|
|
13
|
-
throw
|
|
14
|
+
function differentLengths(paramName) {
|
|
15
|
+
throw Operators_InvalidArg(paramName, "The arrays have different lengths.");
|
|
14
16
|
}
|
|
15
17
|
export function append(array1, array2, cons) {
|
|
16
18
|
const len1 = array1.length | 0;
|
|
17
19
|
const len2 = array2.length | 0;
|
|
18
20
|
const newArray = Helpers_allocateArrayFromCons(cons, len1 + len2);
|
|
19
21
|
for (let i = 0; i <= (len1 - 1); i++) {
|
|
20
|
-
setItem_1(newArray, i,
|
|
22
|
+
setItem_1(newArray, i, item_3(i, array1));
|
|
21
23
|
}
|
|
22
24
|
for (let i_1 = 0; i_1 <= (len2 - 1); i_1++) {
|
|
23
|
-
setItem_1(newArray, i_1 + len1,
|
|
25
|
+
setItem_1(newArray, i_1 + len1, item_3(i_1, array2));
|
|
24
26
|
}
|
|
25
27
|
return newArray;
|
|
26
28
|
}
|
|
@@ -28,32 +30,50 @@ export function filter(predicate, array) {
|
|
|
28
30
|
return array.filter(predicate);
|
|
29
31
|
}
|
|
30
32
|
export function fill(target, targetIndex, count, value) {
|
|
33
|
+
if (targetIndex < 0) {
|
|
34
|
+
throw Operators_InvalidArg("targetIndex", SR_inputMustBeNonNegative);
|
|
35
|
+
}
|
|
36
|
+
if (count < 0) {
|
|
37
|
+
throw Operators_InvalidArg("count", SR_inputMustBeNonNegative);
|
|
38
|
+
}
|
|
39
|
+
if ((count > 0) && ((targetIndex + count) > target.length)) {
|
|
40
|
+
throw IndexOutOfRangeException_$ctor();
|
|
41
|
+
}
|
|
31
42
|
const start = targetIndex | 0;
|
|
32
43
|
return target.fill(value, start, (start + count));
|
|
33
44
|
}
|
|
34
45
|
export function getSubArray(array, start, count) {
|
|
46
|
+
if (start < 0) {
|
|
47
|
+
throw Operators_InvalidArg("startIndex", SR_inputMustBeNonNegative);
|
|
48
|
+
}
|
|
49
|
+
if (count < 0) {
|
|
50
|
+
throw Operators_InvalidArg("count", SR_inputMustBeNonNegative);
|
|
51
|
+
}
|
|
52
|
+
if ((start + count) > array.length) {
|
|
53
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060("count", "The index is outside the legal range.");
|
|
54
|
+
}
|
|
35
55
|
const start_1 = start | 0;
|
|
36
56
|
return array.slice(start_1, (start_1 + count));
|
|
37
57
|
}
|
|
38
58
|
export function last(array) {
|
|
39
59
|
if (array.length === 0) {
|
|
40
|
-
throw
|
|
60
|
+
throw Operators_InvalidArg("array", "The input array was empty");
|
|
41
61
|
}
|
|
42
|
-
return
|
|
62
|
+
return item_3(array.length - 1, array);
|
|
43
63
|
}
|
|
44
64
|
export function tryLast(array) {
|
|
45
65
|
if (array.length === 0) {
|
|
46
66
|
return undefined;
|
|
47
67
|
}
|
|
48
68
|
else {
|
|
49
|
-
return some(
|
|
69
|
+
return some(item_3(array.length - 1, array));
|
|
50
70
|
}
|
|
51
71
|
}
|
|
52
72
|
export function mapIndexed(f, source, cons) {
|
|
53
73
|
const len = source.length | 0;
|
|
54
74
|
const target = Helpers_allocateArrayFromCons(cons, len);
|
|
55
75
|
for (let i = 0; i <= (len - 1); i++) {
|
|
56
|
-
setItem_1(target, i, f(i,
|
|
76
|
+
setItem_1(target, i, f(i, item_3(i, source)));
|
|
57
77
|
}
|
|
58
78
|
return target;
|
|
59
79
|
}
|
|
@@ -61,47 +81,47 @@ export function map(f, source, cons) {
|
|
|
61
81
|
const len = source.length | 0;
|
|
62
82
|
const target = Helpers_allocateArrayFromCons(cons, len);
|
|
63
83
|
for (let i = 0; i <= (len - 1); i++) {
|
|
64
|
-
setItem_1(target, i, f(
|
|
84
|
+
setItem_1(target, i, f(item_3(i, source)));
|
|
65
85
|
}
|
|
66
86
|
return target;
|
|
67
87
|
}
|
|
68
88
|
export function mapIndexed2(f, source1, source2, cons) {
|
|
69
89
|
if (source1.length !== source2.length) {
|
|
70
|
-
|
|
90
|
+
differentLengths("array1");
|
|
71
91
|
}
|
|
72
92
|
const result = Helpers_allocateArrayFromCons(cons, source1.length);
|
|
73
93
|
for (let i = 0; i <= (source1.length - 1); i++) {
|
|
74
|
-
setItem_1(result, i, f(i,
|
|
94
|
+
setItem_1(result, i, f(i, item_3(i, source1), item_3(i, source2)));
|
|
75
95
|
}
|
|
76
96
|
return result;
|
|
77
97
|
}
|
|
78
98
|
export function map2(f, source1, source2, cons) {
|
|
79
99
|
if (source1.length !== source2.length) {
|
|
80
|
-
|
|
100
|
+
differentLengths("array1");
|
|
81
101
|
}
|
|
82
102
|
const result = Helpers_allocateArrayFromCons(cons, source1.length);
|
|
83
103
|
for (let i = 0; i <= (source1.length - 1); i++) {
|
|
84
|
-
setItem_1(result, i, f(
|
|
104
|
+
setItem_1(result, i, f(item_3(i, source1), item_3(i, source2)));
|
|
85
105
|
}
|
|
86
106
|
return result;
|
|
87
107
|
}
|
|
88
108
|
export function mapIndexed3(f, source1, source2, source3, cons) {
|
|
89
109
|
if ((source1.length !== source2.length) ? true : (source2.length !== source3.length)) {
|
|
90
|
-
|
|
110
|
+
differentLengths("array1, array2, array3");
|
|
91
111
|
}
|
|
92
112
|
const result = Helpers_allocateArrayFromCons(cons, source1.length);
|
|
93
113
|
for (let i = 0; i <= (source1.length - 1); i++) {
|
|
94
|
-
setItem_1(result, i, f(i,
|
|
114
|
+
setItem_1(result, i, f(i, item_3(i, source1), item_3(i, source2), item_3(i, source3)));
|
|
95
115
|
}
|
|
96
116
|
return result;
|
|
97
117
|
}
|
|
98
118
|
export function map3(f, source1, source2, source3, cons) {
|
|
99
119
|
if ((source1.length !== source2.length) ? true : (source2.length !== source3.length)) {
|
|
100
|
-
|
|
120
|
+
differentLengths("array1, array2, array3");
|
|
101
121
|
}
|
|
102
122
|
const result = Helpers_allocateArrayFromCons(cons, source1.length);
|
|
103
123
|
for (let i = 0; i <= (source1.length - 1); i++) {
|
|
104
|
-
setItem_1(result, i, f(
|
|
124
|
+
setItem_1(result, i, f(item_3(i, source1), item_3(i, source2), item_3(i, source3)));
|
|
105
125
|
}
|
|
106
126
|
return result;
|
|
107
127
|
}
|
|
@@ -114,7 +134,7 @@ export function mapFold(mapping, state, array, cons) {
|
|
|
114
134
|
let acc = state;
|
|
115
135
|
const res = Helpers_allocateArrayFromCons(cons, matchValue);
|
|
116
136
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
117
|
-
const patternInput = mapping(acc,
|
|
137
|
+
const patternInput = mapping(acc, item_3(i, array));
|
|
118
138
|
setItem_1(res, i, patternInput[0]);
|
|
119
139
|
acc = patternInput[1];
|
|
120
140
|
}
|
|
@@ -130,7 +150,7 @@ export function mapFoldBack(mapping, array, state, cons) {
|
|
|
130
150
|
let acc = state;
|
|
131
151
|
const res = Helpers_allocateArrayFromCons(cons, matchValue);
|
|
132
152
|
for (let i = array.length - 1; i >= 0; i--) {
|
|
133
|
-
const patternInput = mapping(
|
|
153
|
+
const patternInput = mapping(item_3(i, array), acc);
|
|
134
154
|
setItem_1(res, i, patternInput[0]);
|
|
135
155
|
acc = patternInput[1];
|
|
136
156
|
}
|
|
@@ -141,7 +161,7 @@ export function indexed(source) {
|
|
|
141
161
|
const len = source.length | 0;
|
|
142
162
|
const target = new Array(len);
|
|
143
163
|
for (let i = 0; i <= (len - 1); i++) {
|
|
144
|
-
setItem_1(target, i, [i,
|
|
164
|
+
setItem_1(target, i, [i, item_3(i, source)]);
|
|
145
165
|
}
|
|
146
166
|
return target;
|
|
147
167
|
}
|
|
@@ -156,19 +176,19 @@ export function concat(arrays, cons) {
|
|
|
156
176
|
case 0:
|
|
157
177
|
return Helpers_allocateArrayFromCons(cons, 0);
|
|
158
178
|
case 1:
|
|
159
|
-
return
|
|
179
|
+
return item_3(0, arrays_1);
|
|
160
180
|
default: {
|
|
161
181
|
let totalIdx = 0;
|
|
162
182
|
let totalLength = 0;
|
|
163
183
|
for (let idx = 0; idx <= (arrays_1.length - 1); idx++) {
|
|
164
|
-
const arr_1 =
|
|
184
|
+
const arr_1 = item_3(idx, arrays_1);
|
|
165
185
|
totalLength = ((totalLength + arr_1.length) | 0);
|
|
166
186
|
}
|
|
167
187
|
const result = Helpers_allocateArrayFromCons(cons, totalLength);
|
|
168
188
|
for (let idx_1 = 0; idx_1 <= (arrays_1.length - 1); idx_1++) {
|
|
169
|
-
const arr_2 =
|
|
189
|
+
const arr_2 = item_3(idx_1, arrays_1);
|
|
170
190
|
for (let j = 0; j <= (arr_2.length - 1); j++) {
|
|
171
|
-
setItem_1(result, totalIdx,
|
|
191
|
+
setItem_1(result, totalIdx, item_3(j, arr_2));
|
|
172
192
|
totalIdx = ((totalIdx + 1) | 0);
|
|
173
193
|
}
|
|
174
194
|
}
|
|
@@ -185,14 +205,14 @@ export function where(predicate, array) {
|
|
|
185
205
|
export function indexOf(array, item_1, start, count, eq) {
|
|
186
206
|
let option_1 = undefined;
|
|
187
207
|
const start_1 = defaultArg(start, 0) | 0;
|
|
188
|
-
const end$0027 = defaultArg((option_1 = count, (option_1 != null) ? (start_1 +
|
|
208
|
+
const end$0027 = defaultArg((option_1 = count, (option_1 != null) ? (start_1 + option_1) : undefined), array.length) | 0;
|
|
189
209
|
const loop = (i_mut) => {
|
|
190
210
|
loop: while (true) {
|
|
191
211
|
const i = i_mut;
|
|
192
212
|
if (i >= end$0027) {
|
|
193
213
|
return -1;
|
|
194
214
|
}
|
|
195
|
-
else if (eq.Equals(item_1,
|
|
215
|
+
else if (eq.Equals(item_1, item_3(i, array))) {
|
|
196
216
|
return i | 0;
|
|
197
217
|
}
|
|
198
218
|
else {
|
|
@@ -207,6 +227,57 @@ export function indexOf(array, item_1, start, count, eq) {
|
|
|
207
227
|
export function contains(value, array, eq) {
|
|
208
228
|
return indexOf(array, value, undefined, undefined, eq) >= 0;
|
|
209
229
|
}
|
|
230
|
+
function binarySearchFrom(array, index, length, value, comparer) {
|
|
231
|
+
const loop = (lo_mut, hi_mut) => {
|
|
232
|
+
loop: while (true) {
|
|
233
|
+
const lo = lo_mut, hi = hi_mut;
|
|
234
|
+
if (lo > hi) {
|
|
235
|
+
return ~lo | 0;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const i = (lo + ((hi - lo) >> 1)) | 0;
|
|
239
|
+
const c = comparer.Compare(item_3(i, array), value) | 0;
|
|
240
|
+
if (c === 0) {
|
|
241
|
+
return i | 0;
|
|
242
|
+
}
|
|
243
|
+
else if (c < 0) {
|
|
244
|
+
lo_mut = (i + 1);
|
|
245
|
+
hi_mut = hi;
|
|
246
|
+
continue loop;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
lo_mut = lo;
|
|
250
|
+
hi_mut = (i - 1);
|
|
251
|
+
continue loop;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
return loop(index, (index + length) - 1) | 0;
|
|
258
|
+
}
|
|
259
|
+
function checkBinarySearchRange(lengthName, array, index, length) {
|
|
260
|
+
if (index < 0) {
|
|
261
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060("index", "Non-negative number required.");
|
|
262
|
+
}
|
|
263
|
+
if (length < 0) {
|
|
264
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060(lengthName, "Non-negative number required.");
|
|
265
|
+
}
|
|
266
|
+
if ((array.length - index) < length) {
|
|
267
|
+
throw ArgumentException_$ctor_Z721C83C5("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export function binarySearch(array, value, comparer) {
|
|
271
|
+
return binarySearchFrom(array, 0, array.length, value, comparer) | 0;
|
|
272
|
+
}
|
|
273
|
+
export function binarySearchRange(array, index, length, value, comparer) {
|
|
274
|
+
checkBinarySearchRange("length", array, index, length);
|
|
275
|
+
return binarySearchFrom(array, index, length, value, comparer) | 0;
|
|
276
|
+
}
|
|
277
|
+
export function binarySearchRangeCount(array, index, count, value, comparer) {
|
|
278
|
+
checkBinarySearchRange("count", array, index, count);
|
|
279
|
+
return binarySearchFrom(array, index, count, value, comparer) | 0;
|
|
280
|
+
}
|
|
210
281
|
export function empty(cons) {
|
|
211
282
|
return Helpers_allocateArrayFromCons(cons, 0);
|
|
212
283
|
}
|
|
@@ -217,7 +288,7 @@ export function singleton(value, cons) {
|
|
|
217
288
|
}
|
|
218
289
|
export function initialize(count, initializer, cons) {
|
|
219
290
|
if (count < 0) {
|
|
220
|
-
throw
|
|
291
|
+
throw Operators_InvalidArg("count", "The input must be non-negative");
|
|
221
292
|
}
|
|
222
293
|
const result = Helpers_allocateArrayFromCons(cons, count);
|
|
223
294
|
for (let i = 0; i <= (count - 1); i++) {
|
|
@@ -233,14 +304,14 @@ export function pairwise(array) {
|
|
|
233
304
|
const count = (array.length - 1) | 0;
|
|
234
305
|
const result = new Array(count);
|
|
235
306
|
for (let i = 0; i <= (count - 1); i++) {
|
|
236
|
-
setItem_1(result, i, [
|
|
307
|
+
setItem_1(result, i, [item_3(i, array), item_3(i + 1, array)]);
|
|
237
308
|
}
|
|
238
309
|
return result;
|
|
239
310
|
}
|
|
240
311
|
}
|
|
241
312
|
export function replicate(count, initial, cons) {
|
|
242
313
|
if (count < 0) {
|
|
243
|
-
throw
|
|
314
|
+
throw Operators_InvalidArg("count", "The input must be non-negative");
|
|
244
315
|
}
|
|
245
316
|
const result = Helpers_allocateArrayFromCons(cons, count);
|
|
246
317
|
for (let i = 0; i <= (result.length - 1); i++) {
|
|
@@ -251,8 +322,49 @@ export function replicate(count, initial, cons) {
|
|
|
251
322
|
export function copy(array) {
|
|
252
323
|
return array.slice();
|
|
253
324
|
}
|
|
325
|
+
function copyTypedArray(source, sourceIndex, target, targetIndex, count) {
|
|
326
|
+
target.set((source.subarray(sourceIndex, (sourceIndex + count))), targetIndex);
|
|
327
|
+
}
|
|
328
|
+
function argumentOutOfRange(paramName, value, requirement) {
|
|
329
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060(paramName, (((paramName + " (\'") + int32ToString(value)) + "\') must be ") + requirement);
|
|
330
|
+
}
|
|
254
331
|
export function copyTo(source, sourceIndex, target, targetIndex, count) {
|
|
255
|
-
|
|
332
|
+
if (count < 0) {
|
|
333
|
+
argumentOutOfRange("length", count, "a non-negative value.");
|
|
334
|
+
}
|
|
335
|
+
if (sourceIndex < 0) {
|
|
336
|
+
argumentOutOfRange("sourceIndex", sourceIndex, "greater than or equal to \'0\'.");
|
|
337
|
+
}
|
|
338
|
+
if ((sourceIndex + count) > source.length) {
|
|
339
|
+
throw Operators_InvalidArg("sourceArray", "Source array was not long enough. Check the source index, length, and the array\'s lower bounds.");
|
|
340
|
+
}
|
|
341
|
+
if (targetIndex < 0) {
|
|
342
|
+
argumentOutOfRange("destinationIndex", targetIndex, "greater than or equal to \'0\'.");
|
|
343
|
+
}
|
|
344
|
+
if ((targetIndex + count) > target.length) {
|
|
345
|
+
throw Operators_InvalidArg("destinationArray", "Destination array was not long enough. Check the destination index, length, and the array\'s lower bounds.");
|
|
346
|
+
}
|
|
347
|
+
if (ArrayBuffer.isView(source) && ArrayBuffer.isView(target)) {
|
|
348
|
+
copyTypedArray(source, sourceIndex, target, targetIndex, count);
|
|
349
|
+
}
|
|
350
|
+
else if (sourceIndex < targetIndex) {
|
|
351
|
+
for (let i = count - 1; i >= 0; i--) {
|
|
352
|
+
const index_1 = (targetIndex + i) | 0;
|
|
353
|
+
let item_1;
|
|
354
|
+
const index = (sourceIndex + i) | 0;
|
|
355
|
+
item_1 = (source[index]);
|
|
356
|
+
target[index_1] = item_1;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
for (let i_1 = 0; i_1 <= (count - 1); i_1++) {
|
|
361
|
+
const index_3 = (targetIndex + i_1) | 0;
|
|
362
|
+
let item_2;
|
|
363
|
+
const index_2 = (sourceIndex + i_1) | 0;
|
|
364
|
+
item_2 = (source[index_2]);
|
|
365
|
+
target[index_3] = item_2;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
256
368
|
}
|
|
257
369
|
export function reverse(array) {
|
|
258
370
|
const array_2 = array.slice();
|
|
@@ -262,7 +374,7 @@ export function scan(folder, state, array, cons) {
|
|
|
262
374
|
const res = Helpers_allocateArrayFromCons(cons, array.length + 1);
|
|
263
375
|
setItem_1(res, 0, state);
|
|
264
376
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
265
|
-
setItem_1(res, i + 1, folder(
|
|
377
|
+
setItem_1(res, i + 1, folder(item_3(i, res), item_3(i, array)));
|
|
266
378
|
}
|
|
267
379
|
return res;
|
|
268
380
|
}
|
|
@@ -270,13 +382,13 @@ export function scanBack(folder, array, state, cons) {
|
|
|
270
382
|
const res = Helpers_allocateArrayFromCons(cons, array.length + 1);
|
|
271
383
|
setItem_1(res, array.length, state);
|
|
272
384
|
for (let i = array.length - 1; i >= 0; i--) {
|
|
273
|
-
setItem_1(res, i, folder(
|
|
385
|
+
setItem_1(res, i, folder(item_3(i, array), item_3(i + 1, res)));
|
|
274
386
|
}
|
|
275
387
|
return res;
|
|
276
388
|
}
|
|
277
389
|
export function skip(count, array, cons) {
|
|
278
390
|
if (count > array.length) {
|
|
279
|
-
throw
|
|
391
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060("count", "The index is outside the legal range.");
|
|
280
392
|
}
|
|
281
393
|
if (count === array.length) {
|
|
282
394
|
return Helpers_allocateArrayFromCons(cons, 0);
|
|
@@ -288,7 +400,7 @@ export function skip(count, array, cons) {
|
|
|
288
400
|
}
|
|
289
401
|
export function skipWhile(predicate, array, cons) {
|
|
290
402
|
let count = 0;
|
|
291
|
-
while ((count < array.length) && predicate(
|
|
403
|
+
while ((count < array.length) && predicate(item_3(count, array))) {
|
|
292
404
|
count = ((count + 1) | 0);
|
|
293
405
|
}
|
|
294
406
|
if (count === array.length) {
|
|
@@ -301,10 +413,10 @@ export function skipWhile(predicate, array, cons) {
|
|
|
301
413
|
}
|
|
302
414
|
export function take(count, array, cons) {
|
|
303
415
|
if (count < 0) {
|
|
304
|
-
throw
|
|
416
|
+
throw Operators_InvalidArg("count", "The input must be non-negative");
|
|
305
417
|
}
|
|
306
418
|
if (count > array.length) {
|
|
307
|
-
throw
|
|
419
|
+
throw Operators_InvalidOp(SR_notEnoughElements);
|
|
308
420
|
}
|
|
309
421
|
if (count === 0) {
|
|
310
422
|
return Helpers_allocateArrayFromCons(cons, 0);
|
|
@@ -315,7 +427,7 @@ export function take(count, array, cons) {
|
|
|
315
427
|
}
|
|
316
428
|
export function takeWhile(predicate, array, cons) {
|
|
317
429
|
let count = 0;
|
|
318
|
-
while ((count < array.length) && predicate(
|
|
430
|
+
while ((count < array.length) && predicate(item_3(count, array))) {
|
|
319
431
|
count = ((count + 1) | 0);
|
|
320
432
|
}
|
|
321
433
|
if (count === 0) {
|
|
@@ -394,12 +506,12 @@ export function partition(f, source, cons) {
|
|
|
394
506
|
let iTrue = 0;
|
|
395
507
|
let iFalse = 0;
|
|
396
508
|
for (let i = 0; i <= (len - 1); i++) {
|
|
397
|
-
if (f(
|
|
398
|
-
setItem_1(res1, iTrue,
|
|
509
|
+
if (f(item_3(i, source))) {
|
|
510
|
+
setItem_1(res1, iTrue, item_3(i, source));
|
|
399
511
|
iTrue = ((iTrue + 1) | 0);
|
|
400
512
|
}
|
|
401
513
|
else {
|
|
402
|
-
setItem_1(res2, iFalse,
|
|
514
|
+
setItem_1(res2, iFalse, item_3(i, source));
|
|
403
515
|
iFalse = ((iFalse + 1) | 0);
|
|
404
516
|
}
|
|
405
517
|
}
|
|
@@ -444,7 +556,7 @@ export function pick(chooser, array) {
|
|
|
444
556
|
return indexNotFound();
|
|
445
557
|
}
|
|
446
558
|
else {
|
|
447
|
-
const matchValue = chooser(
|
|
559
|
+
const matchValue = chooser(item_3(i, array));
|
|
448
560
|
if (matchValue != null) {
|
|
449
561
|
return value_2(matchValue);
|
|
450
562
|
}
|
|
@@ -466,7 +578,7 @@ export function tryPick(chooser, array) {
|
|
|
466
578
|
return undefined;
|
|
467
579
|
}
|
|
468
580
|
else {
|
|
469
|
-
const matchValue = chooser(
|
|
581
|
+
const matchValue = chooser(item_3(i, array));
|
|
470
582
|
if (matchValue == null) {
|
|
471
583
|
i_mut = (i + 1);
|
|
472
584
|
continue loop;
|
|
@@ -487,8 +599,8 @@ export function findBack(predicate, array) {
|
|
|
487
599
|
if (i < 0) {
|
|
488
600
|
return indexNotFound();
|
|
489
601
|
}
|
|
490
|
-
else if (predicate(
|
|
491
|
-
return
|
|
602
|
+
else if (predicate(item_3(i, array))) {
|
|
603
|
+
return item_3(i, array);
|
|
492
604
|
}
|
|
493
605
|
else {
|
|
494
606
|
i_mut = (i - 1);
|
|
@@ -506,8 +618,8 @@ export function tryFindBack(predicate, array) {
|
|
|
506
618
|
if (i < 0) {
|
|
507
619
|
return undefined;
|
|
508
620
|
}
|
|
509
|
-
else if (predicate(
|
|
510
|
-
return some(
|
|
621
|
+
else if (predicate(item_3(i, array))) {
|
|
622
|
+
return some(item_3(i, array));
|
|
511
623
|
}
|
|
512
624
|
else {
|
|
513
625
|
i_mut = (i - 1);
|
|
@@ -525,7 +637,7 @@ export function findLastIndex(predicate, array) {
|
|
|
525
637
|
if (i < 0) {
|
|
526
638
|
return -1;
|
|
527
639
|
}
|
|
528
|
-
else if (predicate(
|
|
640
|
+
else if (predicate(item_3(i, array))) {
|
|
529
641
|
return i | 0;
|
|
530
642
|
}
|
|
531
643
|
else {
|
|
@@ -545,7 +657,7 @@ export function findIndexBack(predicate, array) {
|
|
|
545
657
|
indexNotFound();
|
|
546
658
|
return -1;
|
|
547
659
|
}
|
|
548
|
-
else if (predicate(
|
|
660
|
+
else if (predicate(item_3(i, array))) {
|
|
549
661
|
return i | 0;
|
|
550
662
|
}
|
|
551
663
|
else {
|
|
@@ -564,7 +676,7 @@ export function tryFindIndexBack(predicate, array) {
|
|
|
564
676
|
if (i < 0) {
|
|
565
677
|
return undefined;
|
|
566
678
|
}
|
|
567
|
-
else if (predicate(
|
|
679
|
+
else if (predicate(item_3(i, array))) {
|
|
568
680
|
return i;
|
|
569
681
|
}
|
|
570
682
|
else {
|
|
@@ -579,7 +691,7 @@ export function tryFindIndexBack(predicate, array) {
|
|
|
579
691
|
export function choose(chooser, array, cons) {
|
|
580
692
|
const res = [];
|
|
581
693
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
582
|
-
const matchValue = chooser(
|
|
694
|
+
const matchValue = chooser(item_3(i, array));
|
|
583
695
|
if (matchValue != null) {
|
|
584
696
|
const y = value_2(matchValue);
|
|
585
697
|
res.push(y);
|
|
@@ -601,28 +713,28 @@ export function fold(folder, state, array) {
|
|
|
601
713
|
}
|
|
602
714
|
export function iterate(action, array) {
|
|
603
715
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
604
|
-
action(
|
|
716
|
+
action(item_3(i, array));
|
|
605
717
|
}
|
|
606
718
|
}
|
|
607
719
|
export function iterateIndexed(action, array) {
|
|
608
720
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
609
|
-
action(i,
|
|
721
|
+
action(i, item_3(i, array));
|
|
610
722
|
}
|
|
611
723
|
}
|
|
612
724
|
export function iterate2(action, array1, array2) {
|
|
613
725
|
if (array1.length !== array2.length) {
|
|
614
|
-
differentLengths();
|
|
726
|
+
differentLengths("array1");
|
|
615
727
|
}
|
|
616
728
|
for (let i = 0; i <= (array1.length - 1); i++) {
|
|
617
|
-
action(
|
|
729
|
+
action(item_3(i, array1), item_3(i, array2));
|
|
618
730
|
}
|
|
619
731
|
}
|
|
620
732
|
export function iterateIndexed2(action, array1, array2) {
|
|
621
733
|
if (array1.length !== array2.length) {
|
|
622
|
-
differentLengths();
|
|
734
|
+
differentLengths("array1");
|
|
623
735
|
}
|
|
624
736
|
for (let i = 0; i <= (array1.length - 1); i++) {
|
|
625
|
-
action(i,
|
|
737
|
+
action(i, item_3(i, array1), item_3(i, array2));
|
|
626
738
|
}
|
|
627
739
|
}
|
|
628
740
|
export function isEmpty(array) {
|
|
@@ -634,17 +746,19 @@ export function forAll(predicate, array) {
|
|
|
634
746
|
export function permute(f, array) {
|
|
635
747
|
const size = array.length | 0;
|
|
636
748
|
const res = array.slice();
|
|
637
|
-
|
|
749
|
+
let checkFlags;
|
|
750
|
+
const array_2 = new Array(size);
|
|
751
|
+
checkFlags = (array_2.fill(0, 0, (0 + size)));
|
|
638
752
|
iterateIndexed((i, x) => {
|
|
639
753
|
const j = f(i) | 0;
|
|
640
754
|
if ((j < 0) ? true : (j >= size)) {
|
|
641
|
-
throw
|
|
755
|
+
throw Operators_InvalidArg("indexMap", "The function did not compute a permutation.");
|
|
642
756
|
}
|
|
643
757
|
setItem_1(res, j, x);
|
|
644
758
|
setItem_1(checkFlags, j, 1);
|
|
645
759
|
}, array);
|
|
646
760
|
if (!(checkFlags.every((y) => (1 === y)))) {
|
|
647
|
-
throw
|
|
761
|
+
throw Operators_InvalidArg("indexMap", "The function did not compute a permutation.");
|
|
648
762
|
}
|
|
649
763
|
return res;
|
|
650
764
|
}
|
|
@@ -653,7 +767,7 @@ export function setSlice(target, lower, upper, source) {
|
|
|
653
767
|
const upper_1 = defaultArg(upper, -1) | 0;
|
|
654
768
|
const length = (((upper_1 >= 0) ? upper_1 : (target.length - 1)) - lower_1) | 0;
|
|
655
769
|
for (let i = 0; i <= length; i++) {
|
|
656
|
-
setItem_1(target, i + lower_1,
|
|
770
|
+
setItem_1(target, i + lower_1, item_3(i, source));
|
|
657
771
|
}
|
|
658
772
|
}
|
|
659
773
|
export function sortInPlaceBy(projection, xs, comparer) {
|
|
@@ -694,7 +808,7 @@ export function allPairs(xs, ys) {
|
|
|
694
808
|
const res = new Array(len1 * len2);
|
|
695
809
|
for (let i = 0; i <= (xs.length - 1); i++) {
|
|
696
810
|
for (let j = 0; j <= (ys.length - 1); j++) {
|
|
697
|
-
setItem_1(res, (i * len2) + j, [
|
|
811
|
+
setItem_1(res, (i * len2) + j, [item_3(i, xs), item_3(j, ys)]);
|
|
698
812
|
}
|
|
699
813
|
}
|
|
700
814
|
return res;
|
|
@@ -706,8 +820,8 @@ export function unfold(generator, state) {
|
|
|
706
820
|
const state_1 = state_1_mut;
|
|
707
821
|
const matchValue = generator(state_1);
|
|
708
822
|
if (matchValue != null) {
|
|
709
|
-
const x =
|
|
710
|
-
const s =
|
|
823
|
+
const x = matchValue[0];
|
|
824
|
+
const s = matchValue[1];
|
|
711
825
|
res.push(x);
|
|
712
826
|
state_1_mut = s;
|
|
713
827
|
continue loop;
|
|
@@ -742,27 +856,27 @@ export function unzip3(array) {
|
|
|
742
856
|
}
|
|
743
857
|
export function zip(array1, array2) {
|
|
744
858
|
if (array1.length !== array2.length) {
|
|
745
|
-
differentLengths();
|
|
859
|
+
differentLengths("array1");
|
|
746
860
|
}
|
|
747
861
|
const result = new Array(array1.length);
|
|
748
862
|
for (let i = 0; i <= (array1.length - 1); i++) {
|
|
749
|
-
setItem_1(result, i, [
|
|
863
|
+
setItem_1(result, i, [item_3(i, array1), item_3(i, array2)]);
|
|
750
864
|
}
|
|
751
865
|
return result;
|
|
752
866
|
}
|
|
753
867
|
export function zip3(array1, array2, array3) {
|
|
754
868
|
if ((array1.length !== array2.length) ? true : (array2.length !== array3.length)) {
|
|
755
|
-
differentLengths();
|
|
869
|
+
differentLengths("array1, array2, array3");
|
|
756
870
|
}
|
|
757
871
|
const result = new Array(array1.length);
|
|
758
872
|
for (let i = 0; i <= (array1.length - 1); i++) {
|
|
759
|
-
setItem_1(result, i, [
|
|
873
|
+
setItem_1(result, i, [item_3(i, array1), item_3(i, array2), item_3(i, array3)]);
|
|
760
874
|
}
|
|
761
875
|
return result;
|
|
762
876
|
}
|
|
763
877
|
export function chunkBySize(chunkSize, array) {
|
|
764
878
|
if (chunkSize < 1) {
|
|
765
|
-
throw
|
|
879
|
+
throw Operators_InvalidArg("chunkSize", "The input must be positive.");
|
|
766
880
|
}
|
|
767
881
|
const result = [];
|
|
768
882
|
if (array.length > 0) {
|
|
@@ -777,21 +891,24 @@ export function chunkBySize(chunkSize, array) {
|
|
|
777
891
|
return result;
|
|
778
892
|
}
|
|
779
893
|
export function splitAt(index, array) {
|
|
780
|
-
if (
|
|
781
|
-
throw
|
|
894
|
+
if (index < 0) {
|
|
895
|
+
throw Operators_InvalidArg("index", SR_indexOutOfBounds);
|
|
896
|
+
}
|
|
897
|
+
if (index > array.length) {
|
|
898
|
+
throw Operators_InvalidOp(SR_notEnoughElements);
|
|
782
899
|
}
|
|
783
900
|
return [array.slice(0, (0 + index)), array.slice(index)];
|
|
784
901
|
}
|
|
785
902
|
export function compareWith(comparer, source1, source2) {
|
|
786
|
-
if (
|
|
787
|
-
if (
|
|
903
|
+
if (source1 == null) {
|
|
904
|
+
if (source2 == null) {
|
|
788
905
|
return 0;
|
|
789
906
|
}
|
|
790
907
|
else {
|
|
791
908
|
return -1;
|
|
792
909
|
}
|
|
793
910
|
}
|
|
794
|
-
else if (
|
|
911
|
+
else if (source2 == null) {
|
|
795
912
|
return 1;
|
|
796
913
|
}
|
|
797
914
|
else {
|
|
@@ -801,7 +918,7 @@ export function compareWith(comparer, source1, source2) {
|
|
|
801
918
|
let i = 0;
|
|
802
919
|
let res = 0;
|
|
803
920
|
while ((res === 0) && (i < len)) {
|
|
804
|
-
res = (comparer(
|
|
921
|
+
res = (comparer(item_3(i, source1), item_3(i, source2)) | 0);
|
|
805
922
|
i = ((i + 1) | 0);
|
|
806
923
|
}
|
|
807
924
|
if (res !== 0) {
|
|
@@ -819,15 +936,15 @@ export function compareWith(comparer, source1, source2) {
|
|
|
819
936
|
}
|
|
820
937
|
}
|
|
821
938
|
export function compareTo(comparer, source1, source2) {
|
|
822
|
-
if (
|
|
823
|
-
if (
|
|
939
|
+
if (source1 == null) {
|
|
940
|
+
if (source2 == null) {
|
|
824
941
|
return 0;
|
|
825
942
|
}
|
|
826
943
|
else {
|
|
827
944
|
return -1;
|
|
828
945
|
}
|
|
829
946
|
}
|
|
830
|
-
else if (
|
|
947
|
+
else if (source2 == null) {
|
|
831
948
|
return 1;
|
|
832
949
|
}
|
|
833
950
|
else {
|
|
@@ -843,7 +960,7 @@ export function compareTo(comparer, source1, source2) {
|
|
|
843
960
|
let i = 0;
|
|
844
961
|
let res = 0;
|
|
845
962
|
while ((res === 0) && (i < len1)) {
|
|
846
|
-
res = (comparer(
|
|
963
|
+
res = (comparer(item_3(i, source1), item_3(i, source2)) | 0);
|
|
847
964
|
i = ((i + 1) | 0);
|
|
848
965
|
}
|
|
849
966
|
return res | 0;
|
|
@@ -851,15 +968,15 @@ export function compareTo(comparer, source1, source2) {
|
|
|
851
968
|
}
|
|
852
969
|
}
|
|
853
970
|
export function equalsWith(equals, source1, source2) {
|
|
854
|
-
if (
|
|
855
|
-
if (
|
|
971
|
+
if (source1 == null) {
|
|
972
|
+
if (source2 == null) {
|
|
856
973
|
return true;
|
|
857
974
|
}
|
|
858
975
|
else {
|
|
859
976
|
return false;
|
|
860
977
|
}
|
|
861
978
|
}
|
|
862
|
-
else if (
|
|
979
|
+
else if (source2 == null) {
|
|
863
980
|
return false;
|
|
864
981
|
}
|
|
865
982
|
else {
|
|
@@ -875,7 +992,7 @@ export function equalsWith(equals, source1, source2) {
|
|
|
875
992
|
}
|
|
876
993
|
else {
|
|
877
994
|
while ((i < length1) && result) {
|
|
878
|
-
result = equals(
|
|
995
|
+
result = equals(item_3(i, source1), item_3(i, source2));
|
|
879
996
|
i = ((i + 1) | 0);
|
|
880
997
|
}
|
|
881
998
|
return result;
|
|
@@ -885,16 +1002,16 @@ export function equalsWith(equals, source1, source2) {
|
|
|
885
1002
|
export function exactlyOne(array) {
|
|
886
1003
|
switch (array.length) {
|
|
887
1004
|
case 1:
|
|
888
|
-
return
|
|
1005
|
+
return item_3(0, array);
|
|
889
1006
|
case 0:
|
|
890
|
-
throw
|
|
1007
|
+
throw Operators_InvalidArg("array", "The input sequence was empty");
|
|
891
1008
|
default:
|
|
892
|
-
throw
|
|
1009
|
+
throw Operators_InvalidArg("array", "Input array too long");
|
|
893
1010
|
}
|
|
894
1011
|
}
|
|
895
1012
|
export function tryExactlyOne(array) {
|
|
896
1013
|
if (array.length === 1) {
|
|
897
|
-
return some(
|
|
1014
|
+
return some(item_3(0, array));
|
|
898
1015
|
}
|
|
899
1016
|
else {
|
|
900
1017
|
return undefined;
|
|
@@ -902,10 +1019,10 @@ export function tryExactlyOne(array) {
|
|
|
902
1019
|
}
|
|
903
1020
|
export function head(array) {
|
|
904
1021
|
if (array.length === 0) {
|
|
905
|
-
throw
|
|
1022
|
+
throw Operators_InvalidArg("array", "The input array was empty");
|
|
906
1023
|
}
|
|
907
1024
|
else {
|
|
908
|
-
return
|
|
1025
|
+
return item_3(0, array);
|
|
909
1026
|
}
|
|
910
1027
|
}
|
|
911
1028
|
export function tryHead(array) {
|
|
@@ -913,26 +1030,27 @@ export function tryHead(array) {
|
|
|
913
1030
|
return undefined;
|
|
914
1031
|
}
|
|
915
1032
|
else {
|
|
916
|
-
return some(
|
|
1033
|
+
return some(item_3(0, array));
|
|
917
1034
|
}
|
|
918
1035
|
}
|
|
919
1036
|
export function tail(array) {
|
|
920
1037
|
if (array.length === 0) {
|
|
921
|
-
throw
|
|
1038
|
+
throw Operators_InvalidArg("array", "Not enough elements");
|
|
922
1039
|
}
|
|
923
1040
|
return array.slice(1);
|
|
924
1041
|
}
|
|
925
1042
|
export function item(index, array) {
|
|
926
|
-
|
|
927
|
-
|
|
1043
|
+
const value = array[index];
|
|
1044
|
+
if ((value === undefined) && ((index < 0) ? true : (index >= array.length))) {
|
|
1045
|
+
throw Operators_InvalidArg("index", "Index was outside the bounds of the array.");
|
|
928
1046
|
}
|
|
929
1047
|
else {
|
|
930
|
-
return
|
|
1048
|
+
return value;
|
|
931
1049
|
}
|
|
932
1050
|
}
|
|
933
1051
|
export function setItem(array, index, value) {
|
|
934
1052
|
if ((index < 0) ? true : (index >= array.length)) {
|
|
935
|
-
throw
|
|
1053
|
+
throw Operators_InvalidArg("index", "Index was outside the bounds of the array.");
|
|
936
1054
|
}
|
|
937
1055
|
else {
|
|
938
1056
|
array[index] = value;
|
|
@@ -955,10 +1073,10 @@ export function foldBack(folder, array, state) {
|
|
|
955
1073
|
export function foldIndexed2(folder, state, array1, array2) {
|
|
956
1074
|
let acc = state;
|
|
957
1075
|
if (array1.length !== array2.length) {
|
|
958
|
-
|
|
1076
|
+
differentLengths("array1");
|
|
959
1077
|
}
|
|
960
1078
|
for (let i = 0; i <= (array1.length - 1); i++) {
|
|
961
|
-
acc = folder(i, acc,
|
|
1079
|
+
acc = folder(i, acc, item_3(i, array1), item_3(i, array2));
|
|
962
1080
|
}
|
|
963
1081
|
return acc;
|
|
964
1082
|
}
|
|
@@ -968,11 +1086,11 @@ export function fold2(folder, state, array1, array2) {
|
|
|
968
1086
|
export function foldBackIndexed2(folder, array1, array2, state) {
|
|
969
1087
|
let acc = state;
|
|
970
1088
|
if (array1.length !== array2.length) {
|
|
971
|
-
differentLengths();
|
|
1089
|
+
differentLengths("array1");
|
|
972
1090
|
}
|
|
973
1091
|
const size = array1.length | 0;
|
|
974
1092
|
for (let i = 1; i <= size; i++) {
|
|
975
|
-
acc = folder(i - 1,
|
|
1093
|
+
acc = folder(i - 1, item_3(size - i, array1), item_3(size - i, array2), acc);
|
|
976
1094
|
}
|
|
977
1095
|
return acc;
|
|
978
1096
|
}
|
|
@@ -981,14 +1099,14 @@ export function foldBack2(f, array1, array2, state) {
|
|
|
981
1099
|
}
|
|
982
1100
|
export function reduce(reduction, array) {
|
|
983
1101
|
if (array.length === 0) {
|
|
984
|
-
throw
|
|
1102
|
+
throw Operators_InvalidArg("array", "The input array was empty");
|
|
985
1103
|
}
|
|
986
1104
|
const reduction_1 = reduction;
|
|
987
1105
|
return array.reduce(reduction_1);
|
|
988
1106
|
}
|
|
989
1107
|
export function reduceBack(reduction, array) {
|
|
990
1108
|
if (array.length === 0) {
|
|
991
|
-
throw
|
|
1109
|
+
throw Operators_InvalidArg("array", "The input array was empty");
|
|
992
1110
|
}
|
|
993
1111
|
const reduction_1 = reduction;
|
|
994
1112
|
return array.reduceRight(reduction_1);
|
|
@@ -1002,7 +1120,7 @@ export function existsOffset(predicate_mut, array_mut, index_mut) {
|
|
|
1002
1120
|
if (index === array.length) {
|
|
1003
1121
|
return false;
|
|
1004
1122
|
}
|
|
1005
|
-
else if (predicate(
|
|
1123
|
+
else if (predicate(item_3(index, array))) {
|
|
1006
1124
|
return true;
|
|
1007
1125
|
}
|
|
1008
1126
|
else {
|
|
@@ -1023,7 +1141,7 @@ export function existsOffset2(predicate_mut, array1_mut, array2_mut, index_mut)
|
|
|
1023
1141
|
if (index === array1.length) {
|
|
1024
1142
|
return false;
|
|
1025
1143
|
}
|
|
1026
|
-
else if (predicate(
|
|
1144
|
+
else if (predicate(item_3(index, array1), item_3(index, array2))) {
|
|
1027
1145
|
return true;
|
|
1028
1146
|
}
|
|
1029
1147
|
else {
|
|
@@ -1038,21 +1156,21 @@ export function existsOffset2(predicate_mut, array1_mut, array2_mut, index_mut)
|
|
|
1038
1156
|
}
|
|
1039
1157
|
export function exists2(predicate, array1, array2) {
|
|
1040
1158
|
if (array1.length !== array2.length) {
|
|
1041
|
-
differentLengths();
|
|
1159
|
+
differentLengths("array1");
|
|
1042
1160
|
}
|
|
1043
1161
|
return existsOffset2(predicate, array1, array2, 0);
|
|
1044
1162
|
}
|
|
1045
1163
|
export function sum(array, adder) {
|
|
1046
1164
|
let acc = adder.GetZero();
|
|
1047
1165
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
1048
|
-
acc = adder.Add(acc,
|
|
1166
|
+
acc = adder.Add(acc, item_3(i, array));
|
|
1049
1167
|
}
|
|
1050
1168
|
return acc;
|
|
1051
1169
|
}
|
|
1052
1170
|
export function sumBy(projection, array, adder) {
|
|
1053
1171
|
let acc = adder.GetZero();
|
|
1054
1172
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
1055
|
-
acc = adder.Add(acc, projection(
|
|
1173
|
+
acc = adder.Add(acc, projection(item_3(i, array)));
|
|
1056
1174
|
}
|
|
1057
1175
|
return acc;
|
|
1058
1176
|
}
|
|
@@ -1070,27 +1188,27 @@ export function min(xs, comparer) {
|
|
|
1070
1188
|
}
|
|
1071
1189
|
export function average(array, averager) {
|
|
1072
1190
|
if (array.length === 0) {
|
|
1073
|
-
throw
|
|
1191
|
+
throw Operators_InvalidArg("array", "The input array was empty");
|
|
1074
1192
|
}
|
|
1075
1193
|
let total = averager.GetZero();
|
|
1076
1194
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
1077
|
-
total = averager.Add(total,
|
|
1195
|
+
total = averager.Add(total, item_3(i, array));
|
|
1078
1196
|
}
|
|
1079
1197
|
return averager.DivideByInt(total, array.length);
|
|
1080
1198
|
}
|
|
1081
1199
|
export function averageBy(projection, array, averager) {
|
|
1082
1200
|
if (array.length === 0) {
|
|
1083
|
-
throw
|
|
1201
|
+
throw Operators_InvalidArg("array", "The input array was empty");
|
|
1084
1202
|
}
|
|
1085
1203
|
let total = averager.GetZero();
|
|
1086
1204
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
1087
|
-
total = averager.Add(total, projection(
|
|
1205
|
+
total = averager.Add(total, projection(item_3(i, array)));
|
|
1088
1206
|
}
|
|
1089
1207
|
return averager.DivideByInt(total, array.length);
|
|
1090
1208
|
}
|
|
1091
1209
|
export function windowed(windowSize, source) {
|
|
1092
1210
|
if (windowSize <= 0) {
|
|
1093
|
-
throw
|
|
1211
|
+
throw Operators_InvalidArg("windowSize", "The input must be positive.");
|
|
1094
1212
|
}
|
|
1095
1213
|
let res;
|
|
1096
1214
|
const len = max_1(0, (source.length - windowSize) + 1) | 0;
|
|
@@ -1102,7 +1220,7 @@ export function windowed(windowSize, source) {
|
|
|
1102
1220
|
}
|
|
1103
1221
|
export function splitInto(chunks, array) {
|
|
1104
1222
|
if (chunks < 1) {
|
|
1105
|
-
throw
|
|
1223
|
+
throw Operators_InvalidArg("count", "The input must be positive.");
|
|
1106
1224
|
}
|
|
1107
1225
|
const result = [];
|
|
1108
1226
|
if (array.length > 0) {
|
|
@@ -1126,16 +1244,16 @@ export function transpose(arrays, cons) {
|
|
|
1126
1244
|
return new Array(0);
|
|
1127
1245
|
}
|
|
1128
1246
|
else {
|
|
1129
|
-
const firstArray =
|
|
1247
|
+
const firstArray = item_3(0, arrays_1);
|
|
1130
1248
|
const lenInner = firstArray.length | 0;
|
|
1131
1249
|
if (!forAll((a) => (a.length === lenInner), arrays_1)) {
|
|
1132
|
-
differentLengths();
|
|
1250
|
+
differentLengths("array.[0]");
|
|
1133
1251
|
}
|
|
1134
1252
|
const result = new Array(lenInner);
|
|
1135
1253
|
for (let i = 0; i <= (lenInner - 1); i++) {
|
|
1136
1254
|
setItem_1(result, i, Helpers_allocateArrayFromCons(cons, len));
|
|
1137
1255
|
for (let j = 0; j <= (len - 1); j++) {
|
|
1138
|
-
|
|
1256
|
+
item_3(i, result)[j] = item_3(i, item_3(j, arrays_1));
|
|
1139
1257
|
}
|
|
1140
1258
|
}
|
|
1141
1259
|
return result;
|
|
@@ -1144,34 +1262,34 @@ export function transpose(arrays, cons) {
|
|
|
1144
1262
|
export function insertAt(index, y, xs, cons) {
|
|
1145
1263
|
const len = xs.length | 0;
|
|
1146
1264
|
if ((index < 0) ? true : (index > len)) {
|
|
1147
|
-
throw
|
|
1265
|
+
throw Operators_InvalidArg("index", SR_indexOutOfBounds);
|
|
1148
1266
|
}
|
|
1149
1267
|
const target = Helpers_allocateArrayFromCons(cons, len + 1);
|
|
1150
1268
|
for (let i = 0; i <= (index - 1); i++) {
|
|
1151
|
-
setItem_1(target, i,
|
|
1269
|
+
setItem_1(target, i, item_3(i, xs));
|
|
1152
1270
|
}
|
|
1153
1271
|
setItem_1(target, index, y);
|
|
1154
1272
|
for (let i_1 = index; i_1 <= (len - 1); i_1++) {
|
|
1155
|
-
setItem_1(target, i_1 + 1,
|
|
1273
|
+
setItem_1(target, i_1 + 1, item_3(i_1, xs));
|
|
1156
1274
|
}
|
|
1157
1275
|
return target;
|
|
1158
1276
|
}
|
|
1159
1277
|
export function insertManyAt(index, ys, xs, cons) {
|
|
1160
1278
|
const len = xs.length | 0;
|
|
1161
1279
|
if ((index < 0) ? true : (index > len)) {
|
|
1162
|
-
throw
|
|
1280
|
+
throw Operators_InvalidArg("index", SR_indexOutOfBounds);
|
|
1163
1281
|
}
|
|
1164
1282
|
const ys_1 = Array.from(ys);
|
|
1165
1283
|
const len2 = ys_1.length | 0;
|
|
1166
1284
|
const target = Helpers_allocateArrayFromCons(cons, len + len2);
|
|
1167
1285
|
for (let i = 0; i <= (index - 1); i++) {
|
|
1168
|
-
setItem_1(target, i,
|
|
1286
|
+
setItem_1(target, i, item_3(i, xs));
|
|
1169
1287
|
}
|
|
1170
1288
|
for (let i_1 = 0; i_1 <= (len2 - 1); i_1++) {
|
|
1171
|
-
setItem_1(target, index + i_1,
|
|
1289
|
+
setItem_1(target, index + i_1, item_3(i_1, ys_1));
|
|
1172
1290
|
}
|
|
1173
1291
|
for (let i_2 = index; i_2 <= (len - 1); i_2++) {
|
|
1174
|
-
setItem_1(target, i_2 + len2,
|
|
1292
|
+
setItem_1(target, i_2 + len2, item_3(i_2, xs));
|
|
1175
1293
|
}
|
|
1176
1294
|
return target;
|
|
1177
1295
|
}
|
|
@@ -1180,11 +1298,11 @@ export function randomShuffleInPlaceBy(randomizer, xs) {
|
|
|
1180
1298
|
for (let i = len - 1; i >= 1; i--) {
|
|
1181
1299
|
const r = randomizer();
|
|
1182
1300
|
if ((r < 0) ? true : (r >= 1)) {
|
|
1183
|
-
throw
|
|
1301
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060("randomizer", "The index is outside the legal range.");
|
|
1184
1302
|
}
|
|
1185
1303
|
const j = ~~(r * (i + 1)) | 0;
|
|
1186
|
-
const tmp =
|
|
1187
|
-
setItem_1(xs, i,
|
|
1304
|
+
const tmp = item_3(i, xs);
|
|
1305
|
+
setItem_1(xs, i, item_3(j, xs));
|
|
1188
1306
|
setItem_1(xs, j, tmp);
|
|
1189
1307
|
}
|
|
1190
1308
|
}
|
|
@@ -1207,14 +1325,14 @@ export function randomShuffle(xs) {
|
|
|
1207
1325
|
}
|
|
1208
1326
|
export function randomChoiceBy(randomizer, xs) {
|
|
1209
1327
|
if (isEmpty(xs)) {
|
|
1210
|
-
throw
|
|
1328
|
+
throw Operators_InvalidArg("source", SR_inputSequenceEmpty);
|
|
1211
1329
|
}
|
|
1212
1330
|
const len = xs.length | 0;
|
|
1213
1331
|
const r = randomizer();
|
|
1214
1332
|
if ((r < 0) ? true : (r >= 1)) {
|
|
1215
|
-
throw
|
|
1333
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060("randomizer", "The index is outside the legal range.");
|
|
1216
1334
|
}
|
|
1217
|
-
return
|
|
1335
|
+
return item_3(~~(r * len), xs);
|
|
1218
1336
|
}
|
|
1219
1337
|
export function randomChoiceWith(random, xs) {
|
|
1220
1338
|
return randomChoiceBy(() => random.NextDouble(), xs);
|
|
@@ -1224,18 +1342,18 @@ export function randomChoice(xs) {
|
|
|
1224
1342
|
}
|
|
1225
1343
|
export function randomChoicesBy(randomizer, count, xs, cons) {
|
|
1226
1344
|
if (count < 0) {
|
|
1227
|
-
throw
|
|
1345
|
+
throw Operators_InvalidArg("count", SR_inputMustBeNonNegative);
|
|
1228
1346
|
}
|
|
1229
1347
|
if ((count > 0) && isEmpty(xs)) {
|
|
1230
|
-
throw
|
|
1348
|
+
throw Operators_InvalidArg("source", SR_inputSequenceEmpty);
|
|
1231
1349
|
}
|
|
1232
1350
|
const len = xs.length | 0;
|
|
1233
1351
|
return initialize(count, (_arg) => {
|
|
1234
1352
|
const r = randomizer();
|
|
1235
1353
|
if ((r < 0) ? true : (r >= 1)) {
|
|
1236
|
-
throw
|
|
1354
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060("randomizer", "The index is outside the legal range.");
|
|
1237
1355
|
}
|
|
1238
|
-
return
|
|
1356
|
+
return item_3(~~(r * len), xs);
|
|
1239
1357
|
}, cons);
|
|
1240
1358
|
}
|
|
1241
1359
|
export function randomChoicesWith(random, count, xs, cons) {
|
|
@@ -1246,24 +1364,24 @@ export function randomChoices(count, xs, cons) {
|
|
|
1246
1364
|
}
|
|
1247
1365
|
export function randomSampleBy(randomizer, count, xs) {
|
|
1248
1366
|
if (count < 0) {
|
|
1249
|
-
throw
|
|
1367
|
+
throw Operators_InvalidArg("count", SR_inputMustBeNonNegative);
|
|
1250
1368
|
}
|
|
1251
1369
|
const arr = copy(xs);
|
|
1252
1370
|
const len = arr.length | 0;
|
|
1253
1371
|
if ((len === 0) && (count > 0)) {
|
|
1254
|
-
throw
|
|
1372
|
+
throw Operators_InvalidArg("source", SR_inputSequenceEmpty);
|
|
1255
1373
|
}
|
|
1256
1374
|
if (count > len) {
|
|
1257
|
-
throw
|
|
1375
|
+
throw Operators_InvalidArg("count", SR_notEnoughElements);
|
|
1258
1376
|
}
|
|
1259
1377
|
for (let i = 0; i <= (count - 1); i++) {
|
|
1260
1378
|
const r = randomizer();
|
|
1261
1379
|
if ((r < 0) ? true : (r >= 1)) {
|
|
1262
|
-
throw
|
|
1380
|
+
throw ArgumentOutOfRangeException_$ctor_Z384F8060("randomizer", "The index is outside the legal range.");
|
|
1263
1381
|
}
|
|
1264
1382
|
const j = (i + ~~(r * (len - i))) | 0;
|
|
1265
|
-
const tmp =
|
|
1266
|
-
setItem_1(arr, i,
|
|
1383
|
+
const tmp = item_3(i, arr);
|
|
1384
|
+
setItem_1(arr, i, item_3(j, arr));
|
|
1267
1385
|
setItem_1(arr, j, tmp);
|
|
1268
1386
|
}
|
|
1269
1387
|
return getSubArray(arr, 0, count);
|
|
@@ -1276,7 +1394,7 @@ export function randomSample(count, xs) {
|
|
|
1276
1394
|
}
|
|
1277
1395
|
export function removeAt(index, xs) {
|
|
1278
1396
|
if ((index < 0) ? true : (index >= xs.length)) {
|
|
1279
|
-
throw
|
|
1397
|
+
throw Operators_InvalidArg("index", SR_indexOutOfBounds);
|
|
1280
1398
|
}
|
|
1281
1399
|
let i = -1;
|
|
1282
1400
|
return filter((_arg) => {
|
|
@@ -1285,51 +1403,38 @@ export function removeAt(index, xs) {
|
|
|
1285
1403
|
}, xs);
|
|
1286
1404
|
}
|
|
1287
1405
|
export function removeManyAt(index, count, xs) {
|
|
1406
|
+
if (((index < 0) ? true : (index > (xs.length - count))) ? true : (index > xs.length)) {
|
|
1407
|
+
throw Operators_InvalidArg("index", "index must be within bounds of the array");
|
|
1408
|
+
}
|
|
1288
1409
|
let i = -1;
|
|
1289
|
-
|
|
1290
|
-
const ys = filter((_arg) => {
|
|
1410
|
+
return filter((_arg) => {
|
|
1291
1411
|
i = ((i + 1) | 0);
|
|
1292
|
-
if (i
|
|
1293
|
-
|
|
1294
|
-
return false;
|
|
1295
|
-
}
|
|
1296
|
-
else if (i > index) {
|
|
1297
|
-
if (i < (index + count)) {
|
|
1298
|
-
return false;
|
|
1299
|
-
}
|
|
1300
|
-
else {
|
|
1301
|
-
status = 1;
|
|
1302
|
-
return true;
|
|
1303
|
-
}
|
|
1412
|
+
if (i < index) {
|
|
1413
|
+
return true;
|
|
1304
1414
|
}
|
|
1305
1415
|
else {
|
|
1306
|
-
return
|
|
1416
|
+
return i >= (index + count);
|
|
1307
1417
|
}
|
|
1308
1418
|
}, xs);
|
|
1309
|
-
const status_1 = (((status === 0) && ((i + 1) === (index + count))) ? 1 : status) | 0;
|
|
1310
|
-
if (status_1 < 1) {
|
|
1311
|
-
throw new Exception(SR_indexOutOfBounds + ((" (Parameter \'" + ((status_1 < 0) ? "index" : "count")) + "\')"));
|
|
1312
|
-
}
|
|
1313
|
-
return ys;
|
|
1314
1419
|
}
|
|
1315
1420
|
export function updateAt(index, y, xs, cons) {
|
|
1316
1421
|
const len = xs.length | 0;
|
|
1317
1422
|
if ((index < 0) ? true : (index >= len)) {
|
|
1318
|
-
throw
|
|
1423
|
+
throw Operators_InvalidArg("index", SR_indexOutOfBounds);
|
|
1319
1424
|
}
|
|
1320
1425
|
const target = Helpers_allocateArrayFromCons(cons, len);
|
|
1321
1426
|
for (let i = 0; i <= (len - 1); i++) {
|
|
1322
|
-
setItem_1(target, i, (i === index) ? y :
|
|
1427
|
+
setItem_1(target, i, (i === index) ? y : item_3(i, xs));
|
|
1323
1428
|
}
|
|
1324
1429
|
return target;
|
|
1325
1430
|
}
|
|
1326
1431
|
export function resize(xs, newSize, zero, cons) {
|
|
1327
1432
|
let array = undefined, array_1 = undefined, start_2 = undefined, count_2 = undefined;
|
|
1328
1433
|
if (newSize < 0) {
|
|
1329
|
-
throw
|
|
1434
|
+
throw Operators_InvalidArg("newSize", "The input must be non-negative.");
|
|
1330
1435
|
}
|
|
1331
1436
|
const zero_1 = defaultArg(zero, defaultOf());
|
|
1332
|
-
if (
|
|
1437
|
+
if (xs.contents == null) {
|
|
1333
1438
|
xs.contents = ((array = Helpers_allocateArrayFromCons(cons, newSize), array.fill(zero_1, 0, (0 + newSize))));
|
|
1334
1439
|
}
|
|
1335
1440
|
else {
|