ts-data-forge 14.10.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/replace-equal-deep.d.mts +9 -9
- package/dist/others/replace-equal-deep.mjs +12 -12
- package/dist/others/replace-equal-deep.mjs.map +1 -1
- 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/replace-equal-deep.mts +37 -37
- package/src/others/replace-equal-deep.test.mts +13 -7
- package/src/string/str.mts +2 -2
|
@@ -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,
|
|
@@ -70,38 +70,6 @@ export function find<E>(
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
const findImpl = <E,>(
|
|
74
|
-
array: readonly E[],
|
|
75
|
-
predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean,
|
|
76
|
-
): Optional<E> => {
|
|
77
|
-
const foundIndex = array.findIndex(
|
|
78
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
79
|
-
predicate as () => boolean,
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// Left as a comment rather than asserted. This pinned the shape of the
|
|
83
|
-
// standard library's `findIndex`, and the shape differs between the stock
|
|
84
|
-
// library and the strict one — `(value, index, obj: this) => boolean` there
|
|
85
|
-
// against `(value, index, arr: readonly E[]) => unknown` here. `src` ships
|
|
86
|
-
// to consumers so that "Go to Definition" reaches it, so an assertion that
|
|
87
|
-
// only holds under one of them shows up as an error in their editor.
|
|
88
|
-
//
|
|
89
|
-
// expectType<
|
|
90
|
-
// Parameters<typeof array.findIndex>[0],
|
|
91
|
-
// (value: E, index: number, arr: readonly E[]) => unknown
|
|
92
|
-
// >('=');
|
|
93
|
-
|
|
94
|
-
expectType<
|
|
95
|
-
typeof predicate,
|
|
96
|
-
(value: E, index: SizeType.Arr, arr: readonly E[]) => boolean
|
|
97
|
-
>('=');
|
|
98
|
-
|
|
99
|
-
return foundIndex === -1
|
|
100
|
-
? Optional.none
|
|
101
|
-
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
102
|
-
Optional.some(array[foundIndex]!);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
73
|
/**
|
|
106
74
|
* Finds the last element that satisfies a predicate.
|
|
107
75
|
*
|
|
@@ -160,38 +128,6 @@ export function findLast<E>(
|
|
|
160
128
|
}
|
|
161
129
|
}
|
|
162
130
|
|
|
163
|
-
const findLastImpl = <E,>(
|
|
164
|
-
array: readonly E[],
|
|
165
|
-
predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean,
|
|
166
|
-
): Optional<E> => {
|
|
167
|
-
const foundIndex = array.findLastIndex(
|
|
168
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
169
|
-
predicate as () => boolean,
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
// Left as a comment rather than asserted. This pinned the shape of the
|
|
173
|
-
// standard library's `findIndex`, and the shape differs between the stock
|
|
174
|
-
// library and the strict one — `(value, index, obj: this) => boolean` there
|
|
175
|
-
// against `(value, index, arr: readonly E[]) => unknown` here. `src` ships
|
|
176
|
-
// to consumers so that "Go to Definition" reaches it, so an assertion that
|
|
177
|
-
// only holds under one of them shows up as an error in their editor.
|
|
178
|
-
//
|
|
179
|
-
// expectType<
|
|
180
|
-
// Parameters<typeof array.findIndex>[0],
|
|
181
|
-
// (value: E, index: number, arr: readonly E[]) => unknown
|
|
182
|
-
// >('=');
|
|
183
|
-
|
|
184
|
-
expectType<
|
|
185
|
-
typeof predicate,
|
|
186
|
-
(value: E, index: SizeType.Arr, arr: readonly E[]) => boolean
|
|
187
|
-
>('=');
|
|
188
|
-
|
|
189
|
-
return foundIndex === -1
|
|
190
|
-
? Optional.none
|
|
191
|
-
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
192
|
-
Optional.some(array[foundIndex]!);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
131
|
/**
|
|
196
132
|
* Finds the index of the first element that satisfies a predicate.
|
|
197
133
|
*
|
|
@@ -247,17 +183,6 @@ export function findIndex<E>(
|
|
|
247
183
|
}
|
|
248
184
|
}
|
|
249
185
|
|
|
250
|
-
const findIndexImpl = <E,>(
|
|
251
|
-
array: readonly E[],
|
|
252
|
-
predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean,
|
|
253
|
-
): SizeType.Arr | -1 =>
|
|
254
|
-
pipe(
|
|
255
|
-
array.findIndex(
|
|
256
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
257
|
-
predicate as (value: E, index: number) => boolean,
|
|
258
|
-
),
|
|
259
|
-
).map((idx) => (idx >= 0 ? asUint32(idx) : -1)).value;
|
|
260
|
-
|
|
261
186
|
/**
|
|
262
187
|
* Finds the index of the last element that satisfies a predicate.
|
|
263
188
|
*
|
|
@@ -313,17 +238,6 @@ export function findLastIndex<E>(
|
|
|
313
238
|
}
|
|
314
239
|
}
|
|
315
240
|
|
|
316
|
-
const findLastIndexImpl = <E,>(
|
|
317
|
-
array: readonly E[],
|
|
318
|
-
predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean,
|
|
319
|
-
): SizeType.Arr | -1 =>
|
|
320
|
-
pipe(
|
|
321
|
-
array.findLastIndex(
|
|
322
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
323
|
-
predicate as (value: E, index: number) => boolean,
|
|
324
|
-
),
|
|
325
|
-
).map((idx) => (idx >= 0 ? asUint32(idx) : -1)).value;
|
|
326
|
-
|
|
327
241
|
/**
|
|
328
242
|
* Gets the index of a value in an array.
|
|
329
243
|
*
|
|
@@ -371,15 +285,6 @@ export function indexOf<E>(
|
|
|
371
285
|
}
|
|
372
286
|
}
|
|
373
287
|
|
|
374
|
-
const indexOfImpl = <E,>(
|
|
375
|
-
array: readonly E[],
|
|
376
|
-
searchElement: E,
|
|
377
|
-
): SizeType.Arr | -1 => {
|
|
378
|
-
const index = array.indexOf(searchElement);
|
|
379
|
-
|
|
380
|
-
return index !== -1 ? asUint32(index) : -1;
|
|
381
|
-
};
|
|
382
|
-
|
|
383
288
|
/**
|
|
384
289
|
* Gets the index of a value in an array, starting from a specified index.
|
|
385
290
|
*
|
|
@@ -440,16 +345,6 @@ export function indexOfFrom<E>(
|
|
|
440
345
|
}
|
|
441
346
|
}
|
|
442
347
|
|
|
443
|
-
const indexOfFromImpl = <E,>(
|
|
444
|
-
array: readonly E[],
|
|
445
|
-
searchElement: E,
|
|
446
|
-
fromIndex: SizeType.ArgArrWithNegative,
|
|
447
|
-
): SizeType.Arr | -1 => {
|
|
448
|
-
const index = array.indexOf(searchElement, fromIndex);
|
|
449
|
-
|
|
450
|
-
return index !== -1 ? asUint32(index) : -1;
|
|
451
|
-
};
|
|
452
|
-
|
|
453
348
|
/**
|
|
454
349
|
* Gets the last index of a value in an array.
|
|
455
350
|
*
|
|
@@ -501,15 +396,6 @@ export function lastIndexOf<E>(
|
|
|
501
396
|
}
|
|
502
397
|
}
|
|
503
398
|
|
|
504
|
-
const lastIndexOfImpl = <E,>(
|
|
505
|
-
array: readonly E[],
|
|
506
|
-
searchElement: E,
|
|
507
|
-
): SizeType.Arr | -1 => {
|
|
508
|
-
const index = array.lastIndexOf(searchElement);
|
|
509
|
-
|
|
510
|
-
return index !== -1 ? asUint32(index) : -1;
|
|
511
|
-
};
|
|
512
|
-
|
|
513
399
|
/**
|
|
514
400
|
* Gets the last index of a value in an array, starting from a specified index.
|
|
515
401
|
*
|
|
@@ -570,6 +456,120 @@ export function lastIndexOfFrom<E>(
|
|
|
570
456
|
}
|
|
571
457
|
}
|
|
572
458
|
|
|
459
|
+
const findImpl = <E,>(
|
|
460
|
+
array: readonly E[],
|
|
461
|
+
predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean,
|
|
462
|
+
): Optional<E> => {
|
|
463
|
+
const foundIndex = array.findIndex(
|
|
464
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
465
|
+
predicate as () => boolean,
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
// Left as a comment rather than asserted. This pinned the shape of the
|
|
469
|
+
// standard library's `findIndex`, and the shape differs between the stock
|
|
470
|
+
// library and the strict one — `(value, index, obj: this) => boolean` there
|
|
471
|
+
// against `(value, index, arr: readonly E[]) => unknown` here. `src` ships to
|
|
472
|
+
// consumers so that "Go to Definition" reaches it, so an assertion that only
|
|
473
|
+
// holds under one of them shows up as an error in their editor.
|
|
474
|
+
//
|
|
475
|
+
// expectType<
|
|
476
|
+
// Parameters<typeof array.findIndex>[0],
|
|
477
|
+
// (value: E, index: number, arr: readonly E[]) => unknown
|
|
478
|
+
// >('=');
|
|
479
|
+
|
|
480
|
+
expectType<
|
|
481
|
+
typeof predicate,
|
|
482
|
+
(value: E, index: SizeType.Arr, arr: readonly E[]) => boolean
|
|
483
|
+
>('=');
|
|
484
|
+
|
|
485
|
+
return foundIndex === -1
|
|
486
|
+
? Optional.none
|
|
487
|
+
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
488
|
+
Optional.some(array[foundIndex]!);
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const findLastImpl = <E,>(
|
|
492
|
+
array: readonly E[],
|
|
493
|
+
predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean,
|
|
494
|
+
): Optional<E> => {
|
|
495
|
+
const foundIndex = array.findLastIndex(
|
|
496
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
497
|
+
predicate as () => boolean,
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
// Left as a comment rather than asserted. This pinned the shape of the
|
|
501
|
+
// standard library's `findIndex`, and the shape differs between the stock
|
|
502
|
+
// library and the strict one — `(value, index, obj: this) => boolean` there
|
|
503
|
+
// against `(value, index, arr: readonly E[]) => unknown` here. `src` ships to
|
|
504
|
+
// consumers so that "Go to Definition" reaches it, so an assertion that only
|
|
505
|
+
// holds under one of them shows up as an error in their editor.
|
|
506
|
+
//
|
|
507
|
+
// expectType<
|
|
508
|
+
// Parameters<typeof array.findIndex>[0],
|
|
509
|
+
// (value: E, index: number, arr: readonly E[]) => unknown
|
|
510
|
+
// >('=');
|
|
511
|
+
|
|
512
|
+
expectType<
|
|
513
|
+
typeof predicate,
|
|
514
|
+
(value: E, index: SizeType.Arr, arr: readonly E[]) => boolean
|
|
515
|
+
>('=');
|
|
516
|
+
|
|
517
|
+
return foundIndex === -1
|
|
518
|
+
? Optional.none
|
|
519
|
+
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
520
|
+
Optional.some(array[foundIndex]!);
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
const findIndexImpl = <E,>(
|
|
524
|
+
array: readonly E[],
|
|
525
|
+
predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean,
|
|
526
|
+
): SizeType.Arr | -1 =>
|
|
527
|
+
pipe(
|
|
528
|
+
array.findIndex(
|
|
529
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
530
|
+
predicate as (value: E, index: number) => boolean,
|
|
531
|
+
),
|
|
532
|
+
).map((idx) => (idx >= 0 ? asUint32(idx) : -1)).value;
|
|
533
|
+
|
|
534
|
+
const findLastIndexImpl = <E,>(
|
|
535
|
+
array: readonly E[],
|
|
536
|
+
predicate: (value: E, index: SizeType.Arr, arr: readonly E[]) => boolean,
|
|
537
|
+
): SizeType.Arr | -1 =>
|
|
538
|
+
pipe(
|
|
539
|
+
array.findLastIndex(
|
|
540
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
541
|
+
predicate as (value: E, index: number) => boolean,
|
|
542
|
+
),
|
|
543
|
+
).map((idx) => (idx >= 0 ? asUint32(idx) : -1)).value;
|
|
544
|
+
|
|
545
|
+
const indexOfImpl = <E,>(
|
|
546
|
+
array: readonly E[],
|
|
547
|
+
searchElement: E,
|
|
548
|
+
): SizeType.Arr | -1 => {
|
|
549
|
+
const index = array.indexOf(searchElement);
|
|
550
|
+
|
|
551
|
+
return index !== -1 ? asUint32(index) : -1;
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
const indexOfFromImpl = <E,>(
|
|
555
|
+
array: readonly E[],
|
|
556
|
+
searchElement: E,
|
|
557
|
+
fromIndex: SizeType.ArgArrWithNegative,
|
|
558
|
+
): SizeType.Arr | -1 => {
|
|
559
|
+
const index = array.indexOf(searchElement, fromIndex);
|
|
560
|
+
|
|
561
|
+
return index !== -1 ? asUint32(index) : -1;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
const lastIndexOfImpl = <E,>(
|
|
565
|
+
array: readonly E[],
|
|
566
|
+
searchElement: E,
|
|
567
|
+
): SizeType.Arr | -1 => {
|
|
568
|
+
const index = array.lastIndexOf(searchElement);
|
|
569
|
+
|
|
570
|
+
return index !== -1 ? asUint32(index) : -1;
|
|
571
|
+
};
|
|
572
|
+
|
|
573
573
|
const lastIndexOfFromImpl = <E,>(
|
|
574
574
|
array: readonly E[],
|
|
575
575
|
searchElement: E,
|
|
@@ -131,11 +131,6 @@ export function take<E>(
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
const takeImpl = <E,>(
|
|
135
|
-
array: readonly E[],
|
|
136
|
-
num: SizeType.ArgArr,
|
|
137
|
-
): readonly E[] => sliceClamped(array, 0, num);
|
|
138
|
-
|
|
139
134
|
/**
|
|
140
135
|
* Takes the last N elements from an array.
|
|
141
136
|
*
|
|
@@ -197,12 +192,6 @@ export function takeLast<E>(
|
|
|
197
192
|
}
|
|
198
193
|
}
|
|
199
194
|
|
|
200
|
-
const takeLastImpl = <E,>(
|
|
201
|
-
array: readonly E[],
|
|
202
|
-
num: SizeType.ArgArr,
|
|
203
|
-
): readonly E[] =>
|
|
204
|
-
sliceClamped(array, Uint32.sub(size(array), num), size(array));
|
|
205
|
-
|
|
206
195
|
/**
|
|
207
196
|
* Skips the first N elements of an array.
|
|
208
197
|
*
|
|
@@ -255,11 +244,6 @@ export function skip<E>(
|
|
|
255
244
|
}
|
|
256
245
|
}
|
|
257
246
|
|
|
258
|
-
const skipImpl = <E,>(
|
|
259
|
-
array: readonly E[],
|
|
260
|
-
num: SizeType.ArgArr,
|
|
261
|
-
): readonly E[] => sliceClamped(array, num, size(array));
|
|
262
|
-
|
|
263
247
|
/**
|
|
264
248
|
* Skips the last N elements of an array.
|
|
265
249
|
*
|
|
@@ -314,6 +298,22 @@ export function skipLast<E>(
|
|
|
314
298
|
}
|
|
315
299
|
}
|
|
316
300
|
|
|
301
|
+
const takeImpl = <E,>(
|
|
302
|
+
array: readonly E[],
|
|
303
|
+
num: SizeType.ArgArr,
|
|
304
|
+
): readonly E[] => sliceClamped(array, 0, num);
|
|
305
|
+
|
|
306
|
+
const takeLastImpl = <E,>(
|
|
307
|
+
array: readonly E[],
|
|
308
|
+
num: SizeType.ArgArr,
|
|
309
|
+
): readonly E[] =>
|
|
310
|
+
sliceClamped(array, Uint32.sub(size(array), num), size(array));
|
|
311
|
+
|
|
312
|
+
const skipImpl = <E,>(
|
|
313
|
+
array: readonly E[],
|
|
314
|
+
num: SizeType.ArgArr,
|
|
315
|
+
): readonly E[] => sliceClamped(array, num, size(array));
|
|
316
|
+
|
|
317
317
|
const skipLastImpl = <E,>(
|
|
318
318
|
array: readonly E[],
|
|
319
319
|
num: SizeType.ArgArr,
|