@fable-org/fable-library-ts 1.9.0 → 2.0.0-beta.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/Array.ts +1378 -1377
- package/CHANGELOG.md +11 -1
- package/Choice.ts +301 -301
- package/FSharp.Collections.ts +34 -34
- package/FSharp.Core.CompilerServices.ts +37 -37
- package/FSharp.Core.ts +184 -86
- package/Global.ts +37 -37
- package/List.ts +1417 -1417
- package/Map.ts +1552 -1552
- package/MutableMap.ts +345 -345
- package/MutableSet.ts +249 -249
- package/Native.ts +11 -11
- package/Random.ts +181 -180
- package/Range.ts +56 -56
- package/Result.ts +196 -196
- package/Seq.ts +1525 -1525
- package/Seq2.ts +129 -129
- package/Set.ts +1955 -1955
- package/System.Collections.Generic.ts +380 -380
- package/System.Text.ts +203 -197
- package/Types.ts +1 -1
- package/package.json +1 -1
package/Random.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { uint8, int32, float64 } from "./Int32.js";
|
|
2
|
-
import { class_type, TypeInfo } from "./Reflection.js";
|
|
3
|
-
import { fromFloat64, op_Addition, toInt32, toFloat64, compare, int64, fromInt32, toInt64 } from "./BigInt.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { uint8, int32, float64 } from "./Int32.js";
|
|
2
|
+
import { class_type, TypeInfo } from "./Reflection.js";
|
|
3
|
+
import { fromFloat64, op_Addition, toInt32, toFloat64, compare, int64, fromInt32, toInt64 } from "./BigInt.js";
|
|
4
|
+
import { Operators_IsNull } from "./FSharp.Core.js";
|
|
5
|
+
import { item, fill, setItem } from "./Array.js";
|
|
6
|
+
|
|
7
|
+
function Native_random(): float64 {
|
|
8
|
+
return Math.random();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function Native_randomNext(min: int32, max: int32): int32 {
|
|
11
12
|
if (max < min) {
|
|
12
13
|
throw new Error("minValue must be less than maxValue");
|
|
13
14
|
}
|
|
14
15
|
return Math.floor(Math.random() * (max - min)) + min
|
|
15
|
-
;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function Native_randomBytes(buffer: uint8[]): void {
|
|
16
|
+
;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function Native_randomBytes(buffer: uint8[]): void {
|
|
19
20
|
if (buffer == null) {
|
|
20
21
|
throw new Error("Buffer cannot be null");
|
|
21
22
|
}
|
|
@@ -28,169 +29,169 @@ function Native_randomBytes(buffer: uint8[]): void {
|
|
|
28
29
|
buffer[i + j] = r & 255;
|
|
29
30
|
r >>>= 8;
|
|
30
31
|
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface IRandom {
|
|
35
|
-
Next0(): int32,
|
|
36
|
-
Next1(maxValue: int32): int32,
|
|
37
|
-
Next2(minValue: int32, maxValue: int32): int32,
|
|
38
|
-
NextBytes(buffer: uint8[]): void,
|
|
39
|
-
NextDouble(): float64
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class NonSeeded implements IRandom {
|
|
43
|
-
constructor() {
|
|
44
|
-
}
|
|
45
|
-
Next0(): int32 {
|
|
46
|
-
return Native_randomNext(0, 2147483647);
|
|
47
|
-
}
|
|
48
|
-
Next1(maxValue: int32): int32 {
|
|
49
|
-
return Native_randomNext(0, maxValue);
|
|
50
|
-
}
|
|
51
|
-
Next2(minValue: int32, maxValue: int32): int32 {
|
|
52
|
-
return Native_randomNext(minValue, maxValue);
|
|
53
|
-
}
|
|
54
|
-
NextDouble(): float64 {
|
|
55
|
-
return Native_random();
|
|
56
|
-
}
|
|
57
|
-
NextBytes(buffer: uint8[]): void {
|
|
58
|
-
Native_randomBytes(buffer);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function NonSeeded_$reflection(): TypeInfo {
|
|
63
|
-
return class_type("Random.NonSeeded", undefined, NonSeeded);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function NonSeeded_$ctor(): NonSeeded {
|
|
67
|
-
return new NonSeeded();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export class Seeded implements IRandom {
|
|
71
|
-
readonly MBIG: int32;
|
|
72
|
-
inext: int32;
|
|
73
|
-
inextp: int32;
|
|
74
|
-
seedArray: int32[];
|
|
75
|
-
constructor(seed: int32) {
|
|
76
|
-
this.MBIG = 2147483647;
|
|
77
|
-
this.inext = 0;
|
|
78
|
-
this.inextp = 0;
|
|
79
|
-
this.seedArray = fill(new Array(56), 0, 56, 0);
|
|
80
|
-
let ii = 0;
|
|
81
|
-
let mj = 0;
|
|
82
|
-
let mk = 0;
|
|
83
|
-
const subtraction: int32 = ((seed === -2147483648) ? 2147483647 : Math.abs(seed)) | 0;
|
|
84
|
-
mj = ((161803398 - subtraction) | 0);
|
|
85
|
-
this.seedArray[55] = (mj | 0);
|
|
86
|
-
mk = 1;
|
|
87
|
-
for (let i = 1; i <= 54; i++) {
|
|
88
|
-
ii = (((21 * i) % 55) | 0);
|
|
89
|
-
this.seedArray[ii] = (mk | 0);
|
|
90
|
-
mk = ((mj - mk) | 0);
|
|
91
|
-
if (mk < 0) {
|
|
92
|
-
mk = ((mk + this.MBIG) | 0);
|
|
93
|
-
}
|
|
94
|
-
mj = (item(ii, this.seedArray) | 0);
|
|
95
|
-
}
|
|
96
|
-
for (let k = 1; k <= 4; k++) {
|
|
97
|
-
for (let i_1 = 1; i_1 <= 55; i_1++) {
|
|
98
|
-
this.seedArray[i_1] = ((item(i_1, this.seedArray) - item(1 + ((i_1 + 30) % 55), this.seedArray)) | 0);
|
|
99
|
-
if (item(i_1, this.seedArray) < 0) {
|
|
100
|
-
this.seedArray[i_1] = ((item(i_1, this.seedArray) + this.MBIG) | 0);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
this.inext = 0;
|
|
105
|
-
this.inextp = 21;
|
|
106
|
-
}
|
|
107
|
-
Next0(): int32 {
|
|
108
|
-
const this$: Seeded = this;
|
|
109
|
-
return Seeded__InternalSample(this$) | 0;
|
|
110
|
-
}
|
|
111
|
-
Next1(maxValue: int32): int32 {
|
|
112
|
-
const this$: Seeded = this;
|
|
113
|
-
if (maxValue < 0) {
|
|
114
|
-
throw new Error("maxValue must be positive");
|
|
115
|
-
}
|
|
116
|
-
return ~~(Seeded__Sample(this$) * maxValue) | 0;
|
|
117
|
-
}
|
|
118
|
-
Next2(minValue: int32, maxValue: int32): int32 {
|
|
119
|
-
const this$: Seeded = this;
|
|
120
|
-
if (minValue > maxValue) {
|
|
121
|
-
throw new Error("minValue must be less than maxValue");
|
|
122
|
-
}
|
|
123
|
-
const range: int64 = toInt64(fromInt32(maxValue - minValue));
|
|
124
|
-
return ((compare(range, toInt64(fromInt32(2147483647))) <= 0) ? (~~(Seeded__Sample(this$) * toFloat64(range)) + minValue) : ~~toInt32(toInt64(op_Addition(toInt64(fromFloat64(Seeded__GetSampleForLargeRange(this$) * toFloat64(range))), toInt64(fromInt32(minValue)))))) | 0;
|
|
125
|
-
}
|
|
126
|
-
NextDouble(): float64 {
|
|
127
|
-
const this$: Seeded = this;
|
|
128
|
-
return Seeded__Sample(this$);
|
|
129
|
-
}
|
|
130
|
-
NextBytes(buffer: uint8[]): void {
|
|
131
|
-
const this$: Seeded = this;
|
|
132
|
-
if (buffer
|
|
133
|
-
throw new Error("buffer");
|
|
134
|
-
}
|
|
135
|
-
for (let i = 0; i <= (buffer.length - 1); i++) {
|
|
136
|
-
setItem(buffer, i, (Seeded__InternalSample(this$) % (~~255 + 1)) & 0xFF);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function Seeded_$reflection(): TypeInfo {
|
|
142
|
-
return class_type("Random.Seeded", undefined, Seeded);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function Seeded_$ctor_Z524259A4(seed: int32): Seeded {
|
|
146
|
-
return new Seeded(seed);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function Seeded__InternalSample(_: Seeded): int32 {
|
|
150
|
-
let retVal = 0;
|
|
151
|
-
let locINext: int32 = _.inext;
|
|
152
|
-
let locINextp: int32 = _.inextp;
|
|
153
|
-
locINext = ((locINext + 1) | 0);
|
|
154
|
-
if (locINext >= 56) {
|
|
155
|
-
locINext = 1;
|
|
156
|
-
}
|
|
157
|
-
locINextp = ((locINextp + 1) | 0);
|
|
158
|
-
if (locINextp >= 56) {
|
|
159
|
-
locINextp = 1;
|
|
160
|
-
}
|
|
161
|
-
retVal = ((item(locINext, _.seedArray) - item(locINextp, _.seedArray)) | 0);
|
|
162
|
-
if (retVal === _.MBIG) {
|
|
163
|
-
retVal = ((retVal - 1) | 0);
|
|
164
|
-
}
|
|
165
|
-
if (retVal < 0) {
|
|
166
|
-
retVal = ((retVal + _.MBIG) | 0);
|
|
167
|
-
}
|
|
168
|
-
_.seedArray[locINext] = (retVal | 0);
|
|
169
|
-
_.inext = (locINext | 0);
|
|
170
|
-
_.inextp = (locINextp | 0);
|
|
171
|
-
return retVal | 0;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function Seeded__Sample(this$: Seeded): float64 {
|
|
175
|
-
return Seeded__InternalSample(this$) * (1 / this$.MBIG);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function Seeded__GetSampleForLargeRange(this$: Seeded): float64 {
|
|
179
|
-
let result: float64 = Seeded__InternalSample(this$);
|
|
180
|
-
if ((Seeded__InternalSample(this$) % 2) === 0) {
|
|
181
|
-
result = -result;
|
|
182
|
-
}
|
|
183
|
-
let d: float64 = result;
|
|
184
|
-
d = (d + (2147483647 - 1));
|
|
185
|
-
d = (d / (2 * ((2147483647 - 1) >>> 0)));
|
|
186
|
-
return d;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function nonSeeded(): NonSeeded {
|
|
190
|
-
return NonSeeded_$ctor();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function seeded(seed: int32): Seeded {
|
|
194
|
-
return Seeded_$ctor_Z524259A4(seed);
|
|
195
|
-
}
|
|
196
|
-
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IRandom {
|
|
36
|
+
Next0(): int32,
|
|
37
|
+
Next1(maxValue: int32): int32,
|
|
38
|
+
Next2(minValue: int32, maxValue: int32): int32,
|
|
39
|
+
NextBytes(buffer: uint8[]): void,
|
|
40
|
+
NextDouble(): float64
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class NonSeeded implements IRandom {
|
|
44
|
+
constructor() {
|
|
45
|
+
}
|
|
46
|
+
Next0(): int32 {
|
|
47
|
+
return Native_randomNext(0, 2147483647) | 0;
|
|
48
|
+
}
|
|
49
|
+
Next1(maxValue: int32): int32 {
|
|
50
|
+
return Native_randomNext(0, maxValue) | 0;
|
|
51
|
+
}
|
|
52
|
+
Next2(minValue: int32, maxValue: int32): int32 {
|
|
53
|
+
return Native_randomNext(minValue, maxValue) | 0;
|
|
54
|
+
}
|
|
55
|
+
NextDouble(): float64 {
|
|
56
|
+
return Native_random();
|
|
57
|
+
}
|
|
58
|
+
NextBytes(buffer: uint8[]): void {
|
|
59
|
+
Native_randomBytes(buffer);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function NonSeeded_$reflection(): TypeInfo {
|
|
64
|
+
return class_type("Random.NonSeeded", undefined, NonSeeded);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function NonSeeded_$ctor(): NonSeeded {
|
|
68
|
+
return new NonSeeded();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class Seeded implements IRandom {
|
|
72
|
+
readonly MBIG: int32;
|
|
73
|
+
inext: int32;
|
|
74
|
+
inextp: int32;
|
|
75
|
+
seedArray: int32[];
|
|
76
|
+
constructor(seed: int32) {
|
|
77
|
+
this.MBIG = 2147483647;
|
|
78
|
+
this.inext = 0;
|
|
79
|
+
this.inextp = 0;
|
|
80
|
+
this.seedArray = fill(new Array(56), 0, 56, 0);
|
|
81
|
+
let ii = 0;
|
|
82
|
+
let mj = 0;
|
|
83
|
+
let mk = 0;
|
|
84
|
+
const subtraction: int32 = ((seed === -2147483648) ? 2147483647 : Math.abs(seed)) | 0;
|
|
85
|
+
mj = ((161803398 - subtraction) | 0);
|
|
86
|
+
this.seedArray[55] = (mj | 0);
|
|
87
|
+
mk = 1;
|
|
88
|
+
for (let i = 1; i <= 54; i++) {
|
|
89
|
+
ii = (((21 * i) % 55) | 0);
|
|
90
|
+
this.seedArray[ii] = (mk | 0);
|
|
91
|
+
mk = ((mj - mk) | 0);
|
|
92
|
+
if (mk < 0) {
|
|
93
|
+
mk = ((mk + this.MBIG) | 0);
|
|
94
|
+
}
|
|
95
|
+
mj = (item(ii, this.seedArray) | 0);
|
|
96
|
+
}
|
|
97
|
+
for (let k = 1; k <= 4; k++) {
|
|
98
|
+
for (let i_1 = 1; i_1 <= 55; i_1++) {
|
|
99
|
+
this.seedArray[i_1] = ((item(i_1, this.seedArray) - item(1 + ((i_1 + 30) % 55), this.seedArray)) | 0);
|
|
100
|
+
if (item(i_1, this.seedArray) < 0) {
|
|
101
|
+
this.seedArray[i_1] = ((item(i_1, this.seedArray) + this.MBIG) | 0);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
this.inext = 0;
|
|
106
|
+
this.inextp = 21;
|
|
107
|
+
}
|
|
108
|
+
Next0(): int32 {
|
|
109
|
+
const this$: Seeded = this;
|
|
110
|
+
return Seeded__InternalSample(this$) | 0;
|
|
111
|
+
}
|
|
112
|
+
Next1(maxValue: int32): int32 {
|
|
113
|
+
const this$: Seeded = this;
|
|
114
|
+
if (maxValue < 0) {
|
|
115
|
+
throw new Error("maxValue must be positive");
|
|
116
|
+
}
|
|
117
|
+
return ~~(Seeded__Sample(this$) * maxValue) | 0;
|
|
118
|
+
}
|
|
119
|
+
Next2(minValue: int32, maxValue: int32): int32 {
|
|
120
|
+
const this$: Seeded = this;
|
|
121
|
+
if (minValue > maxValue) {
|
|
122
|
+
throw new Error("minValue must be less than maxValue");
|
|
123
|
+
}
|
|
124
|
+
const range: int64 = toInt64(fromInt32(maxValue - minValue));
|
|
125
|
+
return ((compare(range, toInt64(fromInt32(2147483647))) <= 0) ? (~~(Seeded__Sample(this$) * toFloat64(range)) + minValue) : ~~toInt32(toInt64(op_Addition(toInt64(fromFloat64(Seeded__GetSampleForLargeRange(this$) * toFloat64(range))), toInt64(fromInt32(minValue)))))) | 0;
|
|
126
|
+
}
|
|
127
|
+
NextDouble(): float64 {
|
|
128
|
+
const this$: Seeded = this;
|
|
129
|
+
return Seeded__Sample(this$);
|
|
130
|
+
}
|
|
131
|
+
NextBytes(buffer: uint8[]): void {
|
|
132
|
+
const this$: Seeded = this;
|
|
133
|
+
if (Operators_IsNull<uint8[]>(buffer)) {
|
|
134
|
+
throw new Error("buffer");
|
|
135
|
+
}
|
|
136
|
+
for (let i = 0; i <= (buffer.length - 1); i++) {
|
|
137
|
+
setItem(buffer, i, (Seeded__InternalSample(this$) % (~~255 + 1)) & 0xFF);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function Seeded_$reflection(): TypeInfo {
|
|
143
|
+
return class_type("Random.Seeded", undefined, Seeded);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function Seeded_$ctor_Z524259A4(seed: int32): Seeded {
|
|
147
|
+
return new Seeded(seed);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function Seeded__InternalSample(_: Seeded): int32 {
|
|
151
|
+
let retVal = 0;
|
|
152
|
+
let locINext: int32 = _.inext;
|
|
153
|
+
let locINextp: int32 = _.inextp;
|
|
154
|
+
locINext = ((locINext + 1) | 0);
|
|
155
|
+
if (locINext >= 56) {
|
|
156
|
+
locINext = 1;
|
|
157
|
+
}
|
|
158
|
+
locINextp = ((locINextp + 1) | 0);
|
|
159
|
+
if (locINextp >= 56) {
|
|
160
|
+
locINextp = 1;
|
|
161
|
+
}
|
|
162
|
+
retVal = ((item(locINext, _.seedArray) - item(locINextp, _.seedArray)) | 0);
|
|
163
|
+
if (retVal === _.MBIG) {
|
|
164
|
+
retVal = ((retVal - 1) | 0);
|
|
165
|
+
}
|
|
166
|
+
if (retVal < 0) {
|
|
167
|
+
retVal = ((retVal + _.MBIG) | 0);
|
|
168
|
+
}
|
|
169
|
+
_.seedArray[locINext] = (retVal | 0);
|
|
170
|
+
_.inext = (locINext | 0);
|
|
171
|
+
_.inextp = (locINextp | 0);
|
|
172
|
+
return retVal | 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function Seeded__Sample(this$: Seeded): float64 {
|
|
176
|
+
return Seeded__InternalSample(this$) * (1 / this$.MBIG);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function Seeded__GetSampleForLargeRange(this$: Seeded): float64 {
|
|
180
|
+
let result: float64 = Seeded__InternalSample(this$);
|
|
181
|
+
if ((Seeded__InternalSample(this$) % 2) === 0) {
|
|
182
|
+
result = -result;
|
|
183
|
+
}
|
|
184
|
+
let d: float64 = result;
|
|
185
|
+
d = (d + (2147483647 - 1));
|
|
186
|
+
d = (d / (2 * ((2147483647 - 1) >>> 0)));
|
|
187
|
+
return d;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function nonSeeded(): NonSeeded {
|
|
191
|
+
return NonSeeded_$ctor();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function seeded(seed: int32): Seeded {
|
|
195
|
+
return Seeded_$ctor_Z524259A4(seed);
|
|
196
|
+
}
|
|
197
|
+
|
package/Range.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { compare } from "./Util.js";
|
|
2
|
-
import { float64, int32 } from "./Int32.js";
|
|
3
|
-
import { Option } from "./Option.js";
|
|
4
|
-
import { unfold, delay } from "./Seq.js";
|
|
5
|
-
import { uint64, toUInt64, int64, toInt64, op_Addition, fromZero } from "./BigInt.js";
|
|
6
|
-
import { decimal, op_Addition as op_Addition_1, fromParts } from "./Decimal.js";
|
|
7
|
-
|
|
8
|
-
export function makeRangeStepFunction<T>(step: T, stop: T, zero: T, add: ((arg0: T, arg1: T) => T)): ((arg0: T) => Option<[T, T]>) {
|
|
9
|
-
const stepComparedWithZero: int32 = compare(step, zero) | 0;
|
|
10
|
-
if (stepComparedWithZero === 0) {
|
|
11
|
-
throw new Error("The step of a range cannot be zero");
|
|
12
|
-
}
|
|
13
|
-
const stepGreaterThanZero: boolean = stepComparedWithZero > 0;
|
|
14
|
-
return (x: T): Option<[T, T]> => {
|
|
15
|
-
const comparedWithLast: int32 = compare(x, stop) | 0;
|
|
16
|
-
return ((stepGreaterThanZero && (comparedWithLast <= 0)) ? true : (!stepGreaterThanZero && (comparedWithLast >= 0))) ? ([x, add(x, step)] as [T, T]) : undefined;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function integralRangeStep<T>(start: T, step: T, stop: T, zero: T, add: ((arg0: T, arg1: T) => T)): Iterable<T> {
|
|
21
|
-
const stepFn: ((arg0: T) => Option<[T, T]>) = makeRangeStepFunction<T>(step, stop, zero, add);
|
|
22
|
-
return delay<T>((): Iterable<T> => unfold<T, T>(stepFn, start));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function rangeBigInt(start: bigint, step: bigint, stop: bigint): Iterable<bigint> {
|
|
26
|
-
return integralRangeStep<bigint>(start, step, stop, fromZero(), op_Addition);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function rangeDecimal(start: decimal, step: decimal, stop: decimal): Iterable<decimal> {
|
|
30
|
-
return integralRangeStep<decimal>(start, step, stop, fromParts(0, 0, 0, false, 0), op_Addition_1);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function rangeDouble(start: float64, step: float64, stop: float64): Iterable<float64> {
|
|
34
|
-
return integralRangeStep<float64>(start, step, stop, 0, (x: float64, y: float64): float64 => (x + y));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function rangeInt64(start: int64, step: int64, stop: int64): Iterable<int64> {
|
|
38
|
-
return integralRangeStep<int64>(start, step, stop, 0n, (x: int64, y: int64): int64 => toInt64(op_Addition(x, y)));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function rangeUInt64(start: uint64, step: uint64, stop: uint64): Iterable<uint64> {
|
|
42
|
-
return integralRangeStep<uint64>(start, step, stop, 0n, (x: uint64, y: uint64): uint64 => toUInt64(op_Addition(x, y)));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function rangeChar(start: string, stop: string): Iterable<string> {
|
|
46
|
-
const intStop: int32 = ~~stop.charCodeAt(0) | 0;
|
|
47
|
-
return delay<string>((): Iterable<string> => unfold<int32, string>((c: int32): Option<[string, int32]> => {
|
|
48
|
-
if (c <= intStop) {
|
|
49
|
-
return [String.fromCharCode(c), c + 1] as [string, int32];
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
}, ~~start.charCodeAt(0)));
|
|
55
|
-
}
|
|
56
|
-
|
|
1
|
+
import { compare } from "./Util.js";
|
|
2
|
+
import { float64, int32 } from "./Int32.js";
|
|
3
|
+
import { Option } from "./Option.js";
|
|
4
|
+
import { unfold, delay } from "./Seq.js";
|
|
5
|
+
import { uint64, toUInt64, int64, toInt64, op_Addition, fromZero } from "./BigInt.js";
|
|
6
|
+
import { decimal, op_Addition as op_Addition_1, fromParts } from "./Decimal.js";
|
|
7
|
+
|
|
8
|
+
export function makeRangeStepFunction<T>(step: T, stop: T, zero: T, add: ((arg0: T, arg1: T) => T)): ((arg0: T) => Option<[T, T]>) {
|
|
9
|
+
const stepComparedWithZero: int32 = compare(step, zero) | 0;
|
|
10
|
+
if (stepComparedWithZero === 0) {
|
|
11
|
+
throw new Error("The step of a range cannot be zero");
|
|
12
|
+
}
|
|
13
|
+
const stepGreaterThanZero: boolean = stepComparedWithZero > 0;
|
|
14
|
+
return (x: T): Option<[T, T]> => {
|
|
15
|
+
const comparedWithLast: int32 = compare(x, stop) | 0;
|
|
16
|
+
return ((stepGreaterThanZero && (comparedWithLast <= 0)) ? true : (!stepGreaterThanZero && (comparedWithLast >= 0))) ? ([x, add(x, step)] as [T, T]) : undefined;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function integralRangeStep<T>(start: T, step: T, stop: T, zero: T, add: ((arg0: T, arg1: T) => T)): Iterable<T> {
|
|
21
|
+
const stepFn: ((arg0: T) => Option<[T, T]>) = makeRangeStepFunction<T>(step, stop, zero, add);
|
|
22
|
+
return delay<T>((): Iterable<T> => unfold<T, T>(stepFn, start));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function rangeBigInt(start: bigint, step: bigint, stop: bigint): Iterable<bigint> {
|
|
26
|
+
return integralRangeStep<bigint>(start, step, stop, fromZero(), op_Addition);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function rangeDecimal(start: decimal, step: decimal, stop: decimal): Iterable<decimal> {
|
|
30
|
+
return integralRangeStep<decimal>(start, step, stop, fromParts(0, 0, 0, false, 0), op_Addition_1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function rangeDouble(start: float64, step: float64, stop: float64): Iterable<float64> {
|
|
34
|
+
return integralRangeStep<float64>(start, step, stop, 0, (x: float64, y: float64): float64 => (x + y));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function rangeInt64(start: int64, step: int64, stop: int64): Iterable<int64> {
|
|
38
|
+
return integralRangeStep<int64>(start, step, stop, 0n, (x: int64, y: int64): int64 => toInt64(op_Addition(x, y)));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function rangeUInt64(start: uint64, step: uint64, stop: uint64): Iterable<uint64> {
|
|
42
|
+
return integralRangeStep<uint64>(start, step, stop, 0n, (x: uint64, y: uint64): uint64 => toUInt64(op_Addition(x, y)));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function rangeChar(start: string, stop: string): Iterable<string> {
|
|
46
|
+
const intStop: int32 = ~~stop.charCodeAt(0) | 0;
|
|
47
|
+
return delay<string>((): Iterable<string> => unfold<int32, string>((c: int32): Option<[string, int32]> => {
|
|
48
|
+
if (c <= intStop) {
|
|
49
|
+
return [String.fromCharCode(c), c + 1] as [string, int32];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}, ~~start.charCodeAt(0)));
|
|
55
|
+
}
|
|
56
|
+
|