ts-data-forge 14.9.0 → 14.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +4 -4
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +8 -8
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +28 -28
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +4 -4
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +3 -4
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +28 -29
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +3 -3
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +1 -1
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs +15 -15
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +12 -12
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +56 -56
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +3 -3
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +25 -25
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +22 -22
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +2 -2
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.d.mts +2 -2
- package/dist/collections/imap.d.mts +3 -4
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +0 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +1 -2
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +4 -5
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +0 -1
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/number/num.d.mts +2 -2
- package/dist/number/num.mjs.map +1 -1
- package/dist/object/object.d.mts +2 -2
- package/dist/others/fast-deep-equal.d.mts.map +1 -1
- package/dist/others/fast-deep-equal.mjs +10 -7
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/dist/others/index.d.mts +1 -0
- package/dist/others/index.d.mts.map +1 -1
- package/dist/others/index.mjs +1 -0
- package/dist/others/index.mjs.map +1 -1
- package/dist/others/replace-equal-deep.d.mts +95 -0
- package/dist/others/replace-equal-deep.d.mts.map +1 -0
- package/dist/others/replace-equal-deep.mjs +156 -0
- package/dist/others/replace-equal-deep.mjs.map +1 -0
- package/dist/string/str.d.mts +2 -2
- package/package.json +12 -12
- package/src/array/impl/array-utils-element-access.mts +11 -11
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +69 -69
- package/src/array/impl/array-utils-length-bounded-array-guard.mts +21 -21
- package/src/array/impl/array-utils-length-bounded-array-guard.test.mts +2 -2
- package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +64 -65
- package/src/array/impl/array-utils-length-bounded-tuple-guard.mts +15 -15
- package/src/array/impl/array-utils-modification.mts +54 -54
- package/src/array/impl/array-utils-reducing-value.mts +55 -55
- package/src/array/impl/array-utils-search.mts +114 -114
- package/src/array/impl/array-utils-slicing.mts +16 -16
- package/src/array/impl/array-utils-transformation.mts +96 -96
- package/src/array/impl/array-utils-transformation.test.mts +2 -2
- package/src/array/impl/array-utils-validation.mts +19 -19
- package/src/array/impl/array-utils-validation.test.mts +1 -1
- package/src/collections/imap-mapped.mts +2 -2
- package/src/collections/imap.mts +3 -4
- package/src/collections/imap.test.mts +1 -1
- package/src/collections/iset-mapped.mts +1 -2
- package/src/collections/iset.mts +4 -5
- package/src/collections/iset.test.mts +1 -1
- package/src/number/num.mts +10 -10
- package/src/object/object.mts +2 -2
- package/src/others/fast-deep-equal.mts +17 -10
- package/src/others/fast-deep-equal.test.mts +141 -29
- package/src/others/index.mts +1 -0
- package/src/others/replace-equal-deep.mts +225 -0
- package/src/others/replace-equal-deep.test.mts +348 -0
- package/src/string/str.mts +2 -2
|
@@ -18,8 +18,8 @@ import {
|
|
|
18
18
|
* exactly `length` elements.
|
|
19
19
|
*
|
|
20
20
|
* This is the structural counterpart of `asFixedLengthArray`: it produces a
|
|
21
|
-
* tuple type rather than the branded `FixedLengthArray`. Prefer the branded
|
|
22
|
-
*
|
|
21
|
+
* tuple type rather than the branded `FixedLengthArray`. Prefer the branded one
|
|
22
|
+
* unless you specifically need the structural type — the brand keeps
|
|
23
23
|
* type-checking cost independent of the element type and of the bound.
|
|
24
24
|
*
|
|
25
25
|
* The length argument comes first, matching the type-parameter order of
|
|
@@ -76,21 +76,6 @@ export function asFixedLengthTuple(
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const asFixedLengthTupleImpl = (
|
|
80
|
-
length: SizeType.ArgArr,
|
|
81
|
-
xs: readonly unknown[],
|
|
82
|
-
): readonly unknown[] => {
|
|
83
|
-
const actualLength = xs.length;
|
|
84
|
-
|
|
85
|
-
if (!isFixedLengthTuple(length, xs)) {
|
|
86
|
-
throw new TypeError(
|
|
87
|
-
`Expected an array of length ${length}, got an array of length ${actualLength}`,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return xs;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
79
|
/**
|
|
95
80
|
* Casts an array to `MinLengthTuple<MinLength, E>` after checking that it has
|
|
96
81
|
* at least `minLength` elements.
|
|
@@ -148,21 +133,6 @@ export function asMinLengthTuple(
|
|
|
148
133
|
}
|
|
149
134
|
}
|
|
150
135
|
|
|
151
|
-
const asMinLengthTupleImpl = (
|
|
152
|
-
minLength: SizeType.ArgArr,
|
|
153
|
-
xs: readonly unknown[],
|
|
154
|
-
): readonly unknown[] => {
|
|
155
|
-
const actualLength = xs.length;
|
|
156
|
-
|
|
157
|
-
if (!isMinLengthTuple(minLength, xs)) {
|
|
158
|
-
throw new TypeError(
|
|
159
|
-
`Expected an array of length >= ${minLength}, got an array of length ${actualLength}`,
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return xs;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
136
|
/**
|
|
167
137
|
* Casts an array to `MaxLengthTuple<MaxLength, E>` after checking that it has
|
|
168
138
|
* at most `maxLength` elements.
|
|
@@ -218,21 +188,6 @@ export function asMaxLengthTuple(
|
|
|
218
188
|
}
|
|
219
189
|
}
|
|
220
190
|
|
|
221
|
-
const asMaxLengthTupleImpl = (
|
|
222
|
-
maxLength: SizeType.ArgArr,
|
|
223
|
-
xs: readonly unknown[],
|
|
224
|
-
): readonly unknown[] => {
|
|
225
|
-
const actualLength = xs.length;
|
|
226
|
-
|
|
227
|
-
if (!isMaxLengthTuple(maxLength, xs)) {
|
|
228
|
-
throw new TypeError(
|
|
229
|
-
`Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`,
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return xs;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
191
|
/**
|
|
237
192
|
* Casts an array to `BoundedLengthTuple<Min, Max, E>` after checking that its
|
|
238
193
|
* length is within the inclusive range `[min, max]`.
|
|
@@ -299,25 +254,8 @@ export function asBoundedLengthTuple(
|
|
|
299
254
|
}
|
|
300
255
|
}
|
|
301
256
|
|
|
302
|
-
const asBoundedLengthTupleImpl = (
|
|
303
|
-
min: SizeType.ArgArr,
|
|
304
|
-
max: SizeType.ArgArr,
|
|
305
|
-
xs: readonly unknown[],
|
|
306
|
-
): readonly unknown[] => {
|
|
307
|
-
const actualLength = xs.length;
|
|
308
|
-
|
|
309
|
-
if (!isBoundedLengthTuple(min, max, xs)) {
|
|
310
|
-
throw new TypeError(
|
|
311
|
-
`Expected an array of length in [${min}, ${max}], got an array of length ${actualLength}`,
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return xs;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
257
|
/**
|
|
319
|
-
* Casts an array to the structural empty tuple after checking that it is
|
|
320
|
-
* empty.
|
|
258
|
+
* Casts an array to the structural empty tuple after checking that it is empty.
|
|
321
259
|
*
|
|
322
260
|
* This is the structural counterpart of `asEmptyArray`, and the length-0
|
|
323
261
|
* specialization of {@link asFixedLengthTuple}.
|
|
@@ -382,3 +320,64 @@ export const asNonEmptyTuple = <Xs extends readonly unknown[]>(
|
|
|
382
320
|
|
|
383
321
|
return xs;
|
|
384
322
|
};
|
|
323
|
+
|
|
324
|
+
const asFixedLengthTupleImpl = (
|
|
325
|
+
length: SizeType.ArgArr,
|
|
326
|
+
xs: readonly unknown[],
|
|
327
|
+
): readonly unknown[] => {
|
|
328
|
+
const actualLength = xs.length;
|
|
329
|
+
|
|
330
|
+
if (!isFixedLengthTuple(length, xs)) {
|
|
331
|
+
throw new TypeError(
|
|
332
|
+
`Expected an array of length ${length}, got an array of length ${actualLength}`,
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return xs;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const asMinLengthTupleImpl = (
|
|
340
|
+
minLength: SizeType.ArgArr,
|
|
341
|
+
xs: readonly unknown[],
|
|
342
|
+
): readonly unknown[] => {
|
|
343
|
+
const actualLength = xs.length;
|
|
344
|
+
|
|
345
|
+
if (!isMinLengthTuple(minLength, xs)) {
|
|
346
|
+
throw new TypeError(
|
|
347
|
+
`Expected an array of length >= ${minLength}, got an array of length ${actualLength}`,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return xs;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const asMaxLengthTupleImpl = (
|
|
355
|
+
maxLength: SizeType.ArgArr,
|
|
356
|
+
xs: readonly unknown[],
|
|
357
|
+
): readonly unknown[] => {
|
|
358
|
+
const actualLength = xs.length;
|
|
359
|
+
|
|
360
|
+
if (!isMaxLengthTuple(maxLength, xs)) {
|
|
361
|
+
throw new TypeError(
|
|
362
|
+
`Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return xs;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const asBoundedLengthTupleImpl = (
|
|
370
|
+
min: SizeType.ArgArr,
|
|
371
|
+
max: SizeType.ArgArr,
|
|
372
|
+
xs: readonly unknown[],
|
|
373
|
+
): readonly unknown[] => {
|
|
374
|
+
const actualLength = xs.length;
|
|
375
|
+
|
|
376
|
+
if (!isBoundedLengthTuple(min, max, xs)) {
|
|
377
|
+
throw new TypeError(
|
|
378
|
+
`Expected an array of length in [${min}, ${max}], got an array of length ${actualLength}`,
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return xs;
|
|
383
|
+
};
|
|
@@ -102,11 +102,6 @@ export function isFixedLengthTuple(
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
const hasFixedLength = (
|
|
106
|
-
len: SizeType.ArgArr,
|
|
107
|
-
array: readonly unknown[],
|
|
108
|
-
): boolean => array.length === len;
|
|
109
|
-
|
|
110
105
|
/**
|
|
111
106
|
* Checks if an array has at least a specific length.
|
|
112
107
|
*
|
|
@@ -150,11 +145,6 @@ export function isMinLengthTuple(
|
|
|
150
145
|
}
|
|
151
146
|
}
|
|
152
147
|
|
|
153
|
-
const hasMinLength = (
|
|
154
|
-
len: SizeType.ArgArr,
|
|
155
|
-
array: readonly unknown[],
|
|
156
|
-
): boolean => array.length >= len;
|
|
157
|
-
|
|
158
148
|
/**
|
|
159
149
|
* Checks if an array has at most a specific length.
|
|
160
150
|
*
|
|
@@ -198,11 +188,6 @@ export function isMaxLengthTuple(
|
|
|
198
188
|
}
|
|
199
189
|
}
|
|
200
190
|
|
|
201
|
-
const hasMaxLength = (
|
|
202
|
-
len: SizeType.ArgArr,
|
|
203
|
-
array: readonly unknown[],
|
|
204
|
-
): boolean => array.length <= len;
|
|
205
|
-
|
|
206
191
|
/**
|
|
207
192
|
* Checks if an array's length is within a specific inclusive range.
|
|
208
193
|
*
|
|
@@ -259,6 +244,21 @@ export function isBoundedLengthTuple(
|
|
|
259
244
|
}
|
|
260
245
|
}
|
|
261
246
|
|
|
247
|
+
const hasFixedLength = (
|
|
248
|
+
len: SizeType.ArgArr,
|
|
249
|
+
array: readonly unknown[],
|
|
250
|
+
): boolean => array.length === len;
|
|
251
|
+
|
|
252
|
+
const hasMinLength = (
|
|
253
|
+
len: SizeType.ArgArr,
|
|
254
|
+
array: readonly unknown[],
|
|
255
|
+
): boolean => array.length >= len;
|
|
256
|
+
|
|
257
|
+
const hasMaxLength = (
|
|
258
|
+
len: SizeType.ArgArr,
|
|
259
|
+
array: readonly unknown[],
|
|
260
|
+
): boolean => array.length <= len;
|
|
261
|
+
|
|
262
262
|
const isWithinBounds = (
|
|
263
263
|
min: SizeType.ArgArr,
|
|
264
264
|
max: SizeType.ArgArr,
|
|
@@ -55,12 +55,6 @@ export function set<E, const V = E>(
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const setImpl = <E, const V = E>(
|
|
59
|
-
array: readonly E[],
|
|
60
|
-
index: SizeType.ArgArr,
|
|
61
|
-
newValue: V,
|
|
62
|
-
): readonly (E | V)[] => (array as readonly (E | V)[]).with(index, newValue);
|
|
63
|
-
|
|
64
58
|
/**
|
|
65
59
|
* Returns a new array with an element at the specified index updated by applying a function.
|
|
66
60
|
*
|
|
@@ -111,14 +105,6 @@ export function toUpdated<E, V = E>(
|
|
|
111
105
|
}
|
|
112
106
|
}
|
|
113
107
|
|
|
114
|
-
const toUpdatedImpl = <E, V = E>(
|
|
115
|
-
array: readonly E[],
|
|
116
|
-
index: SizeType.ArgArr,
|
|
117
|
-
updater: (prev: E) => V,
|
|
118
|
-
): readonly (E | V)[] =>
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
120
|
-
(array as readonly (E | V)[]).with(index, updater(array[index]!));
|
|
121
|
-
|
|
122
108
|
/**
|
|
123
109
|
* Returns a new array with a value inserted at the specified index.
|
|
124
110
|
*
|
|
@@ -175,20 +161,6 @@ export function toInserted<E, const V = E>(
|
|
|
175
161
|
}
|
|
176
162
|
}
|
|
177
163
|
|
|
178
|
-
const toInsertedImpl = <E, const V = E>(
|
|
179
|
-
array: readonly E[],
|
|
180
|
-
index: SizeType.ArgArrWithNegative,
|
|
181
|
-
newValue: V,
|
|
182
|
-
): NonEmptyArray<E | V> =>
|
|
183
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
184
|
-
(array as readonly (E | V)[]).toSpliced(
|
|
185
|
-
index,
|
|
186
|
-
0,
|
|
187
|
-
newValue,
|
|
188
|
-
) as unknown as NonEmptyArray<E | V>;
|
|
189
|
-
|
|
190
|
-
type CastToNumber<T> = T extends number ? T : never;
|
|
191
|
-
|
|
192
164
|
/**
|
|
193
165
|
* Returns a new array with the element at the specified index removed.
|
|
194
166
|
*
|
|
@@ -229,11 +201,6 @@ export function toRemoved<E>(
|
|
|
229
201
|
}
|
|
230
202
|
}
|
|
231
203
|
|
|
232
|
-
const toRemovedImpl = <E,>(
|
|
233
|
-
array: readonly E[],
|
|
234
|
-
index: SizeType.ArgArrWithNegative,
|
|
235
|
-
): readonly E[] => array.toSpliced(index, 1);
|
|
236
|
-
|
|
237
204
|
/**
|
|
238
205
|
* Returns a new array with a value appended to the end.
|
|
239
206
|
*
|
|
@@ -279,13 +246,6 @@ export function toPushed<const Ar extends readonly unknown[], const V>(
|
|
|
279
246
|
}
|
|
280
247
|
}
|
|
281
248
|
|
|
282
|
-
const toPushedImpl = <const Ar extends readonly unknown[], const V>(
|
|
283
|
-
array: Ar,
|
|
284
|
-
newValue: V,
|
|
285
|
-
): readonly [...Ar, V] =>
|
|
286
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
287
|
-
array.toSpliced(array.length, 0, newValue) as unknown as readonly [...Ar, V];
|
|
288
|
-
|
|
289
249
|
/**
|
|
290
250
|
* Returns a new array with a value prepended to the beginning.
|
|
291
251
|
*
|
|
@@ -331,13 +291,6 @@ export function toUnshifted<Ar extends readonly unknown[], const V>(
|
|
|
331
291
|
}
|
|
332
292
|
}
|
|
333
293
|
|
|
334
|
-
const toUnshiftedImpl = <Ar extends readonly unknown[], const V>(
|
|
335
|
-
array: Ar,
|
|
336
|
-
newValue: V,
|
|
337
|
-
): readonly [V, ...Ar] =>
|
|
338
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
339
|
-
array.toSpliced(0, 0, newValue) as unknown as readonly [V, ...Ar];
|
|
340
|
-
|
|
341
294
|
/**
|
|
342
295
|
* Returns a new array with all elements replaced by the specified value.
|
|
343
296
|
*
|
|
@@ -363,10 +316,10 @@ export function toFilled<
|
|
|
363
316
|
// For an array or tuple that carries no length brand the homomorphic mapping
|
|
364
317
|
// already covers every case the conditional spelled out — a fixed-length tuple
|
|
365
318
|
// keeps its length, `readonly [A, ...A[]]` stays non-empty, and `readonly A[]`
|
|
366
|
-
// stays unbounded. Stating it directly is what keeps this usable from a
|
|
367
|
-
//
|
|
368
|
-
//
|
|
369
|
-
//
|
|
319
|
+
// stays unbounded. Stating it directly is what keeps this usable from a caller
|
|
320
|
+
// that is itself generic over the array: a conditional a *generic* `Ar` cannot
|
|
321
|
+
// decide stays deferred, and its branded branch is then not assignable to the
|
|
322
|
+
// caller's own mapping.
|
|
370
323
|
export function toFilled<const Ar extends readonly unknown[], const V>(
|
|
371
324
|
array: Ar,
|
|
372
325
|
value: V,
|
|
@@ -395,9 +348,6 @@ export function toFilled<E>(
|
|
|
395
348
|
}
|
|
396
349
|
}
|
|
397
350
|
|
|
398
|
-
const toFilledImpl = <E,>(array: readonly E[], value: E): readonly E[] =>
|
|
399
|
-
create(asPositiveUint32(array.length), value);
|
|
400
|
-
|
|
401
351
|
/**
|
|
402
352
|
* Returns a new array with elements in the specified range replaced by the specified value.
|
|
403
353
|
*
|
|
@@ -479,6 +429,56 @@ export function toRangeFilled<E, const V>(
|
|
|
479
429
|
}
|
|
480
430
|
}
|
|
481
431
|
|
|
432
|
+
const setImpl = <E, const V = E>(
|
|
433
|
+
array: readonly E[],
|
|
434
|
+
index: SizeType.ArgArr,
|
|
435
|
+
newValue: V,
|
|
436
|
+
): readonly (E | V)[] => (array as readonly (E | V)[]).with(index, newValue);
|
|
437
|
+
|
|
438
|
+
const toUpdatedImpl = <E, V = E>(
|
|
439
|
+
array: readonly E[],
|
|
440
|
+
index: SizeType.ArgArr,
|
|
441
|
+
updater: (prev: E) => V,
|
|
442
|
+
): readonly (E | V)[] =>
|
|
443
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
444
|
+
(array as readonly (E | V)[]).with(index, updater(array[index]!));
|
|
445
|
+
|
|
446
|
+
const toInsertedImpl = <E, const V = E>(
|
|
447
|
+
array: readonly E[],
|
|
448
|
+
index: SizeType.ArgArrWithNegative,
|
|
449
|
+
newValue: V,
|
|
450
|
+
): NonEmptyArray<E | V> =>
|
|
451
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
452
|
+
(array as readonly (E | V)[]).toSpliced(
|
|
453
|
+
index,
|
|
454
|
+
0,
|
|
455
|
+
newValue,
|
|
456
|
+
) as unknown as NonEmptyArray<E | V>;
|
|
457
|
+
|
|
458
|
+
type CastToNumber<T> = T extends number ? T : never;
|
|
459
|
+
|
|
460
|
+
const toRemovedImpl = <E,>(
|
|
461
|
+
array: readonly E[],
|
|
462
|
+
index: SizeType.ArgArrWithNegative,
|
|
463
|
+
): readonly E[] => array.toSpliced(index, 1);
|
|
464
|
+
|
|
465
|
+
const toPushedImpl = <const Ar extends readonly unknown[], const V>(
|
|
466
|
+
array: Ar,
|
|
467
|
+
newValue: V,
|
|
468
|
+
): readonly [...Ar, V] =>
|
|
469
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
470
|
+
array.toSpliced(array.length, 0, newValue) as unknown as readonly [...Ar, V];
|
|
471
|
+
|
|
472
|
+
const toUnshiftedImpl = <Ar extends readonly unknown[], const V>(
|
|
473
|
+
array: Ar,
|
|
474
|
+
newValue: V,
|
|
475
|
+
): readonly [V, ...Ar] =>
|
|
476
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
477
|
+
array.toSpliced(0, 0, newValue) as unknown as readonly [V, ...Ar];
|
|
478
|
+
|
|
479
|
+
const toFilledImpl = <E,>(array: readonly E[], value: E): readonly E[] =>
|
|
480
|
+
create(asPositiveUint32(array.length), value);
|
|
481
|
+
|
|
482
482
|
const toRangeFilledImpl = <E, const V>(
|
|
483
483
|
array: readonly E[],
|
|
484
484
|
value: V,
|
|
@@ -247,16 +247,6 @@ export function count<E>(
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
const countImpl = <E,>(
|
|
251
|
-
array: readonly E[],
|
|
252
|
-
predicate: (value: E, index: SizeType.Arr) => boolean,
|
|
253
|
-
): SizeType.Arr =>
|
|
254
|
-
array.reduce<Uint32>(
|
|
255
|
-
(acc, curr, index) =>
|
|
256
|
-
predicate(curr, asUint32(index)) ? Uint32.add(acc, 1) : acc,
|
|
257
|
-
asUint32(0),
|
|
258
|
-
);
|
|
259
|
-
|
|
260
250
|
/**
|
|
261
251
|
* Groups elements by a key and counts the elements in each group.
|
|
262
252
|
*
|
|
@@ -303,23 +293,6 @@ export function countBy<E, G extends MapSetKeyType>(
|
|
|
303
293
|
}
|
|
304
294
|
}
|
|
305
295
|
|
|
306
|
-
const countByImpl = <E, G extends MapSetKeyType>(
|
|
307
|
-
array: readonly E[],
|
|
308
|
-
grouper: (value: E, index: SizeType.Arr) => G,
|
|
309
|
-
): IMap<G, SizeType.Arr> => {
|
|
310
|
-
const mut_groups = new Map<G, SizeType.Arr>();
|
|
311
|
-
|
|
312
|
-
for (const [index, e] of array.entries()) {
|
|
313
|
-
const key = grouper(e, asUint32(index));
|
|
314
|
-
|
|
315
|
-
const curr = mut_groups.get(key) ?? 0;
|
|
316
|
-
|
|
317
|
-
mut_groups.set(key, asUint32(curr + 1));
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return IMap.create(mut_groups);
|
|
321
|
-
};
|
|
322
|
-
|
|
323
296
|
/**
|
|
324
297
|
* Reduces an array to a single value from left to right.
|
|
325
298
|
*
|
|
@@ -388,20 +361,6 @@ export function foldl<E, P>(
|
|
|
388
361
|
}
|
|
389
362
|
}
|
|
390
363
|
|
|
391
|
-
const foldlImpl = <E, P>(
|
|
392
|
-
array: readonly E[],
|
|
393
|
-
callbackfn: (
|
|
394
|
-
previousValue: P,
|
|
395
|
-
currentValue: E,
|
|
396
|
-
currentIndex: SizeType.Arr,
|
|
397
|
-
) => P,
|
|
398
|
-
initialValue: P,
|
|
399
|
-
): P =>
|
|
400
|
-
array.reduce(
|
|
401
|
-
(prev, curr, index) => callbackfn(prev, curr, asUint32(index)),
|
|
402
|
-
initialValue,
|
|
403
|
-
);
|
|
404
|
-
|
|
405
364
|
/**
|
|
406
365
|
* Reduces an array to a single value from right to left.
|
|
407
366
|
*
|
|
@@ -470,20 +429,6 @@ export function foldr<E, P>(
|
|
|
470
429
|
}
|
|
471
430
|
}
|
|
472
431
|
|
|
473
|
-
const foldrImpl = <E, P>(
|
|
474
|
-
array: readonly E[],
|
|
475
|
-
callbackfn: (
|
|
476
|
-
previousValue: P,
|
|
477
|
-
currentValue: E,
|
|
478
|
-
currentIndex: SizeType.Arr,
|
|
479
|
-
) => P,
|
|
480
|
-
initialValue: P,
|
|
481
|
-
): P =>
|
|
482
|
-
array.reduceRight(
|
|
483
|
-
(prev, curr, index) => callbackfn(prev, curr, asUint32(index)),
|
|
484
|
-
initialValue,
|
|
485
|
-
);
|
|
486
|
-
|
|
487
432
|
/**
|
|
488
433
|
* Calculates the sum of numbers in an array.
|
|
489
434
|
*
|
|
@@ -618,6 +563,61 @@ export function join(
|
|
|
618
563
|
}
|
|
619
564
|
}
|
|
620
565
|
|
|
566
|
+
const countImpl = <E,>(
|
|
567
|
+
array: readonly E[],
|
|
568
|
+
predicate: (value: E, index: SizeType.Arr) => boolean,
|
|
569
|
+
): SizeType.Arr =>
|
|
570
|
+
array.reduce<Uint32>(
|
|
571
|
+
(acc, curr, index) =>
|
|
572
|
+
predicate(curr, asUint32(index)) ? Uint32.add(acc, 1) : acc,
|
|
573
|
+
asUint32(0),
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
const countByImpl = <E, G extends MapSetKeyType>(
|
|
577
|
+
array: readonly E[],
|
|
578
|
+
grouper: (value: E, index: SizeType.Arr) => G,
|
|
579
|
+
): IMap<G, SizeType.Arr> => {
|
|
580
|
+
const mut_groups = new Map<G, SizeType.Arr>();
|
|
581
|
+
|
|
582
|
+
for (const [index, e] of array.entries()) {
|
|
583
|
+
const key = grouper(e, asUint32(index));
|
|
584
|
+
|
|
585
|
+
const curr = mut_groups.get(key) ?? 0;
|
|
586
|
+
|
|
587
|
+
mut_groups.set(key, asUint32(curr + 1));
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return IMap.create(mut_groups);
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
const foldlImpl = <E, P>(
|
|
594
|
+
array: readonly E[],
|
|
595
|
+
callbackfn: (
|
|
596
|
+
previousValue: P,
|
|
597
|
+
currentValue: E,
|
|
598
|
+
currentIndex: SizeType.Arr,
|
|
599
|
+
) => P,
|
|
600
|
+
initialValue: P,
|
|
601
|
+
): P =>
|
|
602
|
+
array.reduce(
|
|
603
|
+
(prev, curr, index) => callbackfn(prev, curr, asUint32(index)),
|
|
604
|
+
initialValue,
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
const foldrImpl = <E, P>(
|
|
608
|
+
array: readonly E[],
|
|
609
|
+
callbackfn: (
|
|
610
|
+
previousValue: P,
|
|
611
|
+
currentValue: E,
|
|
612
|
+
currentIndex: SizeType.Arr,
|
|
613
|
+
) => P,
|
|
614
|
+
initialValue: P,
|
|
615
|
+
): P =>
|
|
616
|
+
array.reduceRight(
|
|
617
|
+
(prev, curr, index) => callbackfn(prev, curr, asUint32(index)),
|
|
618
|
+
initialValue,
|
|
619
|
+
);
|
|
620
|
+
|
|
621
621
|
const joinImpl = (
|
|
622
622
|
array: readonly unknown[],
|
|
623
623
|
separator: string | undefined,
|