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