@fable-org/fable-library-ts 2.0.0-rc.5 → 2.0.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.ts +117 -2
- package/Async.ts +12 -28
- package/CHANGELOG.md +13 -0
- package/Guid.ts +31 -8
- package/List.ts +53 -2
- package/Seq.ts +62 -3
- package/Set.ts +95 -63
- package/String.ts +13 -0
- package/package.json +1 -1
- package/quotation.ts +644 -0
package/Array.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import { IComparer, IDisposable, disposeSafe, IEnumerator, getEnumerator, copyToArray, IEqualityComparer, defaultOf, MutableArray, Exception } from "./Util.ts";
|
|
3
|
-
import { int32 } from "./Int32.ts";
|
|
3
|
+
import { float64, int32 } from "./Int32.ts";
|
|
4
4
|
import { Helpers_allocateArrayFromCons } from "./Native.ts";
|
|
5
5
|
import { setItem as setItem_1, item as item_2 } from "./Array.ts";
|
|
6
6
|
import { value as value_2, map as map_1, defaultArg, Option, some } from "./Option.ts";
|
|
7
7
|
import { min as min_1, max as max_1 } from "./Double.ts";
|
|
8
|
-
import { SR_indexOutOfBounds } from "./Global.ts";
|
|
8
|
+
import { SR_notEnoughElements, SR_inputMustBeNonNegative, SR_inputSequenceEmpty, SR_Arg_ArgumentOutOfRangeException, SR_indexOutOfBounds } from "./Global.ts";
|
|
9
9
|
import { Operators_IsNull } from "./FSharp.Core.ts";
|
|
10
|
+
import { nonSeeded } from "./Random.ts";
|
|
10
11
|
import { FSharpRef } from "./Types.ts";
|
|
11
12
|
|
|
12
13
|
function indexNotFound<$a>(): $a {
|
|
@@ -1307,6 +1308,120 @@ export function insertManyAt<T>(index: int32, ys: Iterable<T>, xs: MutableArray<
|
|
|
1307
1308
|
return target;
|
|
1308
1309
|
}
|
|
1309
1310
|
|
|
1311
|
+
export function randomShuffleInPlaceBy<T>(randomizer: (() => float64), xs: MutableArray<T>): void {
|
|
1312
|
+
const len: int32 = xs.length | 0;
|
|
1313
|
+
for (let i: int32 = len - 1; i >= 1; i--) {
|
|
1314
|
+
const r: float64 = randomizer();
|
|
1315
|
+
if ((r < 0) ? true : (r >= 1)) {
|
|
1316
|
+
throw new Exception((SR_Arg_ArgumentOutOfRangeException + "\\nParameter name: ") + "randomizer");
|
|
1317
|
+
}
|
|
1318
|
+
const j: int32 = ~~(r * (i + 1)) | 0;
|
|
1319
|
+
const tmp: T = item_2(i, xs);
|
|
1320
|
+
setItem_1(xs, i, item_2(j, xs));
|
|
1321
|
+
setItem_1(xs, j, tmp);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
export function randomShuffleInPlaceWith<T>(random: any, xs: MutableArray<T>): void {
|
|
1326
|
+
randomShuffleInPlaceBy<T>((): float64 => random.NextDouble(), xs);
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
export function randomShuffleInPlace<T>(xs: MutableArray<T>): void {
|
|
1330
|
+
randomShuffleInPlaceWith<T>(nonSeeded(), xs);
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
export function randomShuffleBy<T>(randomizer: (() => float64), xs: MutableArray<T>): MutableArray<T> {
|
|
1334
|
+
const arr: MutableArray<T> = copy<T>(xs);
|
|
1335
|
+
randomShuffleInPlaceBy<T>(randomizer, arr);
|
|
1336
|
+
return arr;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
export function randomShuffleWith<T>(random: any, xs: MutableArray<T>): MutableArray<T> {
|
|
1340
|
+
return randomShuffleBy<T>((): float64 => random.NextDouble(), xs);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
export function randomShuffle<T>(xs: MutableArray<T>): MutableArray<T> {
|
|
1344
|
+
return randomShuffleWith<T>(nonSeeded(), xs);
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
export function randomChoiceBy<T>(randomizer: (() => float64), xs: MutableArray<T>): T {
|
|
1348
|
+
if (isEmpty<T>(xs)) {
|
|
1349
|
+
throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source");
|
|
1350
|
+
}
|
|
1351
|
+
const len: int32 = xs.length | 0;
|
|
1352
|
+
const r: float64 = randomizer();
|
|
1353
|
+
if ((r < 0) ? true : (r >= 1)) {
|
|
1354
|
+
throw new Exception((SR_Arg_ArgumentOutOfRangeException + "\\nParameter name: ") + "randomizer");
|
|
1355
|
+
}
|
|
1356
|
+
return item_2(~~(r * len), xs);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
export function randomChoiceWith<T>(random: any, xs: MutableArray<T>): T {
|
|
1360
|
+
return randomChoiceBy<T>((): float64 => random.NextDouble(), xs);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
export function randomChoice<T>(xs: MutableArray<T>): T {
|
|
1364
|
+
return randomChoiceWith<T>(nonSeeded(), xs);
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
export function randomChoicesBy<T>(randomizer: (() => float64), count: int32, xs: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
1368
|
+
if (count < 0) {
|
|
1369
|
+
throw new Exception((SR_inputMustBeNonNegative + "\\nParameter name: ") + "count");
|
|
1370
|
+
}
|
|
1371
|
+
if ((count > 0) && isEmpty<T>(xs)) {
|
|
1372
|
+
throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source");
|
|
1373
|
+
}
|
|
1374
|
+
const len: int32 = xs.length | 0;
|
|
1375
|
+
return initialize<T>(count, (_arg: int32): T => {
|
|
1376
|
+
const r: float64 = randomizer();
|
|
1377
|
+
if ((r < 0) ? true : (r >= 1)) {
|
|
1378
|
+
throw new Exception((SR_Arg_ArgumentOutOfRangeException + "\\nParameter name: ") + "randomizer");
|
|
1379
|
+
}
|
|
1380
|
+
return item_2(~~(r * len), xs);
|
|
1381
|
+
}, cons);
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
export function randomChoicesWith<T>(random: any, count: int32, xs: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
1385
|
+
return randomChoicesBy<T>((): float64 => random.NextDouble(), count, xs, cons);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
export function randomChoices<T>(count: int32, xs: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
1389
|
+
return randomChoicesWith<T>(nonSeeded(), count, xs, cons);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
export function randomSampleBy<T>(randomizer: (() => float64), count: int32, xs: MutableArray<T>): MutableArray<T> {
|
|
1393
|
+
if (count < 0) {
|
|
1394
|
+
throw new Exception((SR_inputMustBeNonNegative + "\\nParameter name: ") + "count");
|
|
1395
|
+
}
|
|
1396
|
+
const arr: MutableArray<T> = copy<T>(xs);
|
|
1397
|
+
const len: int32 = arr.length | 0;
|
|
1398
|
+
if ((len === 0) && (count > 0)) {
|
|
1399
|
+
throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source");
|
|
1400
|
+
}
|
|
1401
|
+
if (count > len) {
|
|
1402
|
+
throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "count");
|
|
1403
|
+
}
|
|
1404
|
+
for (let i = 0; i <= (count - 1); i++) {
|
|
1405
|
+
const r: float64 = randomizer();
|
|
1406
|
+
if ((r < 0) ? true : (r >= 1)) {
|
|
1407
|
+
throw new Exception((SR_Arg_ArgumentOutOfRangeException + "\\nParameter name: ") + "randomizer");
|
|
1408
|
+
}
|
|
1409
|
+
const j: int32 = (i + ~~(r * (len - i))) | 0;
|
|
1410
|
+
const tmp: T = item_2(i, arr);
|
|
1411
|
+
setItem_1(arr, i, item_2(j, arr));
|
|
1412
|
+
setItem_1(arr, j, tmp);
|
|
1413
|
+
}
|
|
1414
|
+
return getSubArray<T>(arr, 0, count);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
export function randomSampleWith<T>(random: any, count: int32, xs: MutableArray<T>): MutableArray<T> {
|
|
1418
|
+
return randomSampleBy<T>((): float64 => random.NextDouble(), count, xs);
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
export function randomSample<T>(count: int32, xs: MutableArray<T>): MutableArray<T> {
|
|
1422
|
+
return randomSampleWith<T>(nonSeeded(), count, xs);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1310
1425
|
export function removeAt<T>(index: int32, xs: MutableArray<T>): MutableArray<T> {
|
|
1311
1426
|
if ((index < 0) ? true : (index >= xs.length)) {
|
|
1312
1427
|
throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
|
package/Async.ts
CHANGED
|
@@ -58,37 +58,25 @@ export function throwIfCancellationRequested(token: CancellationToken) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function throwAfter(millisecondsDueTime: number): Async<void> {
|
|
62
|
-
return protectedCont((ctx: IAsyncContext<void>) => {
|
|
63
|
-
let tokenId: number;
|
|
64
|
-
const timeoutId = setTimeout(() => {
|
|
65
|
-
ctx.cancelToken.removeListener(tokenId);
|
|
66
|
-
ctx.onError(TimeoutException_$ctor());
|
|
67
|
-
}, millisecondsDueTime);
|
|
68
|
-
tokenId = ctx.cancelToken.addListener(() => {
|
|
69
|
-
clearTimeout(timeoutId);
|
|
70
|
-
ctx.onCancel(new OperationCanceledException());
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
61
|
export function startChild<T>(computation: Async<T>, ms?: number): Async<Async<T>> {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
parallel2(
|
|
79
|
-
computation,
|
|
80
|
-
throwAfter(ms)),
|
|
81
|
-
xs => protectedReturn(xs[0]));
|
|
62
|
+
const promise = startAsPromise(computation);
|
|
63
|
+
let promiseToRun = promise;
|
|
82
64
|
|
|
83
|
-
|
|
65
|
+
if (ms) {
|
|
66
|
+
// Race the computation against a timeout: whichever settles first wins.
|
|
67
|
+
promiseToRun = new Promise<T>((resolve, reject) => {
|
|
68
|
+
const timeoutId = setTimeout(() => reject(TimeoutException_$ctor()), ms);
|
|
69
|
+
promise.then(
|
|
70
|
+
value => { clearTimeout(timeoutId); resolve(value); },
|
|
71
|
+
error => { clearTimeout(timeoutId); reject(error); }
|
|
72
|
+
);
|
|
73
|
+
});
|
|
84
74
|
}
|
|
85
75
|
|
|
86
|
-
const promise = startAsPromise(computation);
|
|
87
|
-
|
|
88
76
|
// JS Promises are hot, computation has already started
|
|
89
77
|
// but we delay returning the result
|
|
90
78
|
return protectedCont((ctx) =>
|
|
91
|
-
protectedReturn(awaitPromise(
|
|
79
|
+
protectedReturn(awaitPromise(promiseToRun))(ctx));
|
|
92
80
|
}
|
|
93
81
|
|
|
94
82
|
export function awaitPromise<T>(p: Promise<T>) {
|
|
@@ -129,10 +117,6 @@ export function parallel<T>(computations: Iterable<Async<T>>) {
|
|
|
129
117
|
return delay(() => awaitPromise(Promise.all(Array.from(computations, (w) => startAsPromise(w)))));
|
|
130
118
|
}
|
|
131
119
|
|
|
132
|
-
function parallel2<T, U>(a: Async<T>, b: Async<U>): Async<[T, U]> {
|
|
133
|
-
return delay(() => awaitPromise(Promise.all([startAsPromise(a), startAsPromise(b)])));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
120
|
export function sequential<T>(computations: Iterable<Async<T>>) {
|
|
137
121
|
|
|
138
122
|
function _sequential<T>(computations: Iterable<Async<T>>): Promise<T[]> {
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
+
## 2.0.0 - 2026-04-21
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
* [JS/TS] Fix `ResizeArray` (`System.Collections.Generic.List`) equality to use reference equality instead of structural equality (fixes #3718)
|
|
15
|
+
* [JS/TS] Fix `String.Contains` ignoring `StringComparison` argument (second argument was silently discarded)
|
|
16
|
+
|
|
17
|
+
## 2.0.0-rc.6 - 2026-04-07
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
* [JS/TS] Fix `Async.StartChild` with timeout always timing out even when the computation finishes before the deadline (fixes #4481) (by @MangelMaxime)
|
|
22
|
+
|
|
10
23
|
## 2.0.0-rc.5 - 2026-03-31
|
|
11
24
|
|
|
12
25
|
### Fixed
|
package/Guid.ts
CHANGED
|
@@ -63,15 +63,38 @@ export function tryParse(str: string, defValue: FSharpRef<string>): boolean {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
// From https://gist.github.com/LeverOne/1308368
|
|
67
66
|
export function newGuid() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
67
|
+
const bytes = new Uint8Array(16);
|
|
68
|
+
crypto.getRandomValues(bytes);
|
|
69
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4
|
|
70
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 1
|
|
71
|
+
const hex = Array.from(bytes, b => b.toString(16).padStart(2, "0")).join("");
|
|
72
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// RFC 9562 UUID v7
|
|
76
|
+
export function createVersion7(timestamp?: Date): string {
|
|
77
|
+
const ms = timestamp != null ? timestamp.getTime() : Date.now();
|
|
78
|
+
|
|
79
|
+
// 48-bit timestamp as hex
|
|
80
|
+
const msHex = Math.floor(ms).toString(16).padStart(12, "0");
|
|
81
|
+
|
|
82
|
+
// random bits
|
|
83
|
+
const bytes = new Uint8Array(10);
|
|
84
|
+
crypto.getRandomValues(bytes);
|
|
85
|
+
const view = new DataView(bytes.buffer);
|
|
86
|
+
const randA = view.getUint16(0) & 0x0fff; // 12 bits
|
|
87
|
+
const randB1 = view.getUint16(2) & 0x3fff; // 14 bits
|
|
88
|
+
const randB2 = view.getUint32(4); // 32 bits
|
|
89
|
+
const randB3 = view.getUint16(8); // 16 bits
|
|
90
|
+
|
|
91
|
+
const timeLow = msHex.slice(0, 8);
|
|
92
|
+
const timeMid = msHex.slice(8, 12);
|
|
93
|
+
const ver = (0x7000 | randA).toString(16).padStart(4, "0");
|
|
94
|
+
const variantAndRandB = (0x8000 | randB1).toString(16).padStart(4, "0");
|
|
95
|
+
const node = randB2.toString(16).padStart(8, "0") + randB3.toString(16).padStart(4, "0");
|
|
96
|
+
|
|
97
|
+
return `${timeLow}-${timeMid}-${ver}-${variantAndRandB}-${node}`;
|
|
75
98
|
}
|
|
76
99
|
|
|
77
100
|
// Maps for number <-> hex string conversion
|
package/List.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { join } from "./String.ts";
|
|
3
3
|
import { defaultArg, some, value as value_1, Option } from "./Option.ts";
|
|
4
4
|
import { IComparer, IEqualityComparer, disposeSafe, isArrayLike, MutableArray, Exception, IDisposable, defaultOf, toIterator, getEnumerator, IEnumerator, compare, structuralHash, equals } from "./Util.ts";
|
|
5
|
-
import { int32 } from "./Int32.ts";
|
|
5
|
+
import { float64, int32 } from "./Int32.ts";
|
|
6
6
|
import { Record } from "./Types.ts";
|
|
7
7
|
import { class_type, record_type, option_type, TypeInfo } from "./Reflection.ts";
|
|
8
8
|
import { SR_inputSequenceTooLong, SR_inputSequenceEmpty, SR_inputMustBeNonNegative, SR_notEnoughElements, SR_differentLengths, SR_keyNotFoundAlt, SR_indexOutOfBounds, SR_inputWasEmpty } from "./Global.ts";
|
|
9
9
|
import { KeyNotFoundException_$ctor_Z721C83C5 } from "./System.Collections.Generic.ts";
|
|
10
|
-
import { transpose as transpose_1, splitInto as splitInto_1, windowed as windowed_1, pairwise as pairwise_1, chunkBySize as chunkBySize_1, map as map_1, permute as permute_1, tryFindIndexBack as tryFindIndexBack_1, tryFindBack as tryFindBack_1, scanBack as scanBack_1, item as item_1, foldBack2 as foldBack2_1, foldBack as foldBack_1, setItem, fill } from "./Array.ts";
|
|
10
|
+
import { randomSampleBy as randomSampleBy_1, randomChoicesBy as randomChoicesBy_1, randomChoiceBy as randomChoiceBy_1, randomShuffleInPlaceBy, transpose as transpose_1, splitInto as splitInto_1, windowed as windowed_1, pairwise as pairwise_1, chunkBySize as chunkBySize_1, map as map_1, permute as permute_1, tryFindIndexBack as tryFindIndexBack_1, tryFindBack as tryFindBack_1, scanBack as scanBack_1, item as item_1, foldBack2 as foldBack2_1, foldBack as foldBack_1, setItem, fill } from "./Array.ts";
|
|
11
|
+
import { nonSeeded } from "./Random.ts";
|
|
11
12
|
|
|
12
13
|
export class FSharpList<T> extends Record implements Iterable<T> {
|
|
13
14
|
readonly head: T;
|
|
@@ -1427,3 +1428,53 @@ export function updateAt<T>(index: int32, y: T, xs: FSharpList<T>): FSharpList<T
|
|
|
1427
1428
|
return ys;
|
|
1428
1429
|
}
|
|
1429
1430
|
|
|
1431
|
+
export function randomShuffleBy<T>(randomizer: (() => float64), xs: FSharpList<T>): FSharpList<T> {
|
|
1432
|
+
const arr: MutableArray<T> = toArray<T>(xs);
|
|
1433
|
+
randomShuffleInPlaceBy<T>(randomizer, arr);
|
|
1434
|
+
return ofArray<T>(arr);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
export function randomShuffleWith<T>(random: any, xs: FSharpList<T>): FSharpList<T> {
|
|
1438
|
+
return randomShuffleBy<T>((): float64 => random.NextDouble(), xs);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
export function randomShuffle<T>(xs: FSharpList<T>): FSharpList<T> {
|
|
1442
|
+
return randomShuffleWith<T>(nonSeeded(), xs);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
export function randomChoiceBy<T>(randomizer: (() => float64), xs: FSharpList<T>): T {
|
|
1446
|
+
return randomChoiceBy_1<T>(randomizer, toArray<T>(xs));
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
export function randomChoiceWith<T>(random: any, xs: FSharpList<T>): T {
|
|
1450
|
+
return randomChoiceBy<T>((): float64 => random.NextDouble(), xs);
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
export function randomChoice<T>(xs: FSharpList<T>): T {
|
|
1454
|
+
return randomChoiceWith<T>(nonSeeded(), xs);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
export function randomChoicesBy<T>(randomizer: (() => float64), count: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
1458
|
+
return ofArray<T>(randomChoicesBy_1<T>(randomizer, count, toArray<T>(xs)));
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
export function randomChoicesWith<T>(random: any, count: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
1462
|
+
return randomChoicesBy<T>((): float64 => random.NextDouble(), count, xs);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
export function randomChoices<T>(count: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
1466
|
+
return randomChoicesWith<T>(nonSeeded(), count, xs);
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
export function randomSampleBy<T>(randomizer: (() => float64), count: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
1470
|
+
return ofArray<T>(randomSampleBy_1<T>(randomizer, count, toArray<T>(xs)));
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
export function randomSampleWith<T>(random: any, count: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
1474
|
+
return randomSampleBy<T>((): float64 => random.NextDouble(), count, xs);
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
export function randomSample<T>(count: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
1478
|
+
return randomSampleWith<T>(nonSeeded(), count, xs);
|
|
1479
|
+
}
|
|
1480
|
+
|
package/Seq.ts
CHANGED
|
@@ -6,10 +6,12 @@ import { class_type, TypeInfo } from "./Reflection.ts";
|
|
|
6
6
|
import { some, value as value_1, Option } from "./Option.ts";
|
|
7
7
|
import { KeyNotFoundException_$ctor_Z721C83C5 } from "./System.Collections.Generic.ts";
|
|
8
8
|
import { Operators_Lock, Operators_NullArgCheck } from "./FSharp.Core.ts";
|
|
9
|
-
import { chunkBySize as chunkBySize_1, permute as permute_1, transpose as transpose_1, map as map_1, windowed as windowed_1, splitInto as splitInto_1, pairwise as pairwise_1, scanBack as scanBack_1, reverse as reverse_1, mapFoldBack as mapFoldBack_1, mapFold as mapFold_1,
|
|
9
|
+
import { randomSampleBy as randomSampleBy_1, randomChoicesBy as randomChoicesBy_1, randomChoice as randomChoice_1, randomChoiceWith as randomChoiceWith_1, randomChoiceBy as randomChoiceBy_1, randomShuffleInPlaceBy, chunkBySize as chunkBySize_1, permute as permute_1, transpose as transpose_1, map as map_1, windowed as windowed_1, splitInto as splitInto_1, pairwise as pairwise_1, scanBack as scanBack_1, reverse as reverse_1, mapFoldBack as mapFoldBack_1, mapFold as mapFold_1, tryItem as tryItem_1, tryHead as tryHead_1, item as item_1, foldBack as foldBack_1, tryFindIndexBack as tryFindIndexBack_1, tryFindBack as tryFindBack_1, singleton as singleton_1 } from "./Array.ts";
|
|
10
10
|
import { length as length_1, tryItem as tryItem_2, isEmpty as isEmpty_1, tryHead as tryHead_2, ofSeq as ofSeq_1, ofArray as ofArray_1, toArray as toArray_1, FSharpList } from "./List.ts";
|
|
11
|
-
import { int32 } from "./Int32.ts";
|
|
11
|
+
import { float64, int32 } from "./Int32.ts";
|
|
12
|
+
import { min as min_1 } from "./Double.ts";
|
|
12
13
|
import { SR_indexOutOfBounds } from "./Global.ts";
|
|
14
|
+
import { nonSeeded } from "./Random.ts";
|
|
13
15
|
|
|
14
16
|
export const SR_enumerationAlreadyFinished = "Enumeration already finished.";
|
|
15
17
|
|
|
@@ -723,7 +725,14 @@ export function fold2<T1, T2, State>(folder: ((arg0: State, arg1: T1, arg2: T2)
|
|
|
723
725
|
}
|
|
724
726
|
|
|
725
727
|
export function foldBack2<T1, T2, State>(folder: ((arg0: T1, arg1: T2, arg2: State) => State), xs: Iterable<T1>, ys: Iterable<T2>, state: State): State {
|
|
726
|
-
|
|
728
|
+
const xs_1: MutableArray<T1> = toArray<T1>(xs);
|
|
729
|
+
const ys_1: MutableArray<T2> = toArray<T2>(ys);
|
|
730
|
+
const len: int32 = min_1(xs_1.length, ys_1.length) | 0;
|
|
731
|
+
let acc: State = state;
|
|
732
|
+
for (let i: int32 = len - 1; i >= 0; i--) {
|
|
733
|
+
acc = folder(item_1(i, xs_1), item_1(i, ys_1), acc);
|
|
734
|
+
}
|
|
735
|
+
return acc;
|
|
727
736
|
}
|
|
728
737
|
|
|
729
738
|
export function forAll<$a>(predicate: ((arg0: $a) => boolean), xs: Iterable<$a>): boolean {
|
|
@@ -1515,3 +1524,53 @@ export function updateAt<T>(index: int32, y: T, xs: Iterable<T>): Iterable<T> {
|
|
|
1515
1524
|
});
|
|
1516
1525
|
}
|
|
1517
1526
|
|
|
1527
|
+
export function randomShuffleBy<T>(randomizer: (() => float64), xs: Iterable<T>): Iterable<T> {
|
|
1528
|
+
const arr: MutableArray<T> = toArray<T>(xs);
|
|
1529
|
+
randomShuffleInPlaceBy<T>(randomizer, arr);
|
|
1530
|
+
return ofArray<T>(arr);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
export function randomShuffleWith<T>(random: any, xs: Iterable<T>): Iterable<T> {
|
|
1534
|
+
return randomShuffleBy<T>((): float64 => random.NextDouble(), xs);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
export function randomShuffle<T>(xs: Iterable<T>): Iterable<T> {
|
|
1538
|
+
return randomShuffleWith<T>(nonSeeded(), xs);
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
export function randomChoiceBy<T>(randomizer: (() => float64), xs: Iterable<T>): T {
|
|
1542
|
+
return randomChoiceBy_1<T>(randomizer, toArray<T>(xs));
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
export function randomChoiceWith<T>(random: any, xs: Iterable<T>): T {
|
|
1546
|
+
return randomChoiceWith_1<T>(random, toArray<T>(xs));
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
export function randomChoice<T>(xs: Iterable<T>): T {
|
|
1550
|
+
return randomChoice_1<T>(toArray<T>(xs));
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
export function randomChoicesBy<T>(randomizer: (() => float64), count: int32, xs: Iterable<T>): Iterable<T> {
|
|
1554
|
+
return ofArray<T>(randomChoicesBy_1<T>(randomizer, count, toArray<T>(xs)));
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
export function randomChoicesWith<T>(random: any, count: int32, xs: Iterable<T>): Iterable<T> {
|
|
1558
|
+
return randomChoicesBy<T>((): float64 => random.NextDouble(), count, xs);
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
export function randomChoices<T>(count: int32, xs: Iterable<T>): Iterable<T> {
|
|
1562
|
+
return randomChoicesWith<T>(nonSeeded(), count, xs);
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
export function randomSampleBy<T>(randomizer: (() => float64), count: int32, xs: Iterable<T>): Iterable<T> {
|
|
1566
|
+
return ofArray<T>(randomSampleBy_1<T>(randomizer, count, toArray<T>(xs)));
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
export function randomSampleWith<T>(random: any, count: int32, xs: Iterable<T>): Iterable<T> {
|
|
1570
|
+
return randomSampleBy<T>((): float64 => random.NextDouble(), count, xs);
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
export function randomSample<T>(count: int32, xs: Iterable<T>): Iterable<T> {
|
|
1574
|
+
return randomSampleWith<T>(nonSeeded(), count, xs);
|
|
1575
|
+
}
|
|
1576
|
+
|