iterflow 0.9.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -194
- package/dist/fn/index.cjs +26 -3
- package/dist/fn/index.cjs.map +1 -1
- package/dist/fn/index.d.cts +1 -3
- package/dist/fn/index.d.ts +1 -3
- package/dist/fn/index.js +26 -3
- package/dist/fn/index.js.map +1 -1
- package/dist/index.cjs +324 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1058 -17
- package/dist/index.d.ts +1058 -17
- package/dist/index.js +324 -10
- package/dist/index.js.map +1 -1
- package/package.json +13 -5
package/dist/index.js
CHANGED
|
@@ -13,6 +13,26 @@ var iterflowError = class extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Returns a detailed error message with context
|
|
16
|
+
*
|
|
17
|
+
* Formats the error as a multi-line string including operation name, context data,
|
|
18
|
+
* and stack trace for comprehensive debugging information.
|
|
19
|
+
*
|
|
20
|
+
* @returns A formatted string containing all error details
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const error = new iterflowError(
|
|
24
|
+
* "Processing failed",
|
|
25
|
+
* "transform",
|
|
26
|
+
* { index: 42, value: null }
|
|
27
|
+
* );
|
|
28
|
+
* console.log(error.toDetailedString());
|
|
29
|
+
* // iterflowError: Processing failed
|
|
30
|
+
* // Operation: transform
|
|
31
|
+
* // Context:
|
|
32
|
+
* // index: 42
|
|
33
|
+
* // value: null
|
|
34
|
+
* // Stack: ...
|
|
35
|
+
* ```
|
|
16
36
|
*/
|
|
17
37
|
toDetailedString() {
|
|
18
38
|
let msg = `${this.name}: ${this.message}`;
|
|
@@ -47,6 +67,28 @@ var OperationError = class extends iterflowError {
|
|
|
47
67
|
this.name = "OperationError";
|
|
48
68
|
this.cause = cause;
|
|
49
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns a detailed error message including the original cause
|
|
72
|
+
*
|
|
73
|
+
* Extends the base toDetailedString() to include information about the
|
|
74
|
+
* underlying error that caused this operation to fail.
|
|
75
|
+
*
|
|
76
|
+
* @returns A formatted string with operation details and cause information
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const originalError = new Error("Network timeout");
|
|
80
|
+
* const opError = new OperationError(
|
|
81
|
+
* "Failed to fetch data",
|
|
82
|
+
* "fetchAsync",
|
|
83
|
+
* originalError
|
|
84
|
+
* );
|
|
85
|
+
* console.log(opError.toDetailedString());
|
|
86
|
+
* // OperationError: Failed to fetch data
|
|
87
|
+
* // Operation: fetchAsync
|
|
88
|
+
* // Caused by: Network timeout
|
|
89
|
+
* // [stack traces...]
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
50
92
|
toDetailedString() {
|
|
51
93
|
let msg = super.toDetailedString();
|
|
52
94
|
if (this.cause) {
|
|
@@ -806,13 +848,28 @@ var iterflow = class _iterflow {
|
|
|
806
848
|
* This method is only available when T is number.
|
|
807
849
|
* This is a terminal operation that consumes the iterator.
|
|
808
850
|
*
|
|
851
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire iterator into memory
|
|
852
|
+
* for sorting. For large datasets, consider using streaming alternatives or limiting data size.
|
|
853
|
+
*
|
|
809
854
|
* @param this - iterflow instance constrained to numbers
|
|
810
855
|
* @returns The median value, or undefined if the iterator is empty
|
|
811
856
|
* @example
|
|
812
857
|
* ```typescript
|
|
858
|
+
* // SAFE: Small dataset
|
|
813
859
|
* iter([1, 2, 3, 4, 5]).median(); // 3
|
|
814
860
|
* iter([1, 2, 3, 4]).median(); // 2.5
|
|
815
|
-
*
|
|
861
|
+
*
|
|
862
|
+
* // SAFE: Limit data before median
|
|
863
|
+
* iter(largeDataset).take(1000).median();
|
|
864
|
+
*
|
|
865
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
866
|
+
* iter(millionRecords).median(); // Materializes all records!
|
|
867
|
+
*
|
|
868
|
+
* // SAFE: Process in chunks
|
|
869
|
+
* iter(largeDataset)
|
|
870
|
+
* .chunk(1000)
|
|
871
|
+
* .map(chunk => iter(chunk).median())
|
|
872
|
+
* .toArray();
|
|
816
873
|
* ```
|
|
817
874
|
*/
|
|
818
875
|
median() {
|
|
@@ -832,12 +889,28 @@ var iterflow = class _iterflow {
|
|
|
832
889
|
* This method is only available when T is number.
|
|
833
890
|
* This is a terminal operation that consumes the iterator.
|
|
834
891
|
*
|
|
892
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire iterator into memory
|
|
893
|
+
* to calculate variance. For large datasets, consider using streaming variance algorithms
|
|
894
|
+
* or limiting data size.
|
|
895
|
+
*
|
|
835
896
|
* @param this - iterflow instance constrained to numbers
|
|
836
897
|
* @returns The variance, or undefined if the iterator is empty
|
|
837
898
|
* @example
|
|
838
899
|
* ```typescript
|
|
900
|
+
* // SAFE: Small dataset
|
|
839
901
|
* iter([1, 2, 3, 4, 5]).variance(); // 2
|
|
840
|
-
*
|
|
902
|
+
*
|
|
903
|
+
* // SAFE: Limit data before variance
|
|
904
|
+
* iter(largeDataset).take(10000).variance();
|
|
905
|
+
*
|
|
906
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
907
|
+
* iter(millionRecords).variance(); // Materializes all records!
|
|
908
|
+
*
|
|
909
|
+
* // SAFE: Process in windows
|
|
910
|
+
* iter(largeDataset)
|
|
911
|
+
* .window(1000)
|
|
912
|
+
* .map(window => iter(window).variance())
|
|
913
|
+
* .toArray();
|
|
841
914
|
* ```
|
|
842
915
|
*/
|
|
843
916
|
variance() {
|
|
@@ -858,12 +931,28 @@ var iterflow = class _iterflow {
|
|
|
858
931
|
* This method is only available when T is number.
|
|
859
932
|
* This is a terminal operation that consumes the iterator.
|
|
860
933
|
*
|
|
934
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire iterator into memory
|
|
935
|
+
* via variance calculation. For large datasets, consider using streaming algorithms
|
|
936
|
+
* or limiting data size.
|
|
937
|
+
*
|
|
861
938
|
* @param this - iterflow instance constrained to numbers
|
|
862
939
|
* @returns The standard deviation, or undefined if the iterator is empty
|
|
863
940
|
* @example
|
|
864
941
|
* ```typescript
|
|
942
|
+
* // SAFE: Small dataset
|
|
865
943
|
* iter([2, 4, 4, 4, 5, 5, 7, 9]).stdDev(); // ~2
|
|
866
|
-
*
|
|
944
|
+
*
|
|
945
|
+
* // SAFE: Limit data before stdDev
|
|
946
|
+
* iter(largeDataset).take(10000).stdDev();
|
|
947
|
+
*
|
|
948
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
949
|
+
* iter(millionRecords).stdDev(); // Materializes all records!
|
|
950
|
+
*
|
|
951
|
+
* // SAFE: Process in chunks
|
|
952
|
+
* iter(largeDataset)
|
|
953
|
+
* .chunk(1000)
|
|
954
|
+
* .map(chunk => iter(chunk).stdDev())
|
|
955
|
+
* .toArray();
|
|
867
956
|
* ```
|
|
868
957
|
*/
|
|
869
958
|
stdDev() {
|
|
@@ -876,15 +965,30 @@ var iterflow = class _iterflow {
|
|
|
876
965
|
* This method is only available when T is number.
|
|
877
966
|
* This is a terminal operation that consumes the iterator.
|
|
878
967
|
*
|
|
968
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire iterator into memory
|
|
969
|
+
* for sorting. For large datasets, consider using approximate percentile algorithms
|
|
970
|
+
* or limiting data size.
|
|
971
|
+
*
|
|
879
972
|
* @param this - iterflow instance constrained to numbers
|
|
880
973
|
* @param p - The percentile to calculate (0-100)
|
|
881
974
|
* @returns The percentile value, or undefined if the iterator is empty
|
|
882
975
|
* @throws {Error} If p is not between 0 and 100
|
|
883
976
|
* @example
|
|
884
977
|
* ```typescript
|
|
978
|
+
* // SAFE: Small dataset
|
|
885
979
|
* iter([1, 2, 3, 4, 5]).percentile(50); // 3 (median)
|
|
886
980
|
* iter([1, 2, 3, 4, 5]).percentile(75); // 4
|
|
887
|
-
*
|
|
981
|
+
*
|
|
982
|
+
* // SAFE: Limit data before percentile
|
|
983
|
+
* iter(largeDataset).take(10000).percentile(95);
|
|
984
|
+
*
|
|
985
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
986
|
+
* iter(millionRecords).percentile(99); // Materializes all records!
|
|
987
|
+
*
|
|
988
|
+
* // SAFE: Sample for approximate percentile
|
|
989
|
+
* iter(largeDataset)
|
|
990
|
+
* .filter(() => Math.random() < 0.01) // 1% sample
|
|
991
|
+
* .percentile(95);
|
|
888
992
|
* ```
|
|
889
993
|
*/
|
|
890
994
|
percentile(p) {
|
|
@@ -909,13 +1013,28 @@ var iterflow = class _iterflow {
|
|
|
909
1013
|
* This method is only available when T is number.
|
|
910
1014
|
* This is a terminal operation that consumes the iterator.
|
|
911
1015
|
*
|
|
1016
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire iterator into memory
|
|
1017
|
+
* to count frequencies. For large datasets with many unique values, memory usage can be significant.
|
|
1018
|
+
*
|
|
912
1019
|
* @param this - iterflow instance constrained to numbers
|
|
913
1020
|
* @returns An array of the most frequent value(s), or undefined if the iterator is empty
|
|
914
1021
|
* @example
|
|
915
1022
|
* ```typescript
|
|
1023
|
+
* // SAFE: Small dataset
|
|
916
1024
|
* iter([1, 2, 2, 3, 3, 3]).mode(); // [3]
|
|
917
1025
|
* iter([1, 1, 2, 2, 3]).mode(); // [1, 2] (bimodal)
|
|
918
|
-
*
|
|
1026
|
+
*
|
|
1027
|
+
* // SAFE: Limit data before mode
|
|
1028
|
+
* iter(largeDataset).take(10000).mode();
|
|
1029
|
+
*
|
|
1030
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
1031
|
+
* iter(millionRecords).mode(); // Materializes all records!
|
|
1032
|
+
*
|
|
1033
|
+
* // SAFE: Process in chunks
|
|
1034
|
+
* iter(largeDataset)
|
|
1035
|
+
* .chunk(1000)
|
|
1036
|
+
* .map(chunk => iter(chunk).mode())
|
|
1037
|
+
* .toArray();
|
|
919
1038
|
* ```
|
|
920
1039
|
*/
|
|
921
1040
|
mode() {
|
|
@@ -942,13 +1061,28 @@ var iterflow = class _iterflow {
|
|
|
942
1061
|
* This method is only available when T is number.
|
|
943
1062
|
* This is a terminal operation that consumes the iterator.
|
|
944
1063
|
*
|
|
1064
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire iterator into memory
|
|
1065
|
+
* for sorting and percentile calculation. For large datasets, consider using streaming
|
|
1066
|
+
* quantile algorithms or limiting data size.
|
|
1067
|
+
*
|
|
945
1068
|
* @param this - iterflow instance constrained to numbers
|
|
946
1069
|
* @returns An object with Q1, Q2, and Q3 values, or undefined if the iterator is empty
|
|
947
1070
|
* @example
|
|
948
1071
|
* ```typescript
|
|
1072
|
+
* // SAFE: Small dataset
|
|
949
1073
|
* iter([1, 2, 3, 4, 5, 6, 7, 8, 9]).quartiles();
|
|
950
1074
|
* // { Q1: 3, Q2: 5, Q3: 7 }
|
|
951
|
-
*
|
|
1075
|
+
*
|
|
1076
|
+
* // SAFE: Limit data before quartiles
|
|
1077
|
+
* iter(largeDataset).take(10000).quartiles();
|
|
1078
|
+
*
|
|
1079
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
1080
|
+
* iter(millionRecords).quartiles(); // Materializes all records!
|
|
1081
|
+
*
|
|
1082
|
+
* // SAFE: Sample for approximate quartiles
|
|
1083
|
+
* iter(largeDataset)
|
|
1084
|
+
* .filter(() => Math.random() < 0.01) // 1% sample
|
|
1085
|
+
* .quartiles();
|
|
952
1086
|
* ```
|
|
953
1087
|
*/
|
|
954
1088
|
quartiles() {
|
|
@@ -1027,13 +1161,34 @@ var iterflow = class _iterflow {
|
|
|
1027
1161
|
* This method is only available when T is number.
|
|
1028
1162
|
* This is a terminal operation that consumes the iterator.
|
|
1029
1163
|
*
|
|
1164
|
+
* WARNING - Memory Intensive: This operation eagerly materializes both iterators into memory
|
|
1165
|
+
* to calculate covariance. For large datasets, this doubles memory usage.
|
|
1166
|
+
*
|
|
1030
1167
|
* @param this - iterflow instance constrained to numbers
|
|
1031
1168
|
* @param other - An iterable of numbers to compare with
|
|
1032
1169
|
* @returns The covariance, or undefined if either sequence is empty or sequences have different lengths
|
|
1033
1170
|
* @example
|
|
1034
1171
|
* ```typescript
|
|
1172
|
+
* // SAFE: Small datasets
|
|
1035
1173
|
* iter([1, 2, 3, 4, 5]).covariance([2, 4, 6, 8, 10]); // 4
|
|
1036
|
-
*
|
|
1174
|
+
*
|
|
1175
|
+
* // SAFE: Limit both sequences
|
|
1176
|
+
* iter(largeDataset1).take(10000).covariance(
|
|
1177
|
+
* iter(largeDataset2).take(10000).toArray()
|
|
1178
|
+
* );
|
|
1179
|
+
*
|
|
1180
|
+
* // UNSAFE: Large datasets may cause memory issues
|
|
1181
|
+
* iter(millionRecords1).covariance(millionRecords2); // Materializes both!
|
|
1182
|
+
*
|
|
1183
|
+
* // SAFE: Process in windows
|
|
1184
|
+
* iter(largeDataset1)
|
|
1185
|
+
* .window(1000)
|
|
1186
|
+
* .map((window, i) =>
|
|
1187
|
+
* iter(window).covariance(
|
|
1188
|
+
* iter(largeDataset2).drop(i * 1000).take(1000).toArray()
|
|
1189
|
+
* )
|
|
1190
|
+
* )
|
|
1191
|
+
* .toArray();
|
|
1037
1192
|
* ```
|
|
1038
1193
|
*/
|
|
1039
1194
|
covariance(other) {
|
|
@@ -1057,14 +1212,32 @@ var iterflow = class _iterflow {
|
|
|
1057
1212
|
* This method is only available when T is number.
|
|
1058
1213
|
* This is a terminal operation that consumes the iterator.
|
|
1059
1214
|
*
|
|
1215
|
+
* WARNING - Memory Intensive: This operation eagerly materializes both iterators into memory
|
|
1216
|
+
* to calculate correlation. For large datasets, this doubles memory usage.
|
|
1217
|
+
*
|
|
1060
1218
|
* @param this - iterflow instance constrained to numbers
|
|
1061
1219
|
* @param other - An iterable of numbers to compare with
|
|
1062
1220
|
* @returns The correlation coefficient, or undefined if either sequence is empty or sequences have different lengths
|
|
1063
1221
|
* @example
|
|
1064
1222
|
* ```typescript
|
|
1065
|
-
*
|
|
1066
|
-
* iter([1, 2, 3]).correlation([
|
|
1067
|
-
* iter([]).correlation([
|
|
1223
|
+
* // SAFE: Small datasets
|
|
1224
|
+
* iter([1, 2, 3, 4, 5]).correlation([2, 4, 6, 8, 10]); // 1 (perfect positive)
|
|
1225
|
+
* iter([1, 2, 3]).correlation([3, 2, 1]); // -1 (perfect negative)
|
|
1226
|
+
*
|
|
1227
|
+
* // SAFE: Limit both sequences
|
|
1228
|
+
* iter(largeDataset1).take(10000).correlation(
|
|
1229
|
+
* iter(largeDataset2).take(10000).toArray()
|
|
1230
|
+
* );
|
|
1231
|
+
*
|
|
1232
|
+
* // UNSAFE: Large datasets may cause memory issues
|
|
1233
|
+
* iter(millionRecords1).correlation(millionRecords2); // Materializes both!
|
|
1234
|
+
*
|
|
1235
|
+
* // SAFE: Sample for approximate correlation
|
|
1236
|
+
* iter(largeDataset1)
|
|
1237
|
+
* .filter(() => Math.random() < 0.01)
|
|
1238
|
+
* .correlation(
|
|
1239
|
+
* iter(largeDataset2).filter(() => Math.random() < 0.01).toArray()
|
|
1240
|
+
* );
|
|
1068
1241
|
* ```
|
|
1069
1242
|
*/
|
|
1070
1243
|
correlation(other) {
|
|
@@ -2229,11 +2402,27 @@ var Asynciterflow = class _Asynciterflow {
|
|
|
2229
2402
|
* Calculates the median value of all numeric elements.
|
|
2230
2403
|
* This is a terminal operation that consumes the async iterator.
|
|
2231
2404
|
*
|
|
2405
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire async iterator into memory
|
|
2406
|
+
* for sorting. For large datasets, consider using streaming alternatives or limiting data size.
|
|
2407
|
+
*
|
|
2232
2408
|
* @param this - async iterflow instance constrained to numbers
|
|
2233
2409
|
* @returns A promise of the median value, or undefined if empty
|
|
2234
2410
|
* @example
|
|
2235
2411
|
* ```typescript
|
|
2412
|
+
* // SAFE: Small dataset
|
|
2236
2413
|
* await asyncIter([1, 2, 3, 4, 5]).median(); // 3
|
|
2414
|
+
*
|
|
2415
|
+
* // SAFE: Limit data before median
|
|
2416
|
+
* await asyncIter(largeAsyncDataset).take(1000).median();
|
|
2417
|
+
*
|
|
2418
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
2419
|
+
* await asyncIter(millionRecords).median(); // Materializes all records!
|
|
2420
|
+
*
|
|
2421
|
+
* // SAFE: Process in chunks
|
|
2422
|
+
* await asyncIter(largeAsyncDataset)
|
|
2423
|
+
* .chunk(1000)
|
|
2424
|
+
* .map(async chunk => await asyncIter(chunk).median())
|
|
2425
|
+
* .toArray();
|
|
2237
2426
|
* ```
|
|
2238
2427
|
*/
|
|
2239
2428
|
async median() {
|
|
@@ -2251,11 +2440,28 @@ var Asynciterflow = class _Asynciterflow {
|
|
|
2251
2440
|
* Calculates the variance of all numeric elements.
|
|
2252
2441
|
* This is a terminal operation that consumes the async iterator.
|
|
2253
2442
|
*
|
|
2443
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire async iterator into memory
|
|
2444
|
+
* to calculate variance. For large datasets, consider using streaming variance algorithms
|
|
2445
|
+
* or limiting data size.
|
|
2446
|
+
*
|
|
2254
2447
|
* @param this - async iterflow instance constrained to numbers
|
|
2255
2448
|
* @returns A promise of the variance, or undefined if empty
|
|
2256
2449
|
* @example
|
|
2257
2450
|
* ```typescript
|
|
2451
|
+
* // SAFE: Small dataset
|
|
2258
2452
|
* await asyncIter([1, 2, 3, 4, 5]).variance(); // 2
|
|
2453
|
+
*
|
|
2454
|
+
* // SAFE: Limit data before variance
|
|
2455
|
+
* await asyncIter(largeAsyncDataset).take(10000).variance();
|
|
2456
|
+
*
|
|
2457
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
2458
|
+
* await asyncIter(millionRecords).variance(); // Materializes all records!
|
|
2459
|
+
*
|
|
2460
|
+
* // SAFE: Process in windows
|
|
2461
|
+
* await asyncIter(largeAsyncDataset)
|
|
2462
|
+
* .window(1000)
|
|
2463
|
+
* .map(async window => await asyncIter(window).variance())
|
|
2464
|
+
* .toArray();
|
|
2259
2465
|
* ```
|
|
2260
2466
|
*/
|
|
2261
2467
|
async variance() {
|
|
@@ -2273,11 +2479,28 @@ var Asynciterflow = class _Asynciterflow {
|
|
|
2273
2479
|
* Calculates the standard deviation of all numeric elements.
|
|
2274
2480
|
* This is a terminal operation that consumes the async iterator.
|
|
2275
2481
|
*
|
|
2482
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire async iterator into memory
|
|
2483
|
+
* via variance calculation. For large datasets, consider using streaming algorithms
|
|
2484
|
+
* or limiting data size.
|
|
2485
|
+
*
|
|
2276
2486
|
* @param this - async iterflow instance constrained to numbers
|
|
2277
2487
|
* @returns A promise of the standard deviation, or undefined if empty
|
|
2278
2488
|
* @example
|
|
2279
2489
|
* ```typescript
|
|
2490
|
+
* // SAFE: Small dataset
|
|
2280
2491
|
* await asyncIter([2, 4, 4, 4, 5, 5, 7, 9]).stdDev(); // ~2
|
|
2492
|
+
*
|
|
2493
|
+
* // SAFE: Limit data before stdDev
|
|
2494
|
+
* await asyncIter(largeAsyncDataset).take(10000).stdDev();
|
|
2495
|
+
*
|
|
2496
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
2497
|
+
* await asyncIter(millionRecords).stdDev(); // Materializes all records!
|
|
2498
|
+
*
|
|
2499
|
+
* // SAFE: Process in chunks
|
|
2500
|
+
* await asyncIter(largeAsyncDataset)
|
|
2501
|
+
* .chunk(1000)
|
|
2502
|
+
* .map(async chunk => await asyncIter(chunk).stdDev())
|
|
2503
|
+
* .toArray();
|
|
2281
2504
|
* ```
|
|
2282
2505
|
*/
|
|
2283
2506
|
async stdDev() {
|
|
@@ -2288,13 +2511,29 @@ var Asynciterflow = class _Asynciterflow {
|
|
|
2288
2511
|
* Calculates the specified percentile of all numeric elements.
|
|
2289
2512
|
* This is a terminal operation that consumes the async iterator.
|
|
2290
2513
|
*
|
|
2514
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire async iterator into memory
|
|
2515
|
+
* for sorting. For large datasets, consider using approximate percentile algorithms
|
|
2516
|
+
* or limiting data size.
|
|
2517
|
+
*
|
|
2291
2518
|
* @param this - async iterflow instance constrained to numbers
|
|
2292
2519
|
* @param p - The percentile to calculate (0-100)
|
|
2293
2520
|
* @returns A promise of the percentile value, or undefined if empty
|
|
2294
2521
|
* @throws {Error} If p is not between 0 and 100
|
|
2295
2522
|
* @example
|
|
2296
2523
|
* ```typescript
|
|
2524
|
+
* // SAFE: Small dataset
|
|
2297
2525
|
* await asyncIter([1, 2, 3, 4, 5]).percentile(50); // 3
|
|
2526
|
+
*
|
|
2527
|
+
* // SAFE: Limit data before percentile
|
|
2528
|
+
* await asyncIter(largeAsyncDataset).take(10000).percentile(95);
|
|
2529
|
+
*
|
|
2530
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
2531
|
+
* await asyncIter(millionRecords).percentile(99); // Materializes all records!
|
|
2532
|
+
*
|
|
2533
|
+
* // SAFE: Sample for approximate percentile
|
|
2534
|
+
* await asyncIter(largeAsyncDataset)
|
|
2535
|
+
* .filter(async () => Math.random() < 0.01) // 1% sample
|
|
2536
|
+
* .percentile(95);
|
|
2298
2537
|
* ```
|
|
2299
2538
|
*/
|
|
2300
2539
|
async percentile(p) {
|
|
@@ -2317,11 +2556,27 @@ var Asynciterflow = class _Asynciterflow {
|
|
|
2317
2556
|
* Finds the most frequent value(s) in the dataset.
|
|
2318
2557
|
* This is a terminal operation that consumes the async iterator.
|
|
2319
2558
|
*
|
|
2559
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire async iterator into memory
|
|
2560
|
+
* to count frequencies. For large datasets with many unique values, memory usage can be significant.
|
|
2561
|
+
*
|
|
2320
2562
|
* @param this - async iterflow instance constrained to numbers
|
|
2321
2563
|
* @returns A promise of an array of the most frequent value(s), or undefined if empty
|
|
2322
2564
|
* @example
|
|
2323
2565
|
* ```typescript
|
|
2566
|
+
* // SAFE: Small dataset
|
|
2324
2567
|
* await asyncIter([1, 2, 2, 3, 3, 3]).mode(); // [3]
|
|
2568
|
+
*
|
|
2569
|
+
* // SAFE: Limit data before mode
|
|
2570
|
+
* await asyncIter(largeAsyncDataset).take(10000).mode();
|
|
2571
|
+
*
|
|
2572
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
2573
|
+
* await asyncIter(millionRecords).mode(); // Materializes all records!
|
|
2574
|
+
*
|
|
2575
|
+
* // SAFE: Process in chunks
|
|
2576
|
+
* await asyncIter(largeAsyncDataset)
|
|
2577
|
+
* .chunk(1000)
|
|
2578
|
+
* .map(async chunk => await asyncIter(chunk).mode())
|
|
2579
|
+
* .toArray();
|
|
2325
2580
|
* ```
|
|
2326
2581
|
*/
|
|
2327
2582
|
async mode() {
|
|
@@ -2346,12 +2601,28 @@ var Asynciterflow = class _Asynciterflow {
|
|
|
2346
2601
|
* Calculates the quartiles (Q1, Q2, Q3) of all numeric elements.
|
|
2347
2602
|
* This is a terminal operation that consumes the async iterator.
|
|
2348
2603
|
*
|
|
2604
|
+
* WARNING - Memory Intensive: This operation eagerly materializes the entire async iterator into memory
|
|
2605
|
+
* for sorting and percentile calculation. For large datasets, consider using streaming
|
|
2606
|
+
* quantile algorithms or limiting data size.
|
|
2607
|
+
*
|
|
2349
2608
|
* @param this - async iterflow instance constrained to numbers
|
|
2350
2609
|
* @returns A promise of an object with Q1, Q2, and Q3 values, or undefined if empty
|
|
2351
2610
|
* @example
|
|
2352
2611
|
* ```typescript
|
|
2612
|
+
* // SAFE: Small dataset
|
|
2353
2613
|
* await asyncIter([1, 2, 3, 4, 5, 6, 7, 8, 9]).quartiles();
|
|
2354
2614
|
* // { Q1: 3, Q2: 5, Q3: 7 }
|
|
2615
|
+
*
|
|
2616
|
+
* // SAFE: Limit data before quartiles
|
|
2617
|
+
* await asyncIter(largeAsyncDataset).take(10000).quartiles();
|
|
2618
|
+
*
|
|
2619
|
+
* // UNSAFE: Large dataset may cause memory issues
|
|
2620
|
+
* await asyncIter(millionRecords).quartiles(); // Materializes all records!
|
|
2621
|
+
*
|
|
2622
|
+
* // SAFE: Sample for approximate quartiles
|
|
2623
|
+
* await asyncIter(largeAsyncDataset)
|
|
2624
|
+
* .filter(async () => Math.random() < 0.01) // 1% sample
|
|
2625
|
+
* .quartiles();
|
|
2355
2626
|
* ```
|
|
2356
2627
|
*/
|
|
2357
2628
|
async quartiles() {
|
|
@@ -2422,12 +2693,34 @@ var Asynciterflow = class _Asynciterflow {
|
|
|
2422
2693
|
* Calculates the covariance between two numeric sequences.
|
|
2423
2694
|
* This is a terminal operation that consumes the async iterator.
|
|
2424
2695
|
*
|
|
2696
|
+
* WARNING - Memory Intensive: This operation eagerly materializes both async iterators into memory
|
|
2697
|
+
* to calculate covariance. For large datasets, this doubles memory usage.
|
|
2698
|
+
*
|
|
2425
2699
|
* @param this - async iterflow instance constrained to numbers
|
|
2426
2700
|
* @param other - An async iterable of numbers to compare with
|
|
2427
2701
|
* @returns A promise of the covariance, or undefined if sequences are empty or have different lengths
|
|
2428
2702
|
* @example
|
|
2429
2703
|
* ```typescript
|
|
2704
|
+
* // SAFE: Small datasets
|
|
2430
2705
|
* await asyncIter([1, 2, 3, 4, 5]).covariance([2, 4, 6, 8, 10]); // 4
|
|
2706
|
+
*
|
|
2707
|
+
* // SAFE: Limit both sequences
|
|
2708
|
+
* await asyncIter(largeAsyncDataset1).take(10000).covariance(
|
|
2709
|
+
* await asyncIter(largeAsyncDataset2).take(10000).toArray()
|
|
2710
|
+
* );
|
|
2711
|
+
*
|
|
2712
|
+
* // UNSAFE: Large datasets may cause memory issues
|
|
2713
|
+
* await asyncIter(millionRecords1).covariance(millionRecords2); // Materializes both!
|
|
2714
|
+
*
|
|
2715
|
+
* // SAFE: Process in windows
|
|
2716
|
+
* await asyncIter(largeAsyncDataset1)
|
|
2717
|
+
* .window(1000)
|
|
2718
|
+
* .map(async (window, i) =>
|
|
2719
|
+
* await asyncIter(window).covariance(
|
|
2720
|
+
* await asyncIter(largeAsyncDataset2).drop(i * 1000).take(1000).toArray()
|
|
2721
|
+
* )
|
|
2722
|
+
* )
|
|
2723
|
+
* .toArray();
|
|
2431
2724
|
* ```
|
|
2432
2725
|
*/
|
|
2433
2726
|
async covariance(other) {
|
|
@@ -2457,12 +2750,33 @@ var Asynciterflow = class _Asynciterflow {
|
|
|
2457
2750
|
* Calculates the Pearson correlation coefficient between two numeric sequences.
|
|
2458
2751
|
* This is a terminal operation that consumes the async iterator.
|
|
2459
2752
|
*
|
|
2753
|
+
* WARNING - Memory Intensive: This operation eagerly materializes both async iterators into memory
|
|
2754
|
+
* to calculate correlation. For large datasets, this doubles memory usage.
|
|
2755
|
+
*
|
|
2460
2756
|
* @param this - async iterflow instance constrained to numbers
|
|
2461
2757
|
* @param other - An async iterable of numbers to compare with
|
|
2462
2758
|
* @returns A promise of the correlation coefficient, or undefined if sequences are empty or have different lengths
|
|
2463
2759
|
* @example
|
|
2464
2760
|
* ```typescript
|
|
2761
|
+
* // SAFE: Small datasets
|
|
2465
2762
|
* await asyncIter([1, 2, 3, 4, 5]).correlation([2, 4, 6, 8, 10]); // 1
|
|
2763
|
+
*
|
|
2764
|
+
* // SAFE: Limit both sequences
|
|
2765
|
+
* await asyncIter(largeAsyncDataset1).take(10000).correlation(
|
|
2766
|
+
* await asyncIter(largeAsyncDataset2).take(10000).toArray()
|
|
2767
|
+
* );
|
|
2768
|
+
*
|
|
2769
|
+
* // UNSAFE: Large datasets may cause memory issues
|
|
2770
|
+
* await asyncIter(millionRecords1).correlation(millionRecords2); // Materializes both!
|
|
2771
|
+
*
|
|
2772
|
+
* // SAFE: Sample for approximate correlation
|
|
2773
|
+
* await asyncIter(largeAsyncDataset1)
|
|
2774
|
+
* .filter(async () => Math.random() < 0.01)
|
|
2775
|
+
* .correlation(
|
|
2776
|
+
* await asyncIter(largeAsyncDataset2)
|
|
2777
|
+
* .filter(async () => Math.random() < 0.01)
|
|
2778
|
+
* .toArray()
|
|
2779
|
+
* );
|
|
2466
2780
|
* ```
|
|
2467
2781
|
*/
|
|
2468
2782
|
async correlation(other) {
|