ts-data-forge 1.5.0 → 1.5.2
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/dist/array/array-utils.d.mts +137 -358
- package/dist/array/array-utils.d.mts.map +1 -1
- package/dist/array/array-utils.mjs +191 -1966
- package/dist/array/array-utils.mjs.map +1 -1
- package/dist/array/tuple-utils.d.mts +9 -23
- package/dist/array/tuple-utils.d.mts.map +1 -1
- package/dist/array/tuple-utils.mjs +10 -56
- package/dist/array/tuple-utils.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/functional/match.d.mts +2 -33
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs +2 -119
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional.d.mts +34 -197
- package/dist/functional/optional.d.mts.map +1 -1
- package/dist/functional/optional.mjs +40 -312
- package/dist/functional/optional.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +2 -15
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs +2 -110
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result.d.mts +18 -209
- package/dist/functional/result.d.mts.map +1 -1
- package/dist/functional/result.mjs +40 -360
- package/dist/functional/result.mjs.map +1 -1
- package/dist/guard/has-key.d.mts +1 -1
- package/dist/guard/has-key.mjs +1 -1
- package/dist/iterator/range.d.mts +2 -6
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs +2 -93
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +14 -438
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +14 -438
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/num.d.mts +7 -107
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +7 -122
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +4 -10
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +8 -140
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.d.mts +2 -6
- package/dist/others/map-nullable.d.mts.map +1 -1
- package/dist/others/map-nullable.mjs +2 -146
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/package.json +11 -11
- package/src/array/array-utils.mts +707 -881
- package/src/array/tuple-utils.mts +20 -41
- package/src/functional/match.mts +18 -44
- package/src/functional/optional.mts +93 -248
- package/src/functional/pipe.mts +25 -20
- package/src/functional/result.mts +114 -288
- package/src/guard/has-key.mts +1 -1
- package/src/iterator/range.mts +14 -17
- package/src/json/json.mts +14 -438
- package/src/number/num.mts +20 -113
- package/src/object/object.mts +30 -45
- package/src/others/map-nullable.mts +13 -15
|
@@ -97,12 +97,9 @@ export declare namespace Arr {
|
|
|
97
97
|
* @see {@link isEmpty} for checking if size is 0
|
|
98
98
|
* @see {@link isNonEmpty} for checking if size > 0
|
|
99
99
|
*/
|
|
100
|
-
export
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
<Ar extends readonly unknown[]>(array: Ar): SizeType.Arr;
|
|
104
|
-
};
|
|
105
|
-
export const length: SizeFnOverload;
|
|
100
|
+
export function size<Ar extends NonEmptyArray<unknown>>(array: Ar): IntersectBrand<PositiveNumber, SizeType.Arr>;
|
|
101
|
+
export function size<Ar extends readonly unknown[]>(array: Ar): SizeType.Arr;
|
|
102
|
+
export const length: typeof size;
|
|
106
103
|
/**
|
|
107
104
|
* Type guard that checks if a value is an array, excluding types that cannot be arrays.
|
|
108
105
|
* This function refines the type by filtering out non-array types from unions.
|
|
@@ -391,21 +388,18 @@ export declare namespace Arr {
|
|
|
391
388
|
* expectType<typeof maybeEmpty, readonly 0[]>('=');
|
|
392
389
|
* ```
|
|
393
390
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
*/
|
|
407
|
-
(len: SizeType.ArgArrNonNegative): readonly 0[];
|
|
408
|
-
};
|
|
391
|
+
/**
|
|
392
|
+
* Create array of zeros with compile-time length.
|
|
393
|
+
*/
|
|
394
|
+
export function zeros<N extends SmallUint>(len: N): ArrayOfLength<N, 0>;
|
|
395
|
+
/**
|
|
396
|
+
* Create non-empty array of zeros.
|
|
397
|
+
*/
|
|
398
|
+
export function zeros(len: SizeType.ArgArrPositive): NonEmptyArray<0>;
|
|
399
|
+
/**
|
|
400
|
+
* Create array of zeros.
|
|
401
|
+
*/
|
|
402
|
+
export function zeros(len: SizeType.ArgArrNonNegative): readonly 0[];
|
|
409
403
|
/**
|
|
410
404
|
* Creates a sequence of consecutive integers from 0 to `len-1`.
|
|
411
405
|
*
|
|
@@ -447,12 +441,9 @@ export declare namespace Arr {
|
|
|
447
441
|
* expectType<typeof single, readonly [0]>('=');
|
|
448
442
|
* ```
|
|
449
443
|
*/
|
|
450
|
-
export
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
(len: SizeType.ArgArrPositive): NonEmptyArray<SizeType.Arr>;
|
|
454
|
-
(len: SizeType.ArgArrNonNegative): readonly SizeType.Arr[];
|
|
455
|
-
};
|
|
444
|
+
export function seq<N extends SmallUint>(len: N): Seq<N>;
|
|
445
|
+
export function seq(len: SizeType.ArgArrPositive): NonEmptyArray<SizeType.Arr>;
|
|
446
|
+
export function seq(len: SizeType.ArgArrNonNegative): readonly SizeType.Arr[];
|
|
456
447
|
/**
|
|
457
448
|
* Creates a new array of the specified length, with each position filled with the provided initial value.
|
|
458
449
|
*
|
|
@@ -501,13 +492,10 @@ export declare namespace Arr {
|
|
|
501
492
|
* @see {@link zeros} for creating arrays filled with zeros
|
|
502
493
|
* @see {@link seq} for creating sequences of consecutive integers
|
|
503
494
|
*/
|
|
504
|
-
export const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
<const V>(len: SizeType.ArgArrNonNegative, init: V): readonly V[];
|
|
509
|
-
};
|
|
510
|
-
export const newArray: CreateFnOverload;
|
|
495
|
+
export function create<const V, N extends SmallUint>(len: N, init: V): ArrayOfLength<N, V>;
|
|
496
|
+
export function create<const V>(len: SizeType.ArgArrPositive, init: V): NonEmptyArray<V>;
|
|
497
|
+
export function create<const V>(len: SizeType.ArgArrNonNegative, init: V): readonly V[];
|
|
498
|
+
export const newArray: typeof create;
|
|
511
499
|
/**
|
|
512
500
|
* Creates an array from a generator function.
|
|
513
501
|
*
|
|
@@ -707,12 +695,9 @@ export declare namespace Arr {
|
|
|
707
695
|
* @see {@link SmallUint} for understanding the constraint that enables precise typing
|
|
708
696
|
* @see {@link SafeInt} and {@link SafeUint} for the safe integer types used
|
|
709
697
|
*/
|
|
710
|
-
export
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
(start: SafeUintWithSmallInt, end: SafeUintWithSmallInt, step?: PositiveSafeIntWithSmallInt): readonly SafeUint[];
|
|
714
|
-
(start: SafeIntWithSmallInt, end: SafeIntWithSmallInt, step?: NonZeroSafeIntWithSmallInt): readonly SafeInt[];
|
|
715
|
-
};
|
|
698
|
+
export function range<S extends SmallUint, E extends SmallUint>(start: S, end: E, step?: 1): RangeList<S, E>;
|
|
699
|
+
export function range(start: SafeUintWithSmallInt, end: SafeUintWithSmallInt, step?: PositiveSafeIntWithSmallInt): readonly SafeUint[];
|
|
700
|
+
export function range(start: SafeIntWithSmallInt, end: SafeIntWithSmallInt, step?: NonZeroSafeIntWithSmallInt): readonly SafeInt[];
|
|
716
701
|
/**
|
|
717
702
|
* Safely retrieves an element at a given index from an array, returning an {@link Optional}.
|
|
718
703
|
*
|
|
@@ -823,14 +808,8 @@ export declare namespace Arr {
|
|
|
823
808
|
* @see {@link Optional.unwrapOr} for safe unwrapping with defaults
|
|
824
809
|
* @see {@link Optional.map} for transforming Optional values
|
|
825
810
|
*/
|
|
826
|
-
export
|
|
827
|
-
|
|
828
|
-
* Function type for safely accessing an array element at a given index.
|
|
829
|
-
*/
|
|
830
|
-
type AtFnOverload = {
|
|
831
|
-
<E>(array: readonly E[], index: SizeType.ArgArr): Optional<E>;
|
|
832
|
-
(index: SizeType.ArgArr): <E>(array: readonly E[]) => Optional<E>;
|
|
833
|
-
};
|
|
811
|
+
export function at<E>(array: readonly E[], index: SizeType.ArgArr): Optional<E>;
|
|
812
|
+
export function at(index: SizeType.ArgArr): <E>(array: readonly E[]) => Optional<E>;
|
|
834
813
|
/**
|
|
835
814
|
* Returns the first element of an array wrapped in an Optional.
|
|
836
815
|
*
|
|
@@ -902,25 +881,10 @@ export declare namespace Arr {
|
|
|
902
881
|
* @see {@link at} for accessing elements at specific indices
|
|
903
882
|
* @see {@link tail} for getting all elements except the first
|
|
904
883
|
*/
|
|
905
|
-
export
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
*/
|
|
910
|
-
(array: readonly []): Optional.None;
|
|
911
|
-
/**
|
|
912
|
-
* Get head of tuple.
|
|
913
|
-
*/
|
|
914
|
-
<E, L extends readonly unknown[]>(array: readonly [E, ...L]): Optional.Some<E>;
|
|
915
|
-
/**
|
|
916
|
-
* Get head of non-empty array.
|
|
917
|
-
*/
|
|
918
|
-
<E>(array: NonEmptyArray<E>): Optional.Some<E>;
|
|
919
|
-
/**
|
|
920
|
-
* Get head of any array.
|
|
921
|
-
*/
|
|
922
|
-
<E>(array: readonly E[]): Optional<E>;
|
|
923
|
-
};
|
|
884
|
+
export function head(array: readonly []): Optional.None;
|
|
885
|
+
export function head<E, L extends readonly unknown[]>(array: readonly [E, ...L]): Optional.Some<E>;
|
|
886
|
+
export function head<E>(array: NonEmptyArray<E>): Optional.Some<E>;
|
|
887
|
+
export function head<E>(array: readonly E[]): Optional<E>;
|
|
924
888
|
/**
|
|
925
889
|
* Returns the last element of an array wrapped in an Optional.
|
|
926
890
|
*
|
|
@@ -1001,25 +965,10 @@ export declare namespace Arr {
|
|
|
1001
965
|
* @see {@link at} for accessing elements at specific indices with negative indexing support
|
|
1002
966
|
* @see {@link butLast} for getting all elements except the last
|
|
1003
967
|
*/
|
|
1004
|
-
export
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
*/
|
|
1009
|
-
(array: readonly []): Optional.None;
|
|
1010
|
-
/**
|
|
1011
|
-
* Get last of tuple.
|
|
1012
|
-
*/
|
|
1013
|
-
<Ar extends readonly unknown[], L>(array: readonly [...Ar, L]): Optional.Some<L>;
|
|
1014
|
-
/**
|
|
1015
|
-
* Get last of non-empty array.
|
|
1016
|
-
*/
|
|
1017
|
-
<E>(array: NonEmptyArray<E>): Optional.Some<E>;
|
|
1018
|
-
/**
|
|
1019
|
-
* Get last of any array.
|
|
1020
|
-
*/
|
|
1021
|
-
<E>(array: readonly E[]): Optional<E>;
|
|
1022
|
-
};
|
|
968
|
+
export function last(array: readonly []): Optional.None;
|
|
969
|
+
export function last<Ar extends readonly unknown[], L>(array: readonly [...Ar, L]): Optional.Some<L>;
|
|
970
|
+
export function last<E>(array: NonEmptyArray<E>): Optional.Some<E>;
|
|
971
|
+
export function last<E>(array: readonly E[]): Optional<E>;
|
|
1023
972
|
/**
|
|
1024
973
|
* Slices an array with automatically clamped start and end indices for safe bounds handling.
|
|
1025
974
|
*
|
|
@@ -1103,11 +1052,8 @@ export declare namespace Arr {
|
|
|
1103
1052
|
* @see {@link skip} for skipping the first N elements
|
|
1104
1053
|
* @see {@link takeLast} for taking the last N elements
|
|
1105
1054
|
*/
|
|
1106
|
-
export
|
|
1107
|
-
|
|
1108
|
-
<E>(array: readonly E[], start: SizeType.ArgArr, end: SizeType.ArgArr): readonly E[];
|
|
1109
|
-
(start: SizeType.ArgArr, end: SizeType.ArgArr): <E>(array: readonly E[]) => readonly E[];
|
|
1110
|
-
};
|
|
1055
|
+
export function sliceClamped<E>(array: readonly E[], start: SizeType.ArgArr, end: SizeType.ArgArr): readonly E[];
|
|
1056
|
+
export function sliceClamped(start: SizeType.ArgArr, end: SizeType.ArgArr): <E>(array: readonly E[]) => readonly E[];
|
|
1111
1057
|
/**
|
|
1112
1058
|
* Returns all elements of an array except the first one.
|
|
1113
1059
|
* @template E The type of the array (can be a tuple for more precise typing).
|
|
@@ -1157,15 +1103,12 @@ export declare namespace Arr {
|
|
|
1157
1103
|
* console.log(result); // [1, 2, 3]
|
|
1158
1104
|
* ```
|
|
1159
1105
|
*/
|
|
1160
|
-
export
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
<E>(array: readonly E[], num: SizeType.ArgArrNonNegative): readonly E[];
|
|
1167
|
-
(num: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1168
|
-
};
|
|
1106
|
+
export function take<Ar extends readonly unknown[], N extends SmallUint>(array: Ar, num: N): List.Take<N, Ar>;
|
|
1107
|
+
export function take<N extends SmallUint>(num: N): <Ar extends readonly unknown[]>(array: Ar) => List.Take<N, Ar>;
|
|
1108
|
+
export function take<E>(array: NonEmptyArray<E>, num: SizeType.ArgArrPositive): NonEmptyArray<E>;
|
|
1109
|
+
export function take(num: SizeType.ArgArrPositive): <E>(array: NonEmptyArray<E>) => NonEmptyArray<E>;
|
|
1110
|
+
export function take<E>(array: readonly E[], num: SizeType.ArgArrNonNegative): readonly E[];
|
|
1111
|
+
export function take(num: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1169
1112
|
/**
|
|
1170
1113
|
* Takes the last N elements from an array.
|
|
1171
1114
|
*
|
|
@@ -1189,15 +1132,12 @@ export declare namespace Arr {
|
|
|
1189
1132
|
* console.log(result); // [4, 5]
|
|
1190
1133
|
* ```
|
|
1191
1134
|
*/
|
|
1192
|
-
export
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
<E>(array: readonly E[], num: SizeType.ArgArrNonNegative): readonly E[];
|
|
1199
|
-
(num: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1200
|
-
};
|
|
1135
|
+
export function takeLast<Ar extends readonly unknown[], N extends SmallUint>(array: Ar, num: N): List.TakeLast<N, Ar>;
|
|
1136
|
+
export function takeLast<N extends SmallUint>(num: N): <Ar extends readonly unknown[]>(array: Ar) => List.TakeLast<N, Ar>;
|
|
1137
|
+
export function takeLast<E>(array: NonEmptyArray<E>, num: SizeType.ArgArrPositive): NonEmptyArray<E>;
|
|
1138
|
+
export function takeLast(num: SizeType.ArgArrPositive): <E>(array: NonEmptyArray<E>) => NonEmptyArray<E>;
|
|
1139
|
+
export function takeLast<E>(array: readonly E[], num: SizeType.ArgArrNonNegative): readonly E[];
|
|
1140
|
+
export function takeLast(num: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1201
1141
|
/**
|
|
1202
1142
|
* Skips the first N elements of an array.
|
|
1203
1143
|
*
|
|
@@ -1221,15 +1161,12 @@ export declare namespace Arr {
|
|
|
1221
1161
|
* console.log(result); // [3, 4, 5]
|
|
1222
1162
|
* ```
|
|
1223
1163
|
*/
|
|
1224
|
-
export
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
(num: SizeType.ArgArrPositive): <E>(array: NonEmptyArray<E>) => readonly E[];
|
|
1231
|
-
(num: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1232
|
-
};
|
|
1164
|
+
export function skip<Ar extends readonly unknown[], N extends SmallUint>(array: Ar, num: N): List.Skip<N, Ar>;
|
|
1165
|
+
export function skip<E>(array: NonEmptyArray<E>, num: SizeType.ArgArrPositive): readonly E[];
|
|
1166
|
+
export function skip<E>(array: readonly E[], num: SizeType.ArgArrNonNegative): readonly E[];
|
|
1167
|
+
export function skip<N extends SmallUint>(num: N): <Ar extends readonly unknown[]>(array: Ar) => List.Skip<N, Ar>;
|
|
1168
|
+
export function skip(num: SizeType.ArgArrPositive): <E>(array: NonEmptyArray<E>) => readonly E[];
|
|
1169
|
+
export function skip(num: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1233
1170
|
/**
|
|
1234
1171
|
* Skips the last N elements of an array.
|
|
1235
1172
|
*
|
|
@@ -1253,13 +1190,10 @@ export declare namespace Arr {
|
|
|
1253
1190
|
* console.log(result); // [1, 2, 3]
|
|
1254
1191
|
* ```
|
|
1255
1192
|
*/
|
|
1256
|
-
export
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
<N extends SmallUint>(num: N): <Ar extends readonly unknown[]>(array: Ar) => List.SkipLast<N, Ar>;
|
|
1261
|
-
(num: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1262
|
-
};
|
|
1193
|
+
export function skipLast<Ar extends readonly unknown[], N extends SmallUint>(array: Ar, num: N): List.SkipLast<N, Ar>;
|
|
1194
|
+
export function skipLast<N extends SmallUint>(num: N): <Ar extends readonly unknown[]>(array: Ar) => List.SkipLast<N, Ar>;
|
|
1195
|
+
export function skipLast<E>(array: readonly E[], num: SizeType.ArgArrNonNegative): readonly E[];
|
|
1196
|
+
export function skipLast(num: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1263
1197
|
/**
|
|
1264
1198
|
* Returns a new array with the element at the specified index updated by a function.
|
|
1265
1199
|
*
|
|
@@ -1414,11 +1348,8 @@ export declare namespace Arr {
|
|
|
1414
1348
|
* @see {@link SizeType.ArgArrNonNegative} for the index type constraint
|
|
1415
1349
|
* @see Immutable update patterns for functional programming approaches
|
|
1416
1350
|
*/
|
|
1417
|
-
export
|
|
1418
|
-
|
|
1419
|
-
<E, U>(array: readonly E[], index: SizeType.ArgArrNonNegative, updater: (prev: E) => U): readonly (E | U)[];
|
|
1420
|
-
<E, U>(index: SizeType.ArgArrNonNegative, updater: (prev: E) => U): (array: readonly E[]) => readonly (E | U)[];
|
|
1421
|
-
};
|
|
1351
|
+
export function toUpdated<E, U>(array: readonly E[], index: SizeType.ArgArrNonNegative, updater: (prev: E) => U): readonly (E | U)[];
|
|
1352
|
+
export function toUpdated<E, U>(index: SizeType.ArgArrNonNegative, updater: (prev: E) => U): (array: readonly E[]) => readonly (E | U)[];
|
|
1422
1353
|
/**
|
|
1423
1354
|
* Returns a new array with a new value inserted at the specified index.
|
|
1424
1355
|
* Index can be out of bounds (e.g., negative or greater than length), `toSpliced` handles this.
|
|
@@ -1438,11 +1369,8 @@ export declare namespace Arr {
|
|
|
1438
1369
|
* console.log(result); // [99, 1, 2, 3]
|
|
1439
1370
|
* ```
|
|
1440
1371
|
*/
|
|
1441
|
-
export const
|
|
1442
|
-
|
|
1443
|
-
<E, const V = E>(array: readonly E[], index: SizeType.ArgArrNonNegative, newValue: V): NonEmptyArray<E | V>;
|
|
1444
|
-
<E, const V = E>(index: SizeType.ArgArrNonNegative, newValue: V): (array: readonly E[]) => NonEmptyArray<E | V>;
|
|
1445
|
-
};
|
|
1372
|
+
export function toInserted<E, const V = E>(array: readonly E[], index: SizeType.ArgArrNonNegative, newValue: V): NonEmptyArray<E | V>;
|
|
1373
|
+
export function toInserted<E, const V = E>(index: SizeType.ArgArrNonNegative, newValue: V): (array: readonly E[]) => NonEmptyArray<E | V>;
|
|
1446
1374
|
/**
|
|
1447
1375
|
* Returns a new array with the element at the specified index removed.
|
|
1448
1376
|
* If index is out of bounds, `toSpliced` handles this (usually by returning a copy).
|
|
@@ -1461,11 +1389,8 @@ export declare namespace Arr {
|
|
|
1461
1389
|
* console.log(result); // [20, 30]
|
|
1462
1390
|
* ```
|
|
1463
1391
|
*/
|
|
1464
|
-
export
|
|
1465
|
-
|
|
1466
|
-
<E>(array: readonly E[], index: SizeType.ArgArrNonNegative): readonly E[];
|
|
1467
|
-
(index: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1468
|
-
};
|
|
1392
|
+
export function toRemoved<E>(array: readonly E[], index: SizeType.ArgArrNonNegative): readonly E[];
|
|
1393
|
+
export function toRemoved(index: SizeType.ArgArrNonNegative): <E>(array: readonly E[]) => readonly E[];
|
|
1469
1394
|
/**
|
|
1470
1395
|
* Returns a new array with a value added to the end.
|
|
1471
1396
|
* @template E The type of the input array (can be a tuple).
|
|
@@ -1484,11 +1409,8 @@ export declare namespace Arr {
|
|
|
1484
1409
|
* console.log(result); // [1, 2, 3, 0]
|
|
1485
1410
|
* ```
|
|
1486
1411
|
*/
|
|
1487
|
-
export const
|
|
1488
|
-
|
|
1489
|
-
<Ar extends readonly unknown[], const V>(array: Ar, newValue: V): readonly [...Ar, V];
|
|
1490
|
-
<const V>(newValue: V): <Ar extends readonly unknown[]>(array: Ar) => readonly [...Ar, V];
|
|
1491
|
-
};
|
|
1412
|
+
export function toPushed<Ar extends readonly unknown[], const V>(array: Ar, newValue: V): readonly [...Ar, V];
|
|
1413
|
+
export function toPushed<const V>(newValue: V): <Ar extends readonly unknown[]>(array: Ar) => readonly [...Ar, V];
|
|
1492
1414
|
/**
|
|
1493
1415
|
* Returns a new array with a value added to the beginning.
|
|
1494
1416
|
* @template E The type of the input array (can be a tuple).
|
|
@@ -1507,11 +1429,8 @@ export declare namespace Arr {
|
|
|
1507
1429
|
* console.log(result); // [0, 1, 2, 3]
|
|
1508
1430
|
* ```
|
|
1509
1431
|
*/
|
|
1510
|
-
export const
|
|
1511
|
-
|
|
1512
|
-
<Ar extends readonly unknown[], const V>(array: Ar, newValue: V): readonly [V, ...Ar];
|
|
1513
|
-
<const V>(newValue: V): <Ar extends readonly unknown[]>(array: Ar) => readonly [V, ...Ar];
|
|
1514
|
-
};
|
|
1432
|
+
export function toUnshifted<Ar extends readonly unknown[], const V>(array: Ar, newValue: V): readonly [V, ...Ar];
|
|
1433
|
+
export function toUnshifted<const V>(newValue: V): <Ar extends readonly unknown[]>(array: Ar) => readonly [V, ...Ar];
|
|
1515
1434
|
/**
|
|
1516
1435
|
* Fills an array with a value (creates a new filled array).
|
|
1517
1436
|
* @param array The array.
|
|
@@ -1532,16 +1451,10 @@ export declare namespace Arr {
|
|
|
1532
1451
|
* console.log(result2); // [1, 0, 0, 4]
|
|
1533
1452
|
* ```
|
|
1534
1453
|
*/
|
|
1535
|
-
export
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
};
|
|
1540
|
-
export const toRangeFilled: ToRangeFilledFnOverload;
|
|
1541
|
-
type ToRangeFilledFnOverload = {
|
|
1542
|
-
<E>(array: readonly E[], value: E, fillRange: readonly [start: SizeType.ArgArr, end: SizeType.ArgArr]): readonly E[];
|
|
1543
|
-
<E>(value: E, fillRange: readonly [start: SizeType.ArgArr, end: SizeType.ArgArr]): (array: readonly E[]) => readonly E[];
|
|
1544
|
-
};
|
|
1454
|
+
export function toFilled<E>(array: readonly E[], value: E): readonly E[];
|
|
1455
|
+
export function toFilled<E>(value: E): (array: readonly E[]) => readonly E[];
|
|
1456
|
+
export function toRangeFilled<E>(array: readonly E[], value: E, fillRange: readonly [start: SizeType.ArgArr, end: SizeType.ArgArr]): readonly E[];
|
|
1457
|
+
export function toRangeFilled<E>(value: E, fillRange: readonly [start: SizeType.ArgArr, end: SizeType.ArgArr]): (array: readonly E[]) => readonly E[];
|
|
1545
1458
|
/**
|
|
1546
1459
|
* Safely finds the first element in an array that satisfies a predicate function.
|
|
1547
1460
|
*
|
|
@@ -1564,83 +1477,23 @@ export declare namespace Arr {
|
|
|
1564
1477
|
*
|
|
1565
1478
|
* @example
|
|
1566
1479
|
* ```typescript
|
|
1567
|
-
* // Basic element finding
|
|
1568
1480
|
* const numbers = [1, 2, 3, 4, 5];
|
|
1569
1481
|
* const firstEven = Arr.find(numbers, x => x % 2 === 0);
|
|
1570
1482
|
* if (Optional.isSome(firstEven)) {
|
|
1571
|
-
* console.log(firstEven.value); // 2
|
|
1483
|
+
* console.log(firstEven.value); // 2
|
|
1572
1484
|
* }
|
|
1573
1485
|
*
|
|
1574
|
-
*
|
|
1575
|
-
* const findLargeAtEnd = Arr.find(numbers, (value, index) => value > 3 && index > 2);
|
|
1576
|
-
* // Optional.Some(4) - first number > 3 after index 2
|
|
1577
|
-
*
|
|
1578
|
-
* // Finding objects by property
|
|
1579
|
-
* const users = [
|
|
1580
|
-
* { id: 1, name: 'Alice', age: 25 },
|
|
1581
|
-
* { id: 2, name: 'Bob', age: 30 },
|
|
1582
|
-
* { id: 3, name: 'Charlie', age: 35 }
|
|
1583
|
-
* ];
|
|
1584
|
-
*
|
|
1486
|
+
* const users = [{ id: 1, name: 'Alice', age: 25 }, { id: 2, name: 'Bob', age: 30 }];
|
|
1585
1487
|
* const adult = Arr.find(users, user => user.age >= 30);
|
|
1586
1488
|
* // Optional.Some({ id: 2, name: 'Bob', age: 30 })
|
|
1587
|
-
*
|
|
1588
|
-
* const nonExistent = Arr.find(users, user => user.age > 100);
|
|
1589
|
-
* // Optional.None
|
|
1590
|
-
*
|
|
1591
|
-
* // Empty array handling
|
|
1592
|
-
* const emptyResult = Arr.find([], x => x > 0); // Optional.None
|
|
1593
|
-
*
|
|
1594
|
-
* // Curried usage for functional composition
|
|
1595
|
-
* const findNegative = Arr.find((x: number) => x < 0);
|
|
1596
|
-
* const findLongString = Arr.find((s: string) => s.length > 5);
|
|
1597
|
-
*
|
|
1598
|
-
* const datasets = [
|
|
1599
|
-
* [1, 2, -3, 4],
|
|
1600
|
-
* [5, 6, 7, 8],
|
|
1601
|
-
* [-1, 0, 1]
|
|
1602
|
-
* ];
|
|
1603
|
-
*
|
|
1604
|
-
* const negativeNumbers = datasets.map(findNegative);
|
|
1605
|
-
* // [Optional.Some(-3), Optional.None, Optional.Some(-1)]
|
|
1606
|
-
*
|
|
1607
|
-
* // Pipe composition
|
|
1608
|
-
* const result = pipe(['short', 'medium', 'very long string'])
|
|
1609
|
-
* .map(findLongString)
|
|
1610
|
-
* .map(opt => Optional.unwrapOr(opt, 'default'))
|
|
1611
|
-
* .value; // 'very long string'
|
|
1612
|
-
*
|
|
1613
|
-
* // Complex predicate with all parameters
|
|
1614
|
-
* const findSpecial = (arr: readonly number[]) =>
|
|
1615
|
-
* Arr.find(arr, (value, index, array) => {
|
|
1616
|
-
* return value > 10 && index > 0 && index < array.length - 1;
|
|
1617
|
-
* });
|
|
1618
|
-
*
|
|
1619
|
-
* const hasMiddleSpecial = findSpecial([5, 15, 20, 3]);
|
|
1620
|
-
* // Optional.Some(15) - first value > 10 that's not at start or end
|
|
1621
|
-
*
|
|
1622
|
-
* // Safe unwrapping patterns
|
|
1623
|
-
* const maybeFound = Arr.find(numbers, x => x > 10);
|
|
1624
|
-
* const foundOrDefault = Optional.unwrapOr(maybeFound, 0); // 0 (not found)
|
|
1625
|
-
* const foundOrThrow = Optional.isSome(maybeFound)
|
|
1626
|
-
* ? maybeFound.value
|
|
1627
|
-
* : (() => { throw new Error('Not found'); })();
|
|
1628
|
-
*
|
|
1629
|
-
* // Type inference examples
|
|
1630
|
-
* expectType<typeof firstEven, Optional<number>>('=');
|
|
1631
|
-
* expectType<typeof adult, Optional<{id: number, name: string, age: number}>>('=');
|
|
1632
|
-
* expectType<typeof findNegative, (array: readonly number[]) => Optional<number>>('=');
|
|
1633
1489
|
* ```
|
|
1634
1490
|
*
|
|
1635
1491
|
* @see {@link findIndex} for finding the index instead of the element
|
|
1636
1492
|
* @see {@link indexOf} for finding elements by equality
|
|
1637
1493
|
* @see {@link Optional} for working with the returned Optional values
|
|
1638
1494
|
*/
|
|
1639
|
-
export
|
|
1640
|
-
|
|
1641
|
-
<E>(array: readonly E[], predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean): Optional<E>;
|
|
1642
|
-
<E>(predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean): (array: readonly E[]) => Optional<E>;
|
|
1643
|
-
};
|
|
1495
|
+
export function find<E>(array: readonly E[], predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean): Optional<E>;
|
|
1496
|
+
export function find<E>(predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean): (array: readonly E[]) => Optional<E>;
|
|
1644
1497
|
/**
|
|
1645
1498
|
* Safely finds the index of the first element in an array that satisfies a predicate function.
|
|
1646
1499
|
*
|
|
@@ -1746,11 +1599,8 @@ export declare namespace Arr {
|
|
|
1746
1599
|
* @see {@link lastIndexOf} for finding the last occurrence
|
|
1747
1600
|
* @see {@link Optional} for working with the returned Optional values
|
|
1748
1601
|
*/
|
|
1749
|
-
export
|
|
1750
|
-
|
|
1751
|
-
<E>(array: readonly E[], predicate: (value: E, index: SizeType.Arr) => boolean): SizeType.Arr | -1;
|
|
1752
|
-
<E>(predicate: (value: E, index: SizeType.Arr) => boolean): (array: readonly E[]) => SizeType.Arr | -1;
|
|
1753
|
-
};
|
|
1602
|
+
export function findIndex<E>(array: readonly E[], predicate: (value: E, index: SizeType.Arr) => boolean): SizeType.Arr | -1;
|
|
1603
|
+
export function findIndex<E>(predicate: (value: E, index: SizeType.Arr) => boolean): (array: readonly E[]) => SizeType.Arr | -1;
|
|
1754
1604
|
/**
|
|
1755
1605
|
* Gets the index of a value in an array.
|
|
1756
1606
|
* @param array The array to search.
|
|
@@ -1772,16 +1622,10 @@ export declare namespace Arr {
|
|
|
1772
1622
|
* console.log(Optional.unwrapOr(result2, -1)); // 1
|
|
1773
1623
|
* ```
|
|
1774
1624
|
*/
|
|
1775
|
-
export
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
};
|
|
1780
|
-
export const indexOfFrom: IndexOfFromFnOverload;
|
|
1781
|
-
type IndexOfFromFnOverload = {
|
|
1782
|
-
<E>(array: readonly E[], searchElement: E, fromIndex: SizeType.ArgArr): SizeType.Arr | -1;
|
|
1783
|
-
<E>(searchElement: E, fromIndex: SizeType.ArgArr): (array: readonly E[]) => SizeType.Arr | -1;
|
|
1784
|
-
};
|
|
1625
|
+
export function indexOf<E>(array: readonly E[], searchElement: E): SizeType.Arr | -1;
|
|
1626
|
+
export function indexOf<E>(searchElement: E): (array: readonly E[]) => SizeType.Arr | -1;
|
|
1627
|
+
export function indexOfFrom<E>(array: readonly E[], searchElement: E, fromIndex: SizeType.ArgArr): SizeType.Arr | -1;
|
|
1628
|
+
export function indexOfFrom<E>(searchElement: E, fromIndex: SizeType.ArgArr): (array: readonly E[]) => SizeType.Arr | -1;
|
|
1785
1629
|
/**
|
|
1786
1630
|
* Gets the last index of a value in an array.
|
|
1787
1631
|
* @param array The array to search.
|
|
@@ -1803,16 +1647,10 @@ export declare namespace Arr {
|
|
|
1803
1647
|
* console.log(Optional.unwrapOr(result2, -1)); // 3
|
|
1804
1648
|
* ```
|
|
1805
1649
|
*/
|
|
1806
|
-
export
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
};
|
|
1811
|
-
export const lastIndexOfFrom: LastIndexOfFromFnOverload;
|
|
1812
|
-
type LastIndexOfFromFnOverload = {
|
|
1813
|
-
<E>(array: readonly E[], searchElement: E, fromIndex: SizeType.ArgArr): SizeType.Arr | -1;
|
|
1814
|
-
<E>(searchElement: E, fromIndex: SizeType.ArgArr): (array: readonly E[]) => SizeType.Arr | -1;
|
|
1815
|
-
};
|
|
1650
|
+
export function lastIndexOf<E>(array: readonly E[], searchElement: E): SizeType.Arr | -1;
|
|
1651
|
+
export function lastIndexOf<E>(searchElement: E): (array: readonly E[]) => SizeType.Arr | -1;
|
|
1652
|
+
export function lastIndexOfFrom<E>(array: readonly E[], searchElement: E, fromIndex: SizeType.ArgArr): SizeType.Arr | -1;
|
|
1653
|
+
export function lastIndexOfFrom<E>(searchElement: E, fromIndex: SizeType.ArgArr): (array: readonly E[]) => SizeType.Arr | -1;
|
|
1816
1654
|
/**
|
|
1817
1655
|
* Applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
|
|
1818
1656
|
* This is an alias for `Array.prototype.reduce`.
|
|
@@ -1824,20 +1662,12 @@ export declare namespace Arr {
|
|
|
1824
1662
|
* @returns The single value that results from the reduction.
|
|
1825
1663
|
* @example
|
|
1826
1664
|
* ```ts
|
|
1827
|
-
* // Regular usage
|
|
1828
1665
|
* Arr.foldl([1, 2, 3], (sum, n) => sum + n, 0); // 6
|
|
1829
|
-
*
|
|
1830
|
-
* // Curried usage for pipe composition
|
|
1831
|
-
* const sumWithZero = Arr.foldl((sum: number, n: number) => sum + n, 0);
|
|
1832
|
-
* const result = pipe([1, 2, 3, 4]).map(sumWithZero).value;
|
|
1833
|
-
* console.log(result); // 10
|
|
1666
|
+
* Arr.foldl(['a', 'b', 'c'], (acc, str) => acc + str.toUpperCase(), ''); // 'ABC'
|
|
1834
1667
|
* ```
|
|
1835
1668
|
*/
|
|
1836
|
-
export
|
|
1837
|
-
|
|
1838
|
-
<E, P>(array: readonly E[], callbackfn: (previousValue: P, currentValue: E, currentIndex: SizeType.Arr) => P, initialValue: P): P;
|
|
1839
|
-
<E, P>(callbackfn: (previousValue: P, currentValue: E, currentIndex: SizeType.Arr) => P, initialValue: P): (array: readonly E[]) => P;
|
|
1840
|
-
};
|
|
1669
|
+
export function foldl<E, P>(array: readonly E[], callbackfn: (previousValue: P, currentValue: E, currentIndex: SizeType.Arr) => P, initialValue: P): P;
|
|
1670
|
+
export function foldl<E, P>(callbackfn: (previousValue: P, currentValue: E, currentIndex: SizeType.Arr) => P, initialValue: P): (array: readonly E[]) => P;
|
|
1841
1671
|
/**
|
|
1842
1672
|
* Applies a function against an accumulator and each element in the array (from right to left) to reduce it to a single value.
|
|
1843
1673
|
* This is an alias for `Array.prototype.reduceRight`.
|
|
@@ -1858,11 +1688,8 @@ export declare namespace Arr {
|
|
|
1858
1688
|
* console.log(result); // "abc"
|
|
1859
1689
|
* ```
|
|
1860
1690
|
*/
|
|
1861
|
-
export
|
|
1862
|
-
|
|
1863
|
-
<E, P>(array: readonly E[], callbackfn: (previousValue: P, currentValue: E, currentIndex: SizeType.Arr) => P, initialValue: P): P;
|
|
1864
|
-
<E, P>(callbackfn: (previousValue: P, currentValue: E, currentIndex: SizeType.Arr) => P, initialValue: P): (array: readonly E[]) => P;
|
|
1865
|
-
};
|
|
1691
|
+
export function foldr<E, P>(array: readonly E[], callbackfn: (previousValue: P, currentValue: E, currentIndex: SizeType.Arr) => P, initialValue: P): P;
|
|
1692
|
+
export function foldr<E, P>(callbackfn: (previousValue: P, currentValue: E, currentIndex: SizeType.Arr) => P, initialValue: P): (array: readonly E[]) => P;
|
|
1866
1693
|
/**
|
|
1867
1694
|
* Finds the minimum value in an array.
|
|
1868
1695
|
* @template E The type of numbers in the array (must extend `number`).
|
|
@@ -1876,13 +1703,10 @@ export declare namespace Arr {
|
|
|
1876
1703
|
* Arr.min([]); // Optional.none
|
|
1877
1704
|
* ```
|
|
1878
1705
|
*/
|
|
1879
|
-
export
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
<E>(array: NonEmptyArray<E>, comparator: (x: E, y: E) => number): Optional.Some<E>;
|
|
1884
|
-
<E>(array: readonly E[], comparator: (x: E, y: E) => number): Optional<E>;
|
|
1885
|
-
};
|
|
1706
|
+
export function min<E extends number>(array: NonEmptyArray<E>, comparator?: (x: E, y: E) => number): Optional.Some<E>;
|
|
1707
|
+
export function min<E extends number>(array: readonly E[], comparator?: (x: E, y: E) => number): Optional<E>;
|
|
1708
|
+
export function min<E>(array: NonEmptyArray<E>, comparator: (x: E, y: E) => number): Optional.Some<E>;
|
|
1709
|
+
export function min<E>(array: readonly E[], comparator: (x: E, y: E) => number): Optional<E>;
|
|
1886
1710
|
/**
|
|
1887
1711
|
* Finds the maximum value in an array.
|
|
1888
1712
|
*
|
|
@@ -1901,13 +1725,10 @@ export declare namespace Arr {
|
|
|
1901
1725
|
* Arr.max([]); // Optional.none
|
|
1902
1726
|
* ```
|
|
1903
1727
|
*/
|
|
1904
|
-
export
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
<E>(array: NonEmptyArray<E>, comparator: (x: E, y: E) => number): Optional.Some<E>;
|
|
1909
|
-
<E>(array: readonly E[], comparator: (x: E, y: E) => number): Optional<E>;
|
|
1910
|
-
};
|
|
1728
|
+
export function max<E extends number>(array: NonEmptyArray<E>, comparator?: (x: E, y: E) => number): Optional.Some<E>;
|
|
1729
|
+
export function max<E extends number>(array: readonly E[], comparator?: (x: E, y: E) => number): Optional<E>;
|
|
1730
|
+
export function max<E>(array: NonEmptyArray<E>, comparator: (x: E, y: E) => number): Optional.Some<E>;
|
|
1731
|
+
export function max<E>(array: readonly E[], comparator: (x: E, y: E) => number): Optional<E>;
|
|
1911
1732
|
/**
|
|
1912
1733
|
* Finds the element with the minimum value according to a mapped numeric value.
|
|
1913
1734
|
*
|
|
@@ -1928,13 +1749,10 @@ export declare namespace Arr {
|
|
|
1928
1749
|
* Arr.minBy([], p => p.age); // Optional.none
|
|
1929
1750
|
* ```
|
|
1930
1751
|
*/
|
|
1931
|
-
export
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
<E, V>(array: NonEmptyArray<E>, comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): Optional.Some<E>;
|
|
1936
|
-
<E, V>(array: readonly E[], comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): Optional<E>;
|
|
1937
|
-
};
|
|
1752
|
+
export function minBy<E>(array: NonEmptyArray<E>, comparatorValueMapper: (value: E) => number): Optional.Some<E>;
|
|
1753
|
+
export function minBy<E>(array: readonly E[], comparatorValueMapper: (value: E) => number): Optional<E>;
|
|
1754
|
+
export function minBy<E, V>(array: NonEmptyArray<E>, comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): Optional.Some<E>;
|
|
1755
|
+
export function minBy<E, V>(array: readonly E[], comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): Optional<E>;
|
|
1938
1756
|
/**
|
|
1939
1757
|
* Finds the element with the maximum value according to a mapped numeric value.
|
|
1940
1758
|
*
|
|
@@ -1955,13 +1773,10 @@ export declare namespace Arr {
|
|
|
1955
1773
|
* Arr.maxBy([], p => p.age); // Optional.none
|
|
1956
1774
|
* ```
|
|
1957
1775
|
*/
|
|
1958
|
-
export
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
<E, V>(array: NonEmptyArray<E>, comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): Optional.Some<E>;
|
|
1963
|
-
<E, V>(array: readonly E[], comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): Optional<E>;
|
|
1964
|
-
};
|
|
1776
|
+
export function maxBy<E>(array: NonEmptyArray<E>, comparatorValueMapper: (value: E) => number): Optional.Some<E>;
|
|
1777
|
+
export function maxBy<E>(array: readonly E[], comparatorValueMapper: (value: E) => number): Optional<E>;
|
|
1778
|
+
export function maxBy<E, V>(array: NonEmptyArray<E>, comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): Optional.Some<E>;
|
|
1779
|
+
export function maxBy<E, V>(array: readonly E[], comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): Optional<E>;
|
|
1965
1780
|
/**
|
|
1966
1781
|
* Counts the number of elements in an array that satisfy a predicate.
|
|
1967
1782
|
* @template E The type of elements in the array.
|
|
@@ -1979,11 +1794,8 @@ export declare namespace Arr {
|
|
|
1979
1794
|
* console.log(result); // 3
|
|
1980
1795
|
* ```
|
|
1981
1796
|
*/
|
|
1982
|
-
export
|
|
1983
|
-
|
|
1984
|
-
<E>(array: readonly E[], predicate: (value: E, index: SizeType.Arr) => boolean): SizeType.Arr;
|
|
1985
|
-
<E>(predicate: (value: E, index: SizeType.Arr) => boolean): (array: readonly E[]) => SizeType.Arr;
|
|
1986
|
-
};
|
|
1797
|
+
export function count<E>(array: readonly E[], predicate: (value: E, index: SizeType.Arr) => boolean): SizeType.Arr;
|
|
1798
|
+
export function count<E>(predicate: (value: E, index: SizeType.Arr) => boolean): (array: readonly E[]) => SizeType.Arr;
|
|
1987
1799
|
/**
|
|
1988
1800
|
* Groups elements of an array by a key derived from each element and counts the elements in each group.
|
|
1989
1801
|
* @template E The type of elements in the array.
|
|
@@ -2004,11 +1816,8 @@ export declare namespace Arr {
|
|
|
2004
1816
|
* // IMap { 'a' => 2, 'b' => 1 }
|
|
2005
1817
|
* ```
|
|
2006
1818
|
*/
|
|
2007
|
-
export
|
|
2008
|
-
|
|
2009
|
-
<E, G extends MapSetKeyType>(array: readonly E[], grouper: (value: E, index: SizeType.Arr) => G): IMap<G, SizeType.Arr>;
|
|
2010
|
-
<E, G extends MapSetKeyType>(grouper: (value: E, index: SizeType.Arr) => G): (array: readonly E[]) => IMap<G, SizeType.Arr>;
|
|
2011
|
-
};
|
|
1819
|
+
export function countBy<E, G extends MapSetKeyType>(array: readonly E[], grouper: (value: E, index: SizeType.Arr) => G): IMap<G, SizeType.Arr>;
|
|
1820
|
+
export function countBy<E, G extends MapSetKeyType>(grouper: (value: E, index: SizeType.Arr) => G): (array: readonly E[]) => IMap<G, SizeType.Arr>;
|
|
2012
1821
|
/**
|
|
2013
1822
|
* Calculates the sum of numbers in an array.
|
|
2014
1823
|
* @param array The input array of numbers.
|
|
@@ -2020,14 +1829,11 @@ export declare namespace Arr {
|
|
|
2020
1829
|
* Arr.sum([-1, 0, 1]); // 0
|
|
2021
1830
|
* ```
|
|
2022
1831
|
*/
|
|
2023
|
-
export
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
(array: readonly Int[]): Int;
|
|
2029
|
-
(array: readonly number[]): number;
|
|
2030
|
-
};
|
|
1832
|
+
export function sum(array: readonly []): 0;
|
|
1833
|
+
export function sum<N extends number>(array: readonly [N]): N;
|
|
1834
|
+
export function sum(array: readonly Uint[]): Uint;
|
|
1835
|
+
export function sum(array: readonly Int[]): Int;
|
|
1836
|
+
export function sum(array: readonly number[]): number;
|
|
2031
1837
|
/**
|
|
2032
1838
|
* Joins array elements into a string.
|
|
2033
1839
|
* @param array The array to join.
|
|
@@ -2048,11 +1854,8 @@ export declare namespace Arr {
|
|
|
2048
1854
|
* console.log(Result.unwrapOr(result2, '')); // "a,b,c"
|
|
2049
1855
|
* ```
|
|
2050
1856
|
*/
|
|
2051
|
-
export
|
|
2052
|
-
|
|
2053
|
-
<E>(array: readonly E[], separator?: string): Result<string, Error>;
|
|
2054
|
-
(separator?: string): <E>(array: readonly E[]) => Result<string, Error>;
|
|
2055
|
-
};
|
|
1857
|
+
export function join<E>(array: readonly E[], separator?: string): Result<string, Error>;
|
|
1858
|
+
export function join(separator?: string): <E>(array: readonly E[]) => Result<string, Error>;
|
|
2056
1859
|
/**
|
|
2057
1860
|
* Creates an array of tuples by pairing up corresponding elements from two arrays.
|
|
2058
1861
|
* The resulting array has a length equal to the minimum of the two input array lengths.
|
|
@@ -2088,11 +1891,8 @@ export declare namespace Arr {
|
|
|
2088
1891
|
* console.log(result); // [1, 3, 5]
|
|
2089
1892
|
* ```
|
|
2090
1893
|
*/
|
|
2091
|
-
export
|
|
2092
|
-
|
|
2093
|
-
<E>(array: readonly E[], predicate: (a: E, index: SizeType.Arr) => boolean): readonly E[];
|
|
2094
|
-
<E>(predicate: (a: E, index: SizeType.Arr) => boolean): (array: readonly E[]) => readonly E[];
|
|
2095
|
-
};
|
|
1894
|
+
export function filterNot<E>(array: readonly E[], predicate: (a: E, index: SizeType.Arr) => boolean): readonly E[];
|
|
1895
|
+
export function filterNot<E>(predicate: (a: E, index: SizeType.Arr) => boolean): (array: readonly E[]) => readonly E[];
|
|
2096
1896
|
/**
|
|
2097
1897
|
* Concatenates two arrays.
|
|
2098
1898
|
* @template E1 The type of the first array (can be a tuple).
|
|
@@ -2119,20 +1919,12 @@ export declare namespace Arr {
|
|
|
2119
1919
|
* @returns An array of arrays, where each inner array has up to `chunkSize` elements.
|
|
2120
1920
|
* @example
|
|
2121
1921
|
* ```ts
|
|
2122
|
-
* // Regular usage
|
|
2123
1922
|
* Arr.partition([1, 2, 3, 4, 5, 6], 2); // [[1, 2], [3, 4], [5, 6]]
|
|
2124
|
-
*
|
|
2125
|
-
* // Curried usage for pipe composition
|
|
2126
|
-
* const chunkBy3 = Arr.partition(3);
|
|
2127
|
-
* const result = pipe([1, 2, 3, 4, 5, 6, 7]).map(chunkBy3).value;
|
|
2128
|
-
* console.log(result); // [[1, 2, 3], [4, 5, 6], [7]]
|
|
1923
|
+
* Arr.partition([1, 2, 3, 4, 5, 6, 7], 3); // [[1, 2, 3], [4, 5, 6], [7]]
|
|
2129
1924
|
* ```
|
|
2130
1925
|
*/
|
|
2131
|
-
export
|
|
2132
|
-
|
|
2133
|
-
<N extends WithSmallInt<PositiveInt & SizeType.Arr>, E>(array: readonly E[], chunkSize: N): readonly (readonly E[])[];
|
|
2134
|
-
<N extends WithSmallInt<PositiveInt & SizeType.Arr>>(chunkSize: N): <E>(array: readonly E[]) => readonly (readonly E[])[];
|
|
2135
|
-
};
|
|
1926
|
+
export function partition<N extends WithSmallInt<PositiveInt & SizeType.Arr>, E>(array: readonly E[], chunkSize: N): readonly (readonly E[])[];
|
|
1927
|
+
export function partition<N extends WithSmallInt<PositiveInt & SizeType.Arr>>(chunkSize: N): <E>(array: readonly E[]) => readonly (readonly E[])[];
|
|
2136
1928
|
/**
|
|
2137
1929
|
* Sorts an array by a value derived from its elements, using a numeric mapping.
|
|
2138
1930
|
* @template E The type of elements in the array.
|
|
@@ -2149,11 +1941,8 @@ export declare namespace Arr {
|
|
|
2149
1941
|
* // [{ name: 'Adam', score: 90 }, { name: 'Bob', score: 80 }, { name: 'Eve', score: 70 }]
|
|
2150
1942
|
* ```
|
|
2151
1943
|
*/
|
|
2152
|
-
export
|
|
2153
|
-
|
|
2154
|
-
<E>(array: readonly E[], comparatorValueMapper: (value: E) => number, comparator?: (x: number, y: number) => number): readonly E[];
|
|
2155
|
-
<E, const V>(array: readonly E[], comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): readonly E[];
|
|
2156
|
-
};
|
|
1944
|
+
export function toSortedBy<E>(array: readonly E[], comparatorValueMapper: (value: E) => number, comparator?: (x: number, y: number) => number): readonly E[];
|
|
1945
|
+
export function toSortedBy<E, const V>(array: readonly E[], comparatorValueMapper: (value: E) => V, comparator: (x: V, y: V) => number): readonly E[];
|
|
2157
1946
|
/**
|
|
2158
1947
|
* Returns an array of successively reduced values from an array, starting with an initial value.
|
|
2159
1948
|
*
|
|
@@ -2310,11 +2099,8 @@ export declare namespace Arr {
|
|
|
2310
2099
|
* @see {@link SizeType.Arr} for the index parameter type
|
|
2311
2100
|
* @see Array.prototype.reduce for the standard reduce function
|
|
2312
2101
|
*/
|
|
2313
|
-
export
|
|
2314
|
-
|
|
2315
|
-
<E, S>(array: readonly E[], reducer: (accumulator: S, currentValue: E, currentIndex: SizeType.Arr) => S, init: S): NonEmptyArray<S>;
|
|
2316
|
-
<E, S>(reducer: (accumulator: S, currentValue: E, currentIndex: SizeType.Arr) => S, init: S): (array: readonly E[]) => NonEmptyArray<S>;
|
|
2317
|
-
};
|
|
2102
|
+
export function scan<E, S>(array: readonly E[], reducer: (accumulator: S, currentValue: E, currentIndex: SizeType.Arr) => S, init: S): NonEmptyArray<S>;
|
|
2103
|
+
export function scan<E, S>(reducer: (accumulator: S, currentValue: E, currentIndex: SizeType.Arr) => S, init: S): (array: readonly E[]) => NonEmptyArray<S>;
|
|
2318
2104
|
/**
|
|
2319
2105
|
* Groups elements of an array by a key derived from each element, returning an immutable {@link IMap}.
|
|
2320
2106
|
*
|
|
@@ -2464,11 +2250,8 @@ export declare namespace Arr {
|
|
|
2464
2250
|
* @see {@link IMap.map} for transforming grouped data
|
|
2465
2251
|
* @see {@link Optional} for handling potentially missing groups
|
|
2466
2252
|
*/
|
|
2467
|
-
export
|
|
2468
|
-
|
|
2469
|
-
<E, G extends MapSetKeyType>(array: readonly E[], grouper: (value: E, index: SizeType.Arr) => G): IMap<G, readonly E[]>;
|
|
2470
|
-
<E, G extends MapSetKeyType>(grouper: (value: E, index: SizeType.Arr) => G): (array: readonly E[]) => IMap<G, readonly E[]>;
|
|
2471
|
-
};
|
|
2253
|
+
export function groupBy<E, G extends MapSetKeyType>(array: readonly E[], grouper: (value: E, index: SizeType.Arr) => G): IMap<G, readonly E[]>;
|
|
2254
|
+
export function groupBy<E, G extends MapSetKeyType>(grouper: (value: E, index: SizeType.Arr) => G): (array: readonly E[]) => IMap<G, readonly E[]>;
|
|
2472
2255
|
/**
|
|
2473
2256
|
* Creates a new array with unique elements from the input array. Order is preserved from the first occurrence.
|
|
2474
2257
|
* Uses `Set` internally for efficient uniqueness checking.
|
|
@@ -2478,7 +2261,6 @@ export declare namespace Arr {
|
|
|
2478
2261
|
* @example
|
|
2479
2262
|
* ```ts
|
|
2480
2263
|
* Arr.uniq([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]
|
|
2481
|
-
* Arr.uniq(['a', 'b', 'a']); // ['a', 'b']
|
|
2482
2264
|
* ```
|
|
2483
2265
|
*/
|
|
2484
2266
|
export const uniq: <P extends Primitive>(array: readonly P[]) => readonly P[];
|
|
@@ -2503,11 +2285,8 @@ export declare namespace Arr {
|
|
|
2503
2285
|
* Arr.uniqBy(users, user => user.id); // [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
|
|
2504
2286
|
* ```
|
|
2505
2287
|
*/
|
|
2506
|
-
export
|
|
2507
|
-
|
|
2508
|
-
<E, P extends Primitive>(array: NonEmptyArray<E>, mapFn: (value: E) => P): NonEmptyArray<E>;
|
|
2509
|
-
<E, P extends Primitive>(array: readonly E[], mapFn: (value: E) => P): readonly E[];
|
|
2510
|
-
};
|
|
2288
|
+
export function uniqBy<E, P extends Primitive>(array: NonEmptyArray<E>, mapFn: (value: E) => P): NonEmptyArray<E>;
|
|
2289
|
+
export function uniqBy<E, P extends Primitive>(array: readonly E[], mapFn: (value: E) => P): readonly E[];
|
|
2511
2290
|
/**
|
|
2512
2291
|
* Checks if two arrays are equal by performing a shallow comparison of their elements.
|
|
2513
2292
|
* @template E The type of elements in the arrays.
|
|
@@ -2618,7 +2397,7 @@ export declare namespace Arr {
|
|
|
2618
2397
|
* Alias for `head`. Returns the first element of an array.
|
|
2619
2398
|
* @see {@link head}
|
|
2620
2399
|
*/
|
|
2621
|
-
export const first:
|
|
2400
|
+
export const first: typeof head;
|
|
2622
2401
|
/**
|
|
2623
2402
|
* Alias for `tail`. Returns all elements of an array except the first one.
|
|
2624
2403
|
* @see {@link tail}
|
|
@@ -2628,22 +2407,22 @@ export declare namespace Arr {
|
|
|
2628
2407
|
* Alias for `skip`. Skips the first N elements of an array.
|
|
2629
2408
|
* @see {@link skip}
|
|
2630
2409
|
*/
|
|
2631
|
-
export const drop:
|
|
2410
|
+
export const drop: typeof skip;
|
|
2632
2411
|
/**
|
|
2633
2412
|
* Alias for `foldl`. Applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
|
|
2634
2413
|
* @see {@link foldl}
|
|
2635
2414
|
*/
|
|
2636
|
-
export const reduce:
|
|
2415
|
+
export const reduce: typeof foldl;
|
|
2637
2416
|
/**
|
|
2638
2417
|
* Alias for `foldr`. Applies a function against an accumulator and each element in the array (from right to left) to reduce it to a single value.
|
|
2639
2418
|
* @see {@link foldr}
|
|
2640
2419
|
*/
|
|
2641
|
-
export const reduceRight:
|
|
2420
|
+
export const reduceRight: typeof foldr;
|
|
2642
2421
|
/**
|
|
2643
2422
|
* Alias for `partition`. Splits an array into chunks of a specified size.
|
|
2644
2423
|
* @see {@link partition}
|
|
2645
2424
|
*/
|
|
2646
|
-
export const chunk:
|
|
2425
|
+
export const chunk: typeof partition;
|
|
2647
2426
|
export {};
|
|
2648
2427
|
}
|
|
2649
2428
|
//# sourceMappingURL=array-utils.d.mts.map
|