ts-data-forge 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entry-point.mjs +2 -0
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functional/index.d.mts +1 -0
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +2 -0
- package/dist/functional/index.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/index.d.mts +29 -0
- package/dist/functional/ternary-result/impl/index.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/index.mjs +28 -0
- package/dist/functional/ternary-result/impl/index.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/tag.d.mts +7 -0
- package/dist/functional/ternary-result/impl/tag.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/tag.mjs +9 -0
- package/dist/functional/ternary-result/impl/tag.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +14 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +41 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +27 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +20 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +33 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts +20 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +28 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +35 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +16 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +19 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +16 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +25 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +13 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +19 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +32 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +48 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/types.d.mts +25 -0
- package/dist/functional/ternary-result/impl/types.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/types.mjs +2 -0
- package/dist/functional/ternary-result/impl/types.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/variant-name.d.mts +3 -0
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/variant-name.mjs +16 -0
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -0
- package/dist/functional/ternary-result/index.d.mts +2 -0
- package/dist/functional/ternary-result/index.d.mts.map +1 -0
- package/dist/functional/ternary-result/index.mjs +3 -0
- package/dist/functional/ternary-result/index.mjs.map +1 -0
- package/dist/globals.d.mts +55 -2
- package/dist/json/json.d.mts +9 -3
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +6 -0
- package/dist/json/json.mjs.map +1 -1
- package/package.json +13 -13
- package/src/array/impl/array-utils-creation.test.mts +187 -74
- package/src/array/impl/array-utils-element-access.test.mts +19 -3
- package/src/array/impl/array-utils-iterators.test.mts +44 -24
- package/src/array/impl/array-utils-modification.test.mts +36 -33
- package/src/array/impl/array-utils-reducing-value.test.mts +47 -16
- package/src/array/impl/array-utils-search.test.mts +42 -9
- package/src/array/impl/array-utils-set-op.test.mts +54 -26
- package/src/array/impl/array-utils-size.test.mts +1 -0
- package/src/array/impl/array-utils-slice-clamped.test.mts +20 -11
- package/src/array/impl/array-utils-slicing.test.mts +27 -21
- package/src/array/impl/array-utils-transformation.test.mts +140 -92
- package/src/array/impl/array-utils-validation.test.mts +58 -10
- package/src/array/impl/array.test.mts +5 -5
- package/src/collections/imap-mapped.test.mts +63 -18
- package/src/collections/imap.test.mts +74 -26
- package/src/collections/iset-mapped.test.mts +81 -30
- package/src/collections/iset.test.mts +168 -68
- package/src/collections/queue.test.mts +32 -1
- package/src/collections/stack.test.mts +22 -8
- package/src/functional/index.mts +1 -0
- package/src/functional/match.test.mts +1 -1
- package/src/functional/optional.test.mts +61 -4
- package/src/functional/pipe.test.mts +10 -1
- package/src/functional/result.test.mts +127 -4
- package/src/functional/ternary-result/impl/index.mts +28 -0
- package/src/functional/ternary-result/impl/tag.mts +11 -0
- package/src/functional/ternary-result/impl/ternary-result-err.mts +18 -0
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +53 -0
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +95 -0
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +93 -0
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +27 -0
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +31 -0
- package/src/functional/ternary-result/impl/ternary-result-is-err.mts +23 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +24 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +27 -0
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +24 -0
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +64 -0
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +66 -0
- package/src/functional/ternary-result/impl/ternary-result-map.mts +81 -0
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +20 -0
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +66 -0
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +25 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +40 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +22 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +32 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +42 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +38 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +22 -0
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +23 -0
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +53 -0
- package/src/functional/ternary-result/impl/types.mts +39 -0
- package/src/functional/ternary-result/impl/variant-name.mts +17 -0
- package/src/functional/ternary-result/index.mts +1 -0
- package/src/functional/ternary-result.test.mts +214 -0
- package/src/globals.d.mts +55 -2
- package/src/guard/is-non-empty-string.test.mts +5 -2
- package/src/guard/is-non-null-object.test.mts +3 -5
- package/src/guard/is-primitive.test.mts +5 -3
- package/src/guard/is-record.test.mts +1 -1
- package/src/guard/is-type.test.mts +35 -20
- package/src/guard/key-is-in.test.mts +1 -1
- package/src/iterator/range.test.mts +22 -16
- package/src/json/json.mts +9 -3
- package/src/json/json.test.mts +140 -64
- package/src/number/branded-types/finite-number.test.mts +3 -2
- package/src/number/branded-types/int.test.mts +4 -3
- package/src/number/branded-types/int16.test.mts +9 -3
- package/src/number/branded-types/int32.test.mts +9 -3
- package/src/number/branded-types/non-negative-finite-number.test.mts +6 -4
- package/src/number/branded-types/non-negative-int16.test.mts +8 -3
- package/src/number/branded-types/non-negative-int32.test.mts +8 -3
- package/src/number/branded-types/non-zero-finite-number.test.mts +6 -3
- package/src/number/branded-types/non-zero-int.test.mts +6 -3
- package/src/number/branded-types/non-zero-int16.test.mts +9 -3
- package/src/number/branded-types/non-zero-int32.test.mts +9 -3
- package/src/number/branded-types/non-zero-safe-int.test.mts +10 -3
- package/src/number/branded-types/non-zero-uint16.test.mts +8 -3
- package/src/number/branded-types/non-zero-uint32.test.mts +8 -3
- package/src/number/branded-types/positive-finite-number.test.mts +7 -3
- package/src/number/branded-types/positive-int.test.mts +5 -3
- package/src/number/branded-types/positive-int16.test.mts +8 -3
- package/src/number/branded-types/positive-int32.test.mts +8 -3
- package/src/number/branded-types/positive-safe-int.test.mts +8 -3
- package/src/number/branded-types/positive-uint16.test.mts +8 -3
- package/src/number/branded-types/positive-uint32.test.mts +8 -3
- package/src/number/branded-types/safe-int.test.mts +8 -2
- package/src/number/branded-types/safe-uint.test.mts +8 -3
- package/src/number/branded-types/uint.test.mts +5 -3
- package/src/number/branded-types/uint16.test.mts +8 -3
- package/src/number/branded-types/uint32.test.mts +8 -3
- package/src/number/enum/int8.test.mts +8 -3
- package/src/number/enum/uint8.test.mts +6 -3
- package/src/number/num.test.mts +16 -2
- package/src/object/object.test.mts +26 -13
- package/src/others/cast-mutable.test.mts +10 -8
- package/src/others/cast-readonly.test.mts +9 -5
- package/src/others/if-then.test.mts +4 -1
- package/src/others/map-nullable.test.mts +28 -1
- package/src/others/memoize-function.test.mts +20 -17
- package/src/others/tuple.test.mts +3 -2
- package/src/others/unknown-to-string.test.mts +15 -2
- package/src/promise/promise.test.mts +6 -1
|
@@ -21,27 +21,29 @@ import {
|
|
|
21
21
|
} from './array-utils-transformation.mjs';
|
|
22
22
|
|
|
23
23
|
describe('Arr transformations', () => {
|
|
24
|
-
describe(
|
|
24
|
+
describe(map, () => {
|
|
25
25
|
const mapped = map([1, 2, 3], (x, i): number => x * x * i);
|
|
26
26
|
|
|
27
27
|
expectType<typeof mapped, ArrayOfLength<3, number>>('=');
|
|
28
28
|
|
|
29
29
|
test('case 1', () => {
|
|
30
|
-
|
|
30
|
+
assert.deepStrictEqual(mapped, [0, 4, 18]);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test('should work with empty tuple', () => {
|
|
34
34
|
const empty = [] as const;
|
|
35
35
|
const mappedEmpty = map(empty, (x) => String(x));
|
|
36
36
|
expectType<typeof mappedEmpty, readonly []>('=');
|
|
37
|
-
|
|
37
|
+
|
|
38
|
+
assert.deepStrictEqual(mappedEmpty, []);
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
test('should preserve tuple length with different types', () => {
|
|
41
42
|
const mixed = [1, 'hello', true] as const;
|
|
42
43
|
const mappedMixed = map(mixed, (x) => typeof x);
|
|
43
44
|
expectType<typeof mappedMixed, readonly [string, string, string]>('<=');
|
|
44
|
-
|
|
45
|
+
|
|
46
|
+
assert.deepStrictEqual(mappedMixed, ['number', 'string', 'boolean']);
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
test('should work with index parameter', () => {
|
|
@@ -50,24 +52,27 @@ describe('Arr transformations', () => {
|
|
|
50
52
|
expectType<typeof mappedWithIndex, readonly [string, string, string]>(
|
|
51
53
|
'<=',
|
|
52
54
|
);
|
|
53
|
-
|
|
55
|
+
|
|
56
|
+
assert.deepStrictEqual(mappedWithIndex, ['0:a', '1:b', '2:c']);
|
|
54
57
|
});
|
|
55
58
|
});
|
|
56
59
|
|
|
57
|
-
describe(
|
|
60
|
+
describe(scan, () => {
|
|
58
61
|
test('should compute running sum', () => {
|
|
59
62
|
const numbers = [1, 2, 3, 4];
|
|
60
63
|
const runningSum = scan(numbers, (acc, curr) => acc + curr, 0);
|
|
61
64
|
|
|
62
65
|
expectType<typeof runningSum, readonly [number, ...number[]]>('<=');
|
|
63
|
-
|
|
66
|
+
|
|
67
|
+
assert.deepStrictEqual(runningSum, [0, 1, 3, 6, 10]);
|
|
64
68
|
});
|
|
65
69
|
|
|
66
70
|
test('should include initial value as first element', () => {
|
|
67
71
|
const numbers = [10, 20, 30];
|
|
68
72
|
const result = scan(numbers, (acc, curr) => acc + curr, 100);
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
assert.deepStrictEqual(result, [100, 110, 130, 160]);
|
|
75
|
+
|
|
71
76
|
expect(result).toHaveLength(4); // original length + 1
|
|
72
77
|
});
|
|
73
78
|
|
|
@@ -77,8 +82,8 @@ describe('Arr transformations', () => {
|
|
|
77
82
|
const result1 = scanSum([1, 2, 3]);
|
|
78
83
|
const result2 = scanSum([5, 10]);
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
assert.deepStrictEqual(result1, [0, 1, 3, 6]);
|
|
86
|
+
assert.deepStrictEqual(result2, [0, 5, 15]);
|
|
82
87
|
});
|
|
83
88
|
|
|
84
89
|
test('should provide index to reducer', () => {
|
|
@@ -94,14 +99,14 @@ describe('Arr transformations', () => {
|
|
|
94
99
|
0,
|
|
95
100
|
);
|
|
96
101
|
|
|
97
|
-
|
|
102
|
+
assert.deepStrictEqual(mut_indices, [0, 1, 2]);
|
|
98
103
|
});
|
|
99
104
|
|
|
100
105
|
test('should work with empty array', () => {
|
|
101
106
|
const empty: readonly number[] = [];
|
|
102
107
|
const result = scan(empty, (acc, curr) => acc + curr, 42);
|
|
103
108
|
|
|
104
|
-
|
|
109
|
+
assert.deepStrictEqual(result, [42]);
|
|
105
110
|
});
|
|
106
111
|
|
|
107
112
|
test('should work with different accumulator and element types', () => {
|
|
@@ -109,14 +114,15 @@ describe('Arr transformations', () => {
|
|
|
109
114
|
const result = scan(strings, (acc, curr) => acc + curr.length, 0);
|
|
110
115
|
|
|
111
116
|
expectType<typeof result, readonly [number, ...number[]]>('<=');
|
|
112
|
-
|
|
117
|
+
|
|
118
|
+
assert.deepStrictEqual(result, [0, 1, 2, 3]);
|
|
113
119
|
});
|
|
114
120
|
|
|
115
121
|
test('should compute running product', () => {
|
|
116
122
|
const numbers = [2, 3, 4];
|
|
117
123
|
const runningProduct = scan(numbers, (acc, curr) => acc * curr, 1);
|
|
118
124
|
|
|
119
|
-
|
|
125
|
+
assert.deepStrictEqual(runningProduct, [1, 2, 6, 24]);
|
|
120
126
|
});
|
|
121
127
|
|
|
122
128
|
test('should work with objects', () => {
|
|
@@ -124,7 +130,7 @@ describe('Arr transformations', () => {
|
|
|
124
130
|
|
|
125
131
|
const result = scan(items, (acc, curr) => acc + curr.value, 0);
|
|
126
132
|
|
|
127
|
-
|
|
133
|
+
assert.deepStrictEqual(result, [0, 10, 30, 60]);
|
|
128
134
|
});
|
|
129
135
|
|
|
130
136
|
test('should preserve all intermediate values', () => {
|
|
@@ -132,11 +138,11 @@ describe('Arr transformations', () => {
|
|
|
132
138
|
const result = scan(numbers, (acc, curr) => acc - curr, 10);
|
|
133
139
|
|
|
134
140
|
// 10 -> 10-1=9 -> 9-2=7 -> 7-3=4
|
|
135
|
-
|
|
141
|
+
assert.deepStrictEqual(result, [10, 9, 7, 4]);
|
|
136
142
|
});
|
|
137
143
|
});
|
|
138
144
|
|
|
139
|
-
describe(
|
|
145
|
+
describe(toReversed, () => {
|
|
140
146
|
{
|
|
141
147
|
const xs = [1, 2, 3] as const;
|
|
142
148
|
const _nativeResult = xs.toReversed();
|
|
@@ -148,7 +154,7 @@ describe('Arr transformations', () => {
|
|
|
148
154
|
expectType<typeof result, readonly [3, 2, 1]>('=');
|
|
149
155
|
|
|
150
156
|
test('case 1', () => {
|
|
151
|
-
|
|
157
|
+
assert.deepStrictEqual(result, [3, 2, 1]);
|
|
152
158
|
});
|
|
153
159
|
}
|
|
154
160
|
|
|
@@ -156,25 +162,28 @@ describe('Arr transformations', () => {
|
|
|
156
162
|
const empty = [] as const;
|
|
157
163
|
const reversed = toReversed(empty);
|
|
158
164
|
expectType<typeof reversed, readonly []>('=');
|
|
159
|
-
|
|
165
|
+
|
|
166
|
+
assert.deepStrictEqual(reversed, []);
|
|
160
167
|
});
|
|
161
168
|
|
|
162
169
|
test('should work with single element', () => {
|
|
163
170
|
const single = [42] as const;
|
|
164
171
|
const reversed = toReversed(single);
|
|
165
172
|
expectType<typeof reversed, readonly [42]>('=');
|
|
166
|
-
|
|
173
|
+
|
|
174
|
+
assert.deepStrictEqual(reversed, [42]);
|
|
167
175
|
});
|
|
168
176
|
|
|
169
177
|
test('should preserve mixed types in reverse order', () => {
|
|
170
178
|
const mixed = [1, 'hello', true, null] as const;
|
|
171
179
|
const reversed = toReversed(mixed);
|
|
172
180
|
expectType<typeof reversed, readonly [null, true, 'hello', 1]>('=');
|
|
173
|
-
|
|
181
|
+
|
|
182
|
+
assert.deepStrictEqual(reversed, [null, true, 'hello', 1]);
|
|
174
183
|
});
|
|
175
184
|
});
|
|
176
185
|
|
|
177
|
-
describe(
|
|
186
|
+
describe(toSorted, () => {
|
|
178
187
|
{
|
|
179
188
|
const xs = [2, 1, 3] as const;
|
|
180
189
|
const result = toSorted(xs);
|
|
@@ -182,7 +191,7 @@ describe('Arr transformations', () => {
|
|
|
182
191
|
expectType<typeof result, ArrayOfLength<3, 1 | 2 | 3>>('=');
|
|
183
192
|
|
|
184
193
|
test('case 1', () => {
|
|
185
|
-
|
|
194
|
+
assert.deepStrictEqual(result, [1, 2, 3]);
|
|
186
195
|
});
|
|
187
196
|
}
|
|
188
197
|
{
|
|
@@ -192,7 +201,7 @@ describe('Arr transformations', () => {
|
|
|
192
201
|
expectType<typeof result, ArrayOfLength<3, 1 | 2 | 3>>('=');
|
|
193
202
|
|
|
194
203
|
test('case 2', () => {
|
|
195
|
-
|
|
204
|
+
assert.deepStrictEqual(result, [1, 2, 3]);
|
|
196
205
|
});
|
|
197
206
|
}
|
|
198
207
|
{
|
|
@@ -202,12 +211,12 @@ describe('Arr transformations', () => {
|
|
|
202
211
|
expectType<typeof result, ArrayOfLength<3, 1 | 2 | 3>>('=');
|
|
203
212
|
|
|
204
213
|
test('case 3', () => {
|
|
205
|
-
|
|
214
|
+
assert.deepStrictEqual(result, [3, 2, 1]);
|
|
206
215
|
});
|
|
207
216
|
}
|
|
208
217
|
});
|
|
209
218
|
|
|
210
|
-
describe(
|
|
219
|
+
describe(toSortedBy, () => {
|
|
211
220
|
{
|
|
212
221
|
const xs = [{ v: 2 }, { v: 1 }, { v: 3 }] as const;
|
|
213
222
|
const sorted = toSortedBy(xs, (x) => x.v);
|
|
@@ -218,7 +227,7 @@ describe('Arr transformations', () => {
|
|
|
218
227
|
>('=');
|
|
219
228
|
|
|
220
229
|
test('case 1', () => {
|
|
221
|
-
|
|
230
|
+
assert.deepStrictEqual(sorted, [{ v: 1 }, { v: 2 }, { v: 3 }]);
|
|
222
231
|
});
|
|
223
232
|
}
|
|
224
233
|
{
|
|
@@ -235,7 +244,7 @@ describe('Arr transformations', () => {
|
|
|
235
244
|
>('=');
|
|
236
245
|
|
|
237
246
|
test('case 2', () => {
|
|
238
|
-
|
|
247
|
+
assert.deepStrictEqual(sorted, [{ v: 1 }, { v: 2 }, { v: 3 }]);
|
|
239
248
|
});
|
|
240
249
|
}
|
|
241
250
|
|
|
@@ -260,33 +269,38 @@ describe('Arr transformations', () => {
|
|
|
260
269
|
(word: string) => word,
|
|
261
270
|
(a: string, b: string) => a.localeCompare(b),
|
|
262
271
|
);
|
|
263
|
-
|
|
272
|
+
|
|
273
|
+
assert.deepStrictEqual(result, ['apple', 'banana', 'cherry']);
|
|
264
274
|
});
|
|
265
275
|
|
|
266
276
|
test('should work with custom key extraction', () => {
|
|
267
277
|
const items = ['hello', 'hi', 'welcome', 'bye'];
|
|
268
278
|
const result = toSortedBy(items, (item) => item.length);
|
|
269
|
-
|
|
279
|
+
|
|
280
|
+
assert.deepStrictEqual(result, ['hi', 'bye', 'hello', 'welcome']);
|
|
270
281
|
});
|
|
271
282
|
|
|
272
283
|
test('should work with empty array', () => {
|
|
273
284
|
const empty: readonly { value: number }[] = [];
|
|
274
285
|
const result = toSortedBy(empty, (item) => item.value);
|
|
275
|
-
|
|
286
|
+
|
|
287
|
+
assert.deepStrictEqual(result, []);
|
|
276
288
|
});
|
|
277
289
|
|
|
278
290
|
test('toSortedBy should work with empty array', () => {
|
|
279
291
|
const empty: readonly { value: number }[] = [];
|
|
280
292
|
const result = toSortedBy(empty, (item) => item.value);
|
|
281
|
-
|
|
293
|
+
|
|
294
|
+
assert.deepStrictEqual(result, []);
|
|
282
295
|
});
|
|
283
296
|
});
|
|
284
297
|
|
|
285
|
-
describe(
|
|
298
|
+
describe(filter, () => {
|
|
286
299
|
test('should filter array with predicate', () => {
|
|
287
300
|
const numbers = [1, 2, 3, 4, 5];
|
|
288
301
|
const evens = filter(numbers, (n) => n % 2 === 0);
|
|
289
|
-
|
|
302
|
+
|
|
303
|
+
assert.deepStrictEqual(evens, [2, 4]);
|
|
290
304
|
});
|
|
291
305
|
|
|
292
306
|
test('should work with type guards', () => {
|
|
@@ -299,14 +313,16 @@ describe('Arr transformations', () => {
|
|
|
299
313
|
];
|
|
300
314
|
const strings = filter(mixed, (x): x is string => typeof x === 'string');
|
|
301
315
|
expectType<typeof strings, readonly string[]>('=');
|
|
302
|
-
|
|
316
|
+
|
|
317
|
+
assert.deepStrictEqual(strings, ['hello', 'world']);
|
|
303
318
|
});
|
|
304
319
|
|
|
305
320
|
test('should work with curried version', () => {
|
|
306
321
|
const isPositive = (n: number): boolean => n > 0;
|
|
307
322
|
const filterPositive = filter(isPositive);
|
|
308
323
|
const result = filterPositive([-1, 2, -3, 4]);
|
|
309
|
-
|
|
324
|
+
|
|
325
|
+
assert.deepStrictEqual(result, [2, 4]);
|
|
310
326
|
});
|
|
311
327
|
|
|
312
328
|
test('should work with curried type guards', () => {
|
|
@@ -314,67 +330,75 @@ describe('Arr transformations', () => {
|
|
|
314
330
|
const filterStrings = filter(isString);
|
|
315
331
|
const result = filterStrings(['a', 1, 'b', 2]);
|
|
316
332
|
expectType<typeof result, readonly string[]>('=');
|
|
317
|
-
|
|
333
|
+
|
|
334
|
+
assert.deepStrictEqual(result, ['a', 'b']);
|
|
318
335
|
});
|
|
319
336
|
|
|
320
337
|
test('should preserve array type with generic predicate', () => {
|
|
321
338
|
const tuple = [1, 2, 3] as const;
|
|
322
339
|
const filtered = filter(tuple, (x) => x > 1);
|
|
323
340
|
expectType<typeof filtered, readonly (1 | 2 | 3)[]>('=');
|
|
324
|
-
|
|
341
|
+
|
|
342
|
+
assert.deepStrictEqual(filtered, [2, 3]);
|
|
325
343
|
});
|
|
326
344
|
|
|
327
345
|
test('should work with empty array', () => {
|
|
328
346
|
const empty: number[] = [];
|
|
329
347
|
const result = filter(empty, (n) => n > 0);
|
|
330
|
-
|
|
348
|
+
|
|
349
|
+
assert.deepStrictEqual(result, []);
|
|
331
350
|
});
|
|
332
351
|
|
|
333
352
|
test('should pass index to predicate', () => {
|
|
334
353
|
const numbers = [10, 20, 30, 40];
|
|
335
354
|
const evenIndexes = filter(numbers, (_, i) => i % 2 === 0);
|
|
336
|
-
|
|
355
|
+
|
|
356
|
+
assert.deepStrictEqual(evenIndexes, [10, 30]);
|
|
337
357
|
});
|
|
338
358
|
});
|
|
339
359
|
|
|
340
|
-
describe(
|
|
360
|
+
describe(filterNot, () => {
|
|
341
361
|
const xs = [1, 2, 3] as const;
|
|
342
362
|
const filtered = filterNot(xs, (x) => x % 2 === 0);
|
|
343
363
|
|
|
344
364
|
expectType<typeof filtered, readonly (1 | 2 | 3)[]>('=');
|
|
345
365
|
|
|
346
366
|
test('case 1', () => {
|
|
347
|
-
|
|
367
|
+
assert.deepStrictEqual(filtered, [1, 3]);
|
|
348
368
|
});
|
|
349
369
|
});
|
|
350
370
|
|
|
351
|
-
describe(
|
|
371
|
+
describe(uniq, () => {
|
|
352
372
|
test('should remove duplicate primitives', () => {
|
|
353
373
|
const array = [1, 2, 2, 3, 1, 4, 3];
|
|
354
374
|
const result = uniq(array);
|
|
355
|
-
|
|
375
|
+
|
|
376
|
+
assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
356
377
|
});
|
|
357
378
|
|
|
358
379
|
test('should work with strings', () => {
|
|
359
380
|
const array = ['a', 'b', 'a', 'c', 'b'];
|
|
360
381
|
const result = uniq(array);
|
|
361
|
-
|
|
382
|
+
|
|
383
|
+
assert.deepStrictEqual(result, ['a', 'b', 'c']);
|
|
362
384
|
});
|
|
363
385
|
|
|
364
386
|
test('should work with empty array', () => {
|
|
365
387
|
const array: readonly number[] = [];
|
|
366
388
|
const result = uniq(array);
|
|
367
|
-
|
|
389
|
+
|
|
390
|
+
assert.deepStrictEqual(result, []);
|
|
368
391
|
});
|
|
369
392
|
|
|
370
393
|
test('should preserve order of first occurrence', () => {
|
|
371
394
|
const array = [3, 1, 2, 1, 3, 2];
|
|
372
395
|
const result = uniq(array);
|
|
373
|
-
|
|
396
|
+
|
|
397
|
+
assert.deepStrictEqual(result, [3, 1, 2]);
|
|
374
398
|
});
|
|
375
399
|
});
|
|
376
400
|
|
|
377
|
-
describe(
|
|
401
|
+
describe(uniqBy, () => {
|
|
378
402
|
test('should remove duplicates based on key function', () => {
|
|
379
403
|
const array = [
|
|
380
404
|
{ id: 1, name: 'Alice' },
|
|
@@ -385,9 +409,10 @@ describe('Arr transformations', () => {
|
|
|
385
409
|
const result = uniqBy(array, (item) => item.id);
|
|
386
410
|
|
|
387
411
|
expect(result).toHaveLength(3);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
412
|
+
|
|
413
|
+
assert.deepStrictEqual(result[0], { id: 1, name: 'Alice' });
|
|
414
|
+
assert.deepStrictEqual(result[1], { id: 2, name: 'Bob' });
|
|
415
|
+
assert.deepStrictEqual(result[2], { id: 3, name: 'Charlie' });
|
|
391
416
|
});
|
|
392
417
|
|
|
393
418
|
test('should work with string key function', () => {
|
|
@@ -403,11 +428,12 @@ describe('Arr transformations', () => {
|
|
|
403
428
|
test('should work with empty array', () => {
|
|
404
429
|
const empty: readonly { id: number }[] = [];
|
|
405
430
|
const result = uniqBy(empty, (item) => item.id);
|
|
406
|
-
|
|
431
|
+
|
|
432
|
+
assert.deepStrictEqual(result, []);
|
|
407
433
|
});
|
|
408
434
|
});
|
|
409
435
|
|
|
410
|
-
describe(
|
|
436
|
+
describe(flat, () => {
|
|
411
437
|
test('should flatten nested arrays with default depth 1', () => {
|
|
412
438
|
const nested = [
|
|
413
439
|
[1, 2],
|
|
@@ -415,15 +441,17 @@ describe('Arr transformations', () => {
|
|
|
415
441
|
[5, 6],
|
|
416
442
|
];
|
|
417
443
|
const flattened = flat(nested);
|
|
418
|
-
|
|
444
|
+
|
|
445
|
+
assert.deepStrictEqual(flattened, [1, 2, 3, 4, 5, 6]);
|
|
419
446
|
});
|
|
420
447
|
|
|
421
448
|
test('should flatten with specified depth', () => {
|
|
422
449
|
const deepNested = [1, [2, [3, 4]], 5];
|
|
423
450
|
const flat1 = flat(deepNested, 1);
|
|
424
451
|
const flat2 = flat(deepNested, 2);
|
|
425
|
-
|
|
426
|
-
|
|
452
|
+
|
|
453
|
+
assert.deepStrictEqual(flat1, [1, 2, [3, 4], 5]);
|
|
454
|
+
assert.deepStrictEqual(flat2, [1, 2, 3, 4, 5]);
|
|
427
455
|
});
|
|
428
456
|
|
|
429
457
|
test('should work with curried version', () => {
|
|
@@ -432,13 +460,15 @@ describe('Arr transformations', () => {
|
|
|
432
460
|
[1, 2],
|
|
433
461
|
[3, 4],
|
|
434
462
|
]);
|
|
435
|
-
|
|
463
|
+
|
|
464
|
+
assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
436
465
|
});
|
|
437
466
|
|
|
438
467
|
test('should work with empty arrays', () => {
|
|
439
468
|
const withEmpties = [[1], [], [2, 3]];
|
|
440
469
|
const flattened = flat(withEmpties);
|
|
441
|
-
|
|
470
|
+
|
|
471
|
+
assert.deepStrictEqual(flattened, [1, 2, 3]);
|
|
442
472
|
});
|
|
443
473
|
|
|
444
474
|
test('should work with depth 0', () => {
|
|
@@ -447,7 +477,8 @@ describe('Arr transformations', () => {
|
|
|
447
477
|
[3, 4],
|
|
448
478
|
];
|
|
449
479
|
const unflattened = flat(nested, 0);
|
|
450
|
-
|
|
480
|
+
|
|
481
|
+
assert.deepStrictEqual(unflattened, [
|
|
451
482
|
[1, 2],
|
|
452
483
|
[3, 4],
|
|
453
484
|
]);
|
|
@@ -456,15 +487,17 @@ describe('Arr transformations', () => {
|
|
|
456
487
|
test('should work with infinite depth', () => {
|
|
457
488
|
const veryDeep = [1, [2, [3, [4, [5]]]]];
|
|
458
489
|
const allFlat = flat(veryDeep, SafeUint.MAX_VALUE);
|
|
459
|
-
|
|
490
|
+
|
|
491
|
+
assert.deepStrictEqual(allFlat, [1, 2, 3, 4, 5]);
|
|
460
492
|
});
|
|
461
493
|
});
|
|
462
494
|
|
|
463
|
-
describe(
|
|
495
|
+
describe(flatMap, () => {
|
|
464
496
|
test('should map and flatten results', () => {
|
|
465
497
|
const words = ['hello', 'world'];
|
|
466
498
|
const chars = flatMap(words, (word) => word.split(''));
|
|
467
|
-
|
|
499
|
+
|
|
500
|
+
assert.deepStrictEqual(chars, [
|
|
468
501
|
'h',
|
|
469
502
|
'e',
|
|
470
503
|
'l',
|
|
@@ -481,41 +514,47 @@ describe('Arr transformations', () => {
|
|
|
481
514
|
test('should work with curried version', () => {
|
|
482
515
|
const splitWords = flatMap((word: string) => word.split(''));
|
|
483
516
|
const result = splitWords(['foo', 'bar']);
|
|
484
|
-
|
|
517
|
+
|
|
518
|
+
assert.deepStrictEqual(result, ['f', 'o', 'o', 'b', 'a', 'r']);
|
|
485
519
|
});
|
|
486
520
|
|
|
487
521
|
test('should work with numbers', () => {
|
|
488
522
|
const numbers = [1, 2, 3];
|
|
489
523
|
const doubled = flatMap(numbers, (n) => [n, n * 2]);
|
|
490
|
-
|
|
524
|
+
|
|
525
|
+
assert.deepStrictEqual(doubled, [1, 2, 2, 4, 3, 6]);
|
|
491
526
|
});
|
|
492
527
|
|
|
493
528
|
test('should pass index to mapping function', () => {
|
|
494
529
|
const numbers = [10, 20];
|
|
495
530
|
const result = flatMap(numbers, (n, i) => [n, i]);
|
|
496
|
-
|
|
531
|
+
|
|
532
|
+
assert.deepStrictEqual(result, [10, 0, 20, 1]);
|
|
497
533
|
});
|
|
498
534
|
|
|
499
535
|
test('should work with empty arrays', () => {
|
|
500
536
|
const empty: string[] = [];
|
|
501
537
|
const result = flatMap(empty, (s) => s.split(''));
|
|
502
|
-
|
|
538
|
+
|
|
539
|
+
assert.deepStrictEqual(result, []);
|
|
503
540
|
});
|
|
504
541
|
|
|
505
542
|
test('should handle mapping to empty arrays', () => {
|
|
506
543
|
const numbers = [1, 2, 3];
|
|
507
544
|
const result = flatMap(numbers, (n) => (n % 2 === 0 ? [n] : []));
|
|
508
|
-
|
|
545
|
+
|
|
546
|
+
assert.deepStrictEqual(result, [2]);
|
|
509
547
|
});
|
|
510
548
|
|
|
511
549
|
test('should work with tuples', () => {
|
|
512
550
|
const tuple = [1, 2] as const;
|
|
513
551
|
const result = flatMap(tuple, (n) => [n, n]);
|
|
514
|
-
|
|
552
|
+
|
|
553
|
+
assert.deepStrictEqual(result, [1, 1, 2, 2]);
|
|
515
554
|
});
|
|
516
555
|
});
|
|
517
556
|
|
|
518
|
-
describe(
|
|
557
|
+
describe(partition, () => {
|
|
519
558
|
const xs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] as const;
|
|
520
559
|
|
|
521
560
|
{
|
|
@@ -540,7 +579,7 @@ describe('Arr transformations', () => {
|
|
|
540
579
|
>('=');
|
|
541
580
|
|
|
542
581
|
test('case 1', () => {
|
|
543
|
-
|
|
582
|
+
assert.deepStrictEqual(result, [
|
|
544
583
|
[1, 2, 3, 4],
|
|
545
584
|
[5, 6, 7, 8],
|
|
546
585
|
[9, 10, 11, 12],
|
|
@@ -570,7 +609,7 @@ describe('Arr transformations', () => {
|
|
|
570
609
|
>('=');
|
|
571
610
|
|
|
572
611
|
test('case 2', () => {
|
|
573
|
-
|
|
612
|
+
assert.deepStrictEqual(result, [
|
|
574
613
|
[1, 2, 3],
|
|
575
614
|
[4, 5, 6],
|
|
576
615
|
[7, 8, 9],
|
|
@@ -601,7 +640,7 @@ describe('Arr transformations', () => {
|
|
|
601
640
|
>('=');
|
|
602
641
|
|
|
603
642
|
test('case 3', () => {
|
|
604
|
-
|
|
643
|
+
assert.deepStrictEqual(result, [
|
|
605
644
|
[1, 2, 3, 4, 5],
|
|
606
645
|
[6, 7, 8, 9, 10],
|
|
607
646
|
[11, 12],
|
|
@@ -613,7 +652,7 @@ describe('Arr transformations', () => {
|
|
|
613
652
|
const numbers = [1, 2, 3, 4, 5, 6];
|
|
614
653
|
const result = partition(numbers, 2);
|
|
615
654
|
|
|
616
|
-
|
|
655
|
+
assert.deepStrictEqual(result, [
|
|
617
656
|
[1, 2],
|
|
618
657
|
[3, 4],
|
|
619
658
|
[5, 6],
|
|
@@ -624,7 +663,7 @@ describe('Arr transformations', () => {
|
|
|
624
663
|
const numbers = [1, 2, 3, 4, 5];
|
|
625
664
|
const result = partition(numbers, 2);
|
|
626
665
|
|
|
627
|
-
|
|
666
|
+
assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]]);
|
|
628
667
|
});
|
|
629
668
|
|
|
630
669
|
test('should work with chunk size < 2 (returns empty)', () => {
|
|
@@ -632,25 +671,25 @@ describe('Arr transformations', () => {
|
|
|
632
671
|
const result = partition(numbers, 1);
|
|
633
672
|
|
|
634
673
|
// According to docs, returns empty array if chunkSize < 2
|
|
635
|
-
|
|
674
|
+
assert.deepStrictEqual(result, []);
|
|
636
675
|
});
|
|
637
676
|
|
|
638
677
|
test('should work with chunk size larger than array', () => {
|
|
639
678
|
const numbers = [1, 2];
|
|
640
679
|
const result = partition(numbers, 5);
|
|
641
680
|
|
|
642
|
-
|
|
681
|
+
assert.deepStrictEqual(result, [[1, 2]]);
|
|
643
682
|
});
|
|
644
683
|
|
|
645
684
|
test('partition should work with empty array', () => {
|
|
646
685
|
const empty: readonly number[] = [];
|
|
647
686
|
const result = partition(empty, 2);
|
|
648
687
|
|
|
649
|
-
|
|
688
|
+
assert.deepStrictEqual(result, []);
|
|
650
689
|
});
|
|
651
690
|
});
|
|
652
691
|
|
|
653
|
-
describe(
|
|
692
|
+
describe(concat, () => {
|
|
654
693
|
const xs = [1, 2, 3] as const;
|
|
655
694
|
const ys = [4, 5] as const;
|
|
656
695
|
const result = concat(xs, ys);
|
|
@@ -658,7 +697,7 @@ describe('Arr transformations', () => {
|
|
|
658
697
|
expectType<typeof result, readonly [1, 2, 3, 4, 5]>('=');
|
|
659
698
|
|
|
660
699
|
test('case 1', () => {
|
|
661
|
-
|
|
700
|
+
assert.deepStrictEqual(result, [1, 2, 3, 4, 5]);
|
|
662
701
|
});
|
|
663
702
|
|
|
664
703
|
// testArrayEquality({
|
|
@@ -692,7 +731,7 @@ describe('Arr transformations', () => {
|
|
|
692
731
|
// });
|
|
693
732
|
});
|
|
694
733
|
|
|
695
|
-
describe(
|
|
734
|
+
describe(groupBy, () => {
|
|
696
735
|
const xs = [
|
|
697
736
|
{ x: 1, y: 1 },
|
|
698
737
|
{ x: 2, y: 1 },
|
|
@@ -720,7 +759,8 @@ describe('Arr transformations', () => {
|
|
|
720
759
|
>('=');
|
|
721
760
|
|
|
722
761
|
test('case 1', () => {
|
|
723
|
-
|
|
762
|
+
assert.deepStrictEqual(
|
|
763
|
+
result,
|
|
724
764
|
IMap.create<
|
|
725
765
|
1 | 2 | 3,
|
|
726
766
|
readonly (
|
|
@@ -761,6 +801,7 @@ describe('Arr transformations', () => {
|
|
|
761
801
|
const grouped = groupBy(array, (item) => item.type);
|
|
762
802
|
|
|
763
803
|
expect(grouped.size).toBe(2);
|
|
804
|
+
|
|
764
805
|
const fruits = grouped.get('fruit');
|
|
765
806
|
const vegetables = grouped.get('vegetable');
|
|
766
807
|
|
|
@@ -784,21 +825,23 @@ describe('Arr transformations', () => {
|
|
|
784
825
|
const grouped = groupBy(numbers, (n) => n % 2);
|
|
785
826
|
|
|
786
827
|
expect(grouped.size).toBe(2);
|
|
828
|
+
|
|
787
829
|
const evens = grouped.get(0);
|
|
788
830
|
const odds = grouped.get(1);
|
|
789
831
|
|
|
790
832
|
if (Optional.isSome(evens)) {
|
|
791
|
-
|
|
833
|
+
assert.deepStrictEqual(evens.value, [2, 4, 6]);
|
|
792
834
|
}
|
|
793
835
|
|
|
794
836
|
if (Optional.isSome(odds)) {
|
|
795
|
-
|
|
837
|
+
assert.deepStrictEqual(odds.value, [1, 3, 5]);
|
|
796
838
|
}
|
|
797
839
|
});
|
|
798
840
|
|
|
799
841
|
test('should work with empty array', () => {
|
|
800
842
|
const empty: readonly number[] = [];
|
|
801
843
|
const grouped = groupBy(empty, (n) => n % 2);
|
|
844
|
+
|
|
802
845
|
expect(grouped.size).toBe(0);
|
|
803
846
|
});
|
|
804
847
|
|
|
@@ -807,15 +850,16 @@ describe('Arr transformations', () => {
|
|
|
807
850
|
const grouped = groupBy(array, () => 'all');
|
|
808
851
|
|
|
809
852
|
expect(grouped.size).toBe(1);
|
|
853
|
+
|
|
810
854
|
const all = grouped.get('all');
|
|
811
855
|
|
|
812
856
|
if (Optional.isSome(all)) {
|
|
813
|
-
|
|
857
|
+
assert.deepStrictEqual(all.value, [1, 2, 3, 4]);
|
|
814
858
|
}
|
|
815
859
|
});
|
|
816
860
|
});
|
|
817
861
|
|
|
818
|
-
describe(
|
|
862
|
+
describe(zip, () => {
|
|
819
863
|
{
|
|
820
864
|
const xs = [1, 2, 3] as const;
|
|
821
865
|
const ys = [4, 5, 6] as const;
|
|
@@ -827,7 +871,7 @@ describe('Arr transformations', () => {
|
|
|
827
871
|
>('=');
|
|
828
872
|
|
|
829
873
|
test('case 1', () => {
|
|
830
|
-
|
|
874
|
+
assert.deepStrictEqual(zipped, [
|
|
831
875
|
[1, 4],
|
|
832
876
|
[2, 5],
|
|
833
877
|
[3, 6],
|
|
@@ -842,7 +886,7 @@ describe('Arr transformations', () => {
|
|
|
842
886
|
expectType<typeof zipped, readonly (readonly [number, number])[]>('=');
|
|
843
887
|
|
|
844
888
|
test('case 2', () => {
|
|
845
|
-
|
|
889
|
+
assert.deepStrictEqual(zipped, [[1, 4]]);
|
|
846
890
|
});
|
|
847
891
|
}
|
|
848
892
|
{
|
|
@@ -853,7 +897,7 @@ describe('Arr transformations', () => {
|
|
|
853
897
|
expectType<typeof zipped, readonly [readonly [1, number]]>('=');
|
|
854
898
|
|
|
855
899
|
test('case 3', () => {
|
|
856
|
-
|
|
900
|
+
assert.deepStrictEqual(zipped, [[1, 4]]);
|
|
857
901
|
});
|
|
858
902
|
}
|
|
859
903
|
|
|
@@ -901,7 +945,8 @@ describe('Arr transformations', () => {
|
|
|
901
945
|
const arr1 = [1, 2, 3];
|
|
902
946
|
const arr2 = ['a', 'b', 'c'];
|
|
903
947
|
const result = zip(arr1, arr2);
|
|
904
|
-
|
|
948
|
+
|
|
949
|
+
assert.deepStrictEqual(result, [
|
|
905
950
|
[1, 'a'],
|
|
906
951
|
[2, 'b'],
|
|
907
952
|
[3, 'c'],
|
|
@@ -912,7 +957,8 @@ describe('Arr transformations', () => {
|
|
|
912
957
|
const arr1 = [1, 2, 3, 4];
|
|
913
958
|
const arr2 = ['a', 'b'];
|
|
914
959
|
const result = zip(arr1, arr2);
|
|
915
|
-
|
|
960
|
+
|
|
961
|
+
assert.deepStrictEqual(result, [
|
|
916
962
|
[1, 'a'],
|
|
917
963
|
[2, 'b'],
|
|
918
964
|
]);
|
|
@@ -922,14 +968,16 @@ describe('Arr transformations', () => {
|
|
|
922
968
|
const arr1: readonly number[] = [];
|
|
923
969
|
const arr2: readonly string[] = [];
|
|
924
970
|
const result = zip(arr1, arr2);
|
|
925
|
-
|
|
971
|
+
|
|
972
|
+
assert.deepStrictEqual(result, []);
|
|
926
973
|
});
|
|
927
974
|
|
|
928
975
|
test('should handle one empty array', () => {
|
|
929
976
|
const arr1 = [1, 2, 3];
|
|
930
977
|
const arr2: readonly string[] = [];
|
|
931
978
|
const result = zip(arr1, arr2);
|
|
932
|
-
|
|
979
|
+
|
|
980
|
+
assert.deepStrictEqual(result, []);
|
|
933
981
|
});
|
|
934
982
|
});
|
|
935
983
|
});
|