ts-data-forge 2.1.1 → 2.1.3

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.
Files changed (103) hide show
  1. package/README.md +13 -15
  2. package/dist/array/array-utils.d.mts.map +1 -1
  3. package/dist/array/array-utils.mjs +9 -13
  4. package/dist/array/array-utils.mjs.map +1 -1
  5. package/dist/collections/imap.d.mts +1 -1
  6. package/dist/collections/imap.d.mts.map +1 -1
  7. package/dist/collections/imap.mjs +5 -5
  8. package/dist/collections/imap.mjs.map +1 -1
  9. package/dist/collections/iset-mapped.d.mts +1 -1
  10. package/dist/collections/iset-mapped.mjs +1 -1
  11. package/dist/collections/iset.d.mts +2 -2
  12. package/dist/collections/iset.mjs +4 -5
  13. package/dist/collections/iset.mjs.map +1 -1
  14. package/dist/collections/queue.d.mts +1 -1
  15. package/dist/collections/queue.d.mts.map +1 -1
  16. package/dist/collections/queue.mjs +7 -8
  17. package/dist/collections/queue.mjs.map +1 -1
  18. package/dist/collections/stack.d.mts +1 -1
  19. package/dist/collections/stack.d.mts.map +1 -1
  20. package/dist/collections/stack.mjs +6 -7
  21. package/dist/collections/stack.mjs.map +1 -1
  22. package/dist/entry-point.d.mts.map +1 -1
  23. package/dist/functional/match.d.mts.map +1 -1
  24. package/dist/functional/match.mjs +1 -6
  25. package/dist/functional/match.mjs.map +1 -1
  26. package/dist/functional/optional.d.mts.map +1 -1
  27. package/dist/functional/optional.mjs +6 -4
  28. package/dist/functional/optional.mjs.map +1 -1
  29. package/dist/functional/result.d.mts.map +1 -1
  30. package/dist/functional/result.mjs +1 -6
  31. package/dist/functional/result.mjs.map +1 -1
  32. package/dist/json/json.d.mts.map +1 -1
  33. package/dist/json/json.mjs +3 -3
  34. package/dist/json/json.mjs.map +1 -1
  35. package/dist/others/memoize-function.d.mts +1 -1
  36. package/dist/others/memoize-function.mjs +1 -1
  37. package/dist/others/unknown-to-string.d.mts +44 -77
  38. package/dist/others/unknown-to-string.d.mts.map +1 -1
  39. package/dist/others/unknown-to-string.mjs +51 -85
  40. package/dist/others/unknown-to-string.mjs.map +1 -1
  41. package/package.json +10 -1
  42. package/src/array/array-utils-creation.test.mts +9 -8
  43. package/src/array/array-utils-overload-type-error.test.mts +6 -2
  44. package/src/array/array-utils-search.test.mts +1 -1
  45. package/src/array/array-utils-slicing.test.mts +0 -42
  46. package/src/array/array-utils-transformation.test.mts +11 -186
  47. package/src/array/array-utils-validation.test.mts +27 -27
  48. package/src/array/array-utils.mts +8 -12
  49. package/src/collections/imap-mapped.test.mts +15 -11
  50. package/src/collections/imap.mts +6 -13
  51. package/src/collections/imap.test.mts +20 -19
  52. package/src/collections/iset-mapped.mts +1 -1
  53. package/src/collections/iset-mapped.test.mts +14 -104
  54. package/src/collections/iset.mts +5 -7
  55. package/src/collections/iset.test.mts +43 -34
  56. package/src/collections/queue.mts +12 -10
  57. package/src/collections/queue.test.mts +46 -44
  58. package/src/collections/stack.mts +10 -9
  59. package/src/collections/stack.test.mts +12 -10
  60. package/src/entry-point.mts +1 -0
  61. package/src/functional/match.mts +1 -5
  62. package/src/functional/optional.mts +6 -6
  63. package/src/functional/optional.test.mts +7 -7
  64. package/src/functional/result.mts +1 -5
  65. package/src/guard/is-non-empty-string.test.mts +1 -1
  66. package/src/guard/is-non-null-object.test.mts +3 -3
  67. package/src/guard/is-primitive.test.mts +6 -6
  68. package/src/guard/is-type.test.mts +8 -12
  69. package/src/iterator/range.test.mts +1 -1
  70. package/src/json/json.mts +4 -11
  71. package/src/json/json.test.mts +25 -28
  72. package/src/number/branded-types/finite-number.test.mts +2 -1
  73. package/src/number/branded-types/int.test.mts +2 -1
  74. package/src/number/branded-types/int16.test.mts +3 -2
  75. package/src/number/branded-types/int32.test.mts +3 -2
  76. package/src/number/branded-types/non-negative-finite-number.test.mts +3 -2
  77. package/src/number/branded-types/non-negative-int16.test.mts +3 -2
  78. package/src/number/branded-types/non-negative-int32.test.mts +3 -2
  79. package/src/number/branded-types/non-zero-finite-number.test.mts +4 -3
  80. package/src/number/branded-types/non-zero-int.test.mts +4 -3
  81. package/src/number/branded-types/non-zero-int16.test.mts +3 -2
  82. package/src/number/branded-types/non-zero-int32.test.mts +3 -2
  83. package/src/number/branded-types/non-zero-safe-int.test.mts +4 -3
  84. package/src/number/branded-types/non-zero-uint16.test.mts +3 -2
  85. package/src/number/branded-types/non-zero-uint32.test.mts +3 -2
  86. package/src/number/branded-types/positive-finite-number.test.mts +3 -2
  87. package/src/number/branded-types/positive-int.test.mts +3 -2
  88. package/src/number/branded-types/positive-int16.test.mts +3 -2
  89. package/src/number/branded-types/positive-int32.test.mts +3 -2
  90. package/src/number/branded-types/positive-safe-int.test.mts +3 -2
  91. package/src/number/branded-types/positive-uint16.test.mts +3 -2
  92. package/src/number/branded-types/positive-uint32.test.mts +3 -2
  93. package/src/number/branded-types/safe-int.test.mts +3 -2
  94. package/src/number/branded-types/safe-uint.test.mts +3 -2
  95. package/src/number/branded-types/uint.test.mts +3 -2
  96. package/src/number/branded-types/uint16.test.mts +3 -2
  97. package/src/number/branded-types/uint32.test.mts +3 -2
  98. package/src/object/object.test.mts +10 -10
  99. package/src/others/cast-readonly.test.mts +8 -8
  100. package/src/others/memoize-function.mts +1 -1
  101. package/src/others/memoize-function.test.mts +2 -2
  102. package/src/others/unknown-to-string.mts +52 -87
  103. package/src/others/unknown-to-string.test.mts +26 -58
@@ -25,15 +25,15 @@ describe('IMap[Symbol.iterator]', () => {
25
25
  ['a', 1],
26
26
  ['b', 2],
27
27
  ]);
28
- const collected: [string, number][] = [];
28
+ const mut_collected: (readonly [string, number])[] = [];
29
29
 
30
30
  for (const entry of map) {
31
- collected.push([...entry]);
31
+ mut_collected.push(entry);
32
32
  }
33
33
 
34
- expect(collected).toHaveLength(2);
35
- expect(collected).toContainEqual(['a', 1]);
36
- expect(collected).toContainEqual(['b', 2]);
34
+ expect(mut_collected).toHaveLength(2);
35
+ expect(mut_collected).toContainEqual(['a', 1]);
36
+ expect(mut_collected).toContainEqual(['b', 2]);
37
37
  });
38
38
 
39
39
  test('should work with spread operator', () => {
@@ -41,7 +41,7 @@ describe('IMap[Symbol.iterator]', () => {
41
41
  ['a', 1],
42
42
  ['b', 2],
43
43
  ]);
44
- const entries = [...map];
44
+ const entries = Array.from(map);
45
45
 
46
46
  expect(entries).toHaveLength(2);
47
47
  expect(entries).toContainEqual(['a', 1]);
@@ -282,8 +282,8 @@ describe('IMap.get', () => {
282
282
  ['undef', undefined],
283
283
  ['null', null],
284
284
  ]);
285
- expect(Optional.unwrap(map.get('undef'))).toBe(undefined);
286
- expect(Optional.unwrap(map.get('null'))).toBe(null);
285
+ expect(Optional.unwrap(map.get('undef'))).toBeUndefined();
286
+ expect(Optional.unwrap(map.get('null'))).toBeNull();
287
287
  });
288
288
  });
289
289
 
@@ -781,27 +781,28 @@ describe('IMap.forEach', () => {
781
781
  ['b', 2],
782
782
  ['c', 3],
783
783
  ]);
784
- const collected: [string, number][] = [];
784
+ const mut_collected: [string, number][] = [];
785
785
 
786
- map.forEach((value, key) => {
787
- collected.push([key, value]);
788
- });
786
+ for (const [key, value] of map.entries()) {
787
+ mut_collected.push([key, value]);
788
+ }
789
789
 
790
- expect(collected).toHaveLength(3);
791
- expect(collected).toContainEqual(['a', 1]);
792
- expect(collected).toContainEqual(['b', 2]);
793
- expect(collected).toContainEqual(['c', 3]);
790
+ expect(mut_collected).toHaveLength(3);
791
+ expect(mut_collected).toContainEqual(['a', 1]);
792
+ expect(mut_collected).toContainEqual(['b', 2]);
793
+ expect(mut_collected).toContainEqual(['c', 3]);
794
794
  });
795
795
 
796
796
  test('should work with empty map', () => {
797
797
  const map = IMap.create<string, number>([]);
798
- let called = false;
798
+ let mut_called = false;
799
799
 
800
+ // eslint-disable-next-line unicorn/no-array-for-each
800
801
  map.forEach(() => {
801
- called = true;
802
+ mut_called = true;
802
803
  });
803
804
 
804
- expect(called).toBe(false);
805
+ expect(mut_called).toBe(false);
805
806
  });
806
807
  });
807
808
 
@@ -611,7 +611,7 @@ export namespace ISetMapped {
611
611
  *
612
612
  * const combinedFlags = ISetMapped.union(setA, setB);
613
613
  * // The order might vary as sets are unordered internally.
614
- * console.log(combinedFlags.toArray().map(f => f.flagName).sort());
614
+ * console.log(combinedFlags.toArray().map(f => f.flagName).toSorted());
615
615
  * // Output: ["betaFeature", "darkMode", "newUI"]
616
616
  * ```
617
617
  */
@@ -212,96 +212,6 @@ describe('ISetMapped.entries', () => {
212
212
  });
213
213
  });
214
214
 
215
- describe('ISetMapped.union', () => {
216
- test('case 1', () => {
217
- const s0 = ISetMapped.create(
218
- [{ v: 1 }, { v: 2 }, { v: 3 }],
219
- toKey,
220
- fromKey,
221
- );
222
- const s1 = ISetMapped.create(
223
- [{ v: 3 }, { v: 4 }, { v: 5 }],
224
- toKey,
225
- fromKey,
226
- );
227
-
228
- expect(s0.union(s1)).toStrictEqual(
229
- ISetMapped.create(
230
- [{ v: 1 }, { v: 2 }, { v: 3 }, { v: 4 }, { v: 5 }],
231
- toKey,
232
- fromKey,
233
- ),
234
- );
235
- });
236
- test('case 2', () => {
237
- const s0 = ISetMapped.create(
238
- [{ v: 1 }, { v: 2 }, { v: 3 }],
239
- toKey,
240
- fromKey,
241
- );
242
- const s1 = ISetMapped.create([], toKey, fromKey);
243
-
244
- expect(s0.union(s1)).toStrictEqual(
245
- ISetMapped.create([{ v: 1 }, { v: 2 }, { v: 3 }], toKey, fromKey),
246
- );
247
- });
248
- test('case 3', () => {
249
- const s0 = ISetMapped.create([], toKey, fromKey);
250
- const s1 = ISetMapped.create(
251
- [{ v: 1 }, { v: 2 }, { v: 3 }],
252
- toKey,
253
- fromKey,
254
- );
255
-
256
- expect(s0.union(s1)).toStrictEqual(
257
- ISetMapped.create([{ v: 1 }, { v: 2 }, { v: 3 }], toKey, fromKey),
258
- );
259
- });
260
- });
261
-
262
- describe('ISetMapped.intersect', () => {
263
- test('case 1', () => {
264
- const s0 = ISetMapped.create(
265
- [{ v: 1 }, { v: 2 }, { v: 3 }],
266
- toKey,
267
- fromKey,
268
- );
269
- const s1 = ISetMapped.create(
270
- [{ v: 2 }, { v: 3 }, { v: 4 }],
271
- toKey,
272
- fromKey,
273
- );
274
-
275
- expect(s0.intersect(s1)).toStrictEqual(
276
- ISetMapped.create([{ v: 2 }, { v: 3 }], toKey, fromKey),
277
- );
278
- });
279
- test('case 2', () => {
280
- const s0 = ISetMapped.create(
281
- [{ v: 1 }, { v: 2 }, { v: 3 }],
282
- toKey,
283
- fromKey,
284
- );
285
- const s1 = ISetMapped.create([], toKey, fromKey);
286
-
287
- expect(s0.intersect(s1)).toStrictEqual(
288
- ISetMapped.create([], toKey, fromKey),
289
- );
290
- });
291
- test('case 3', () => {
292
- const s0 = ISetMapped.create([], toKey, fromKey);
293
- const s1 = ISetMapped.create(
294
- [{ v: 1 }, { v: 2 }, { v: 3 }],
295
- toKey,
296
- fromKey,
297
- );
298
-
299
- expect(s0.intersect(s1)).toStrictEqual(
300
- ISetMapped.create([], toKey, fromKey),
301
- );
302
- });
303
- });
304
-
305
215
  describe('ISetMapped.subtract', () => {
306
216
  test('case 1', () => {
307
217
  const s0 = ISetMapped.create(
@@ -901,15 +811,15 @@ describe('ISetMapped additional functionality with complex types', () => {
901
811
  testElementToString,
902
812
  stringToTestElement,
903
813
  );
904
- const collected: TestElement[] = [];
814
+ const mut_collected: TestElement[] = [];
905
815
 
906
- set.forEach((el) => {
907
- collected.push(el);
908
- });
816
+ for (const el of set) {
817
+ mut_collected.push(el);
818
+ }
909
819
 
910
- expect(collected).toHaveLength(2);
911
- expect(collected).toContainEqual({ id: 1, type: 'user' });
912
- expect(collected).toContainEqual({ id: 2, type: 'admin' });
820
+ expect(mut_collected).toHaveLength(2);
821
+ expect(mut_collected).toContainEqual({ id: 1, type: 'user' });
822
+ expect(mut_collected).toContainEqual({ id: 2, type: 'admin' });
913
823
  });
914
824
  });
915
825
 
@@ -1125,9 +1035,9 @@ describe('ISetMapped additional functionality with complex types', () => {
1125
1035
  const entries = Array.from(set.entries());
1126
1036
 
1127
1037
  expect(entries).toHaveLength(2);
1128
- entries.forEach(([key, value]) => {
1038
+ for (const [key, value] of entries) {
1129
1039
  expect(key).toStrictEqual(value);
1130
- });
1040
+ }
1131
1041
  });
1132
1042
 
1133
1043
  test('should work with for-of loop', () => {
@@ -1139,15 +1049,15 @@ describe('ISetMapped additional functionality with complex types', () => {
1139
1049
  testElementToString,
1140
1050
  stringToTestElement,
1141
1051
  );
1142
- const collected: TestElement[] = [];
1052
+ const mut_collected: TestElement[] = [];
1143
1053
 
1144
1054
  for (const element of set) {
1145
- collected.push(element);
1055
+ mut_collected.push(element);
1146
1056
  }
1147
1057
 
1148
- expect(collected).toHaveLength(2);
1149
- expect(collected).toContainEqual({ id: 1, type: 'user' });
1150
- expect(collected).toContainEqual({ id: 2, type: 'admin' });
1058
+ expect(mut_collected).toHaveLength(2);
1059
+ expect(mut_collected).toContainEqual({ id: 1, type: 'user' });
1060
+ expect(mut_collected).toContainEqual({ id: 2, type: 'admin' });
1151
1061
  });
1152
1062
  });
1153
1063
 
@@ -1,6 +1,6 @@
1
- import { Result } from '../functional/index.mjs';
1
+ // No imports from functional needed anymore
2
2
  import { asUint32 } from '../number/index.mjs';
3
- import { unknownToString } from '../others/unknown-to-string.mjs';
3
+ import { unknownToString } from '../others/index.mjs';
4
4
 
5
5
  /**
6
6
  * Interface for an immutable set with O(1) lookup performance and set operation support.
@@ -258,7 +258,7 @@ export namespace ISet {
258
258
  * .filter(x => x % 2 === 0) // Keep even numbers: 2, 4
259
259
  * .add(6) // Add 6: 2, 4, 6
260
260
  * .delete(2); // Remove 2: 4, 6
261
- * console.log(processedNumbers.toArray().sort()); // Output: [4, 6]
261
+ * console.log(processedNumbers.toArray().toSorted()); // Output: [4, 6]
262
262
  *
263
263
  * // From generator function
264
264
  * function* generatePrimes(): Generator<number> {
@@ -445,7 +445,7 @@ export namespace ISet {
445
445
  * const rolePermissions = ISet.create(["write", "execute", "admin"]);
446
446
  *
447
447
  * const allPermissions = ISet.union(userPermissions, rolePermissions);
448
- * console.log(allPermissions.toArray().sort());
448
+ * console.log(allPermissions.toArray().toSorted());
449
449
  * // Output: ["admin", "execute", "read", "write"]
450
450
  *
451
451
  * // Union with different types (type widening)
@@ -560,9 +560,7 @@ class ISetClass<K extends MapSetKeyType> implements ISet<K>, Iterable<K> {
560
560
  if (!this.has(key)) {
561
561
  if (this.#showNotFoundMessage) {
562
562
  const keyStr = unknownToString(key);
563
- console.warn(
564
- `ISet.delete: key not found: ${Result.isOk(keyStr) ? keyStr.value : '<error converting key to string>'}`,
565
- );
563
+ console.warn(`ISet.delete: key not found: ${keyStr}`);
566
564
  }
567
565
  return this;
568
566
  }
@@ -325,7 +325,7 @@ describe('ISet.map', () => {
325
325
  const set = ISet.create([1, 2, 3]);
326
326
  const doubled = set.map((x) => x * 2);
327
327
 
328
- expect([...doubled.toArray()].sort((a, b) => a - b)).toStrictEqual([
328
+ expect(doubled.toArray().toSorted((a, b) => a - b)).toStrictEqual([
329
329
  2, 4, 6,
330
330
  ]);
331
331
  });
@@ -711,34 +711,35 @@ describe('ISet.forEach', () => {
711
711
  (callback: (value: 1 | 2 | 3) => void) => void
712
712
  >('<=');
713
713
 
714
- const result: (1 | 2 | 3)[] = [];
715
- s0.forEach((x) => {
716
- result.push(x);
717
- });
714
+ const mut_result: (1 | 2 | 3)[] = [];
715
+ for (const x of s0) {
716
+ mut_result.push(x);
717
+ }
718
718
 
719
- expect(result.sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
719
+ expect(mut_result.toSorted((a, b) => a - b)).toStrictEqual([1, 2, 3]);
720
720
  });
721
721
 
722
722
  test('should execute callback for each element', () => {
723
723
  const set = ISet.create([1, 2, 3]);
724
- const collected: number[] = [];
724
+ const mut_collected: number[] = [];
725
725
 
726
- set.forEach((value) => {
727
- collected.push(value);
728
- });
726
+ for (const value of set) {
727
+ mut_collected.push(value);
728
+ }
729
729
 
730
- expect(collected.sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
730
+ expect(mut_collected.toSorted((a, b) => a - b)).toStrictEqual([1, 2, 3]);
731
731
  });
732
732
 
733
733
  test('should not call callback for empty set', () => {
734
734
  const set = ISet.create<number>([]);
735
- let callCount = 0;
735
+ let mut_callCount = 0;
736
736
 
737
+ // eslint-disable-next-line unicorn/no-array-for-each
737
738
  set.forEach(() => {
738
- callCount += 1;
739
+ mut_callCount += 1;
739
740
  });
740
741
 
741
- expect(callCount).toBe(0);
742
+ expect(mut_callCount).toBe(0);
742
743
  });
743
744
  });
744
745
 
@@ -748,12 +749,12 @@ describe('ISet.keys', () => {
748
749
 
749
750
  expectType<typeof s0.keys, () => IterableIterator<1 | 2 | 3>>('<=');
750
751
 
751
- const result: (1 | 2 | 3)[] = [];
752
+ const mut_result: (1 | 2 | 3)[] = [];
752
753
  for (const x of s0.keys()) {
753
- result.push(x);
754
+ mut_result.push(x);
754
755
  }
755
756
 
756
- expect(result.sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
757
+ expect(mut_result.toSorted((a, b) => a - b)).toStrictEqual([1, 2, 3]);
757
758
  });
758
759
  });
759
760
 
@@ -763,12 +764,12 @@ describe('ISet.values', () => {
763
764
 
764
765
  expectType<typeof s0.values, () => IterableIterator<1 | 2 | 3>>('<=');
765
766
 
766
- const result: (1 | 2 | 3)[] = [];
767
+ const mut_result: (1 | 2 | 3)[] = [];
767
768
  for (const x of s0.values()) {
768
- result.push(x);
769
+ mut_result.push(x);
769
770
  }
770
771
 
771
- expect(result.sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
772
+ expect(mut_result.toSorted((a, b) => a - b)).toStrictEqual([1, 2, 3]);
772
773
  });
773
774
  });
774
775
 
@@ -781,12 +782,12 @@ describe('ISet.entries', () => {
781
782
  () => IterableIterator<readonly [1 | 2 | 3, 1 | 2 | 3]>
782
783
  >('<=');
783
784
 
784
- const result: [1 | 2 | 3, 1 | 2 | 3][] = [];
785
+ const mut_result: [1 | 2 | 3, 1 | 2 | 3][] = [];
785
786
  for (const x of s0.entries()) {
786
- result.push([x[0], x[1]]);
787
+ mut_result.push([x[0], x[1]]);
787
788
  }
788
789
 
789
- expect(result.sort((a, b) => a[0] - b[0])).toStrictEqual([
790
+ expect(mut_result.toSorted((a, b) => a[0] - b[0])).toStrictEqual([
790
791
  [1, 1],
791
792
  [2, 2],
792
793
  [3, 3],
@@ -799,7 +800,9 @@ describe('ISet.toArray', () => {
799
800
  const s0 = ISet.create([1, 2, 3] as const);
800
801
 
801
802
  expectType<typeof s0.toArray, () => readonly (1 | 2 | 3)[]>('<=');
802
- expect([...s0.toArray()].sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
803
+ expect(Array.from(s0.toArray()).toSorted((a, b) => a - b)).toStrictEqual([
804
+ 1, 2, 3,
805
+ ]);
803
806
  });
804
807
 
805
808
  test('case 2', () => {
@@ -812,8 +815,10 @@ describe('ISet.toArray', () => {
812
815
  const set = ISet.create([1, 3, 2]);
813
816
  const array = set.toArray();
814
817
 
815
- expect(array.length).toBe(3);
816
- expect([...array].sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
818
+ expect(array).toHaveLength(3);
819
+ expect(Array.from(array).toSorted((a, b) => a - b)).toStrictEqual([
820
+ 1, 2, 3,
821
+ ]);
817
822
  });
818
823
  });
819
824
 
@@ -961,34 +966,38 @@ describe('ISet.withMutations', () => {
961
966
  describe('iterable functionality', () => {
962
967
  test('should work with for-of loops', () => {
963
968
  const set = ISet.create([1, 2, 3]);
964
- const collected: number[] = [];
969
+ const mut_collected: number[] = [];
965
970
 
966
971
  for (const value of set) {
967
- collected.push(value);
972
+ mut_collected.push(value);
968
973
  }
969
974
 
970
- expect(collected.sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
975
+ expect(mut_collected.toSorted((a, b) => a - b)).toStrictEqual([1, 2, 3]);
971
976
  });
972
977
 
973
978
  test('should work with spread operator', () => {
974
979
  const set = ISet.create([1, 2, 3]);
975
- const array = [...set];
980
+ const array = Array.from(set);
976
981
 
977
- expect([...array].sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
982
+ expect(Array.from(array).toSorted((a, b) => a - b)).toStrictEqual([
983
+ 1, 2, 3,
984
+ ]);
978
985
  });
979
986
 
980
987
  test('should work with Array.from', () => {
981
988
  const set = ISet.create([1, 2, 3]);
982
989
  const array = Array.from(set);
983
990
 
984
- expect([...array].sort((a, b) => a - b)).toStrictEqual([1, 2, 3]);
991
+ expect(Array.from(array).toSorted((a, b) => a - b)).toStrictEqual([
992
+ 1, 2, 3,
993
+ ]);
985
994
  });
986
995
 
987
996
  test('should work with destructuring', () => {
988
997
  const set = ISet.create([1, 2]);
989
- const values = [...set];
998
+ const values = Array.from(set);
990
999
 
991
- expect(values.sort((a, b) => a - b)).toStrictEqual([1, 2]);
1000
+ expect(values.toSorted((a, b) => a - b)).toStrictEqual([1, 2]);
992
1001
  });
993
1002
  });
994
1003
 
@@ -1,7 +1,6 @@
1
- import { Arr } from '../array/index.mjs';
2
1
  import { Optional } from '../functional/index.mjs';
3
- import { asUint32 } from '../number/index.mjs';
4
- import { castMutable } from '../others/index.mjs';
2
+ import { range } from '../iterator/index.mjs';
3
+ import { asSafeUint, asUint32 } from '../number/index.mjs';
5
4
 
6
5
  /**
7
6
  * Interface for a high-performance queue with FIFO (First-In, First-Out) behavior.
@@ -123,9 +122,11 @@ class QueueClass<T> implements Queue<T> {
123
122
  Math.max(QueueClass.#INITIAL_CAPACITY, initialValues.length * 2),
124
123
  );
125
124
 
126
- this.#buffer = castMutable(
127
- Arr.create<T | undefined, Uint32>(initialCapacity, undefined),
125
+ this.#buffer = Array.from<unknown, T | undefined>(
126
+ { length: initialCapacity },
127
+ () => undefined,
128
128
  );
129
+
129
130
  this.#head = 0;
130
131
  this.#tail = 0;
131
132
  this.#mut_size = 0;
@@ -234,7 +235,7 @@ class QueueClass<T> implements Queue<T> {
234
235
  * // High-volume enqueueing (demonstrates amortized O(1) performance)
235
236
  * const dataQueue = createQueue<number>();
236
237
  *
237
- * for (let i = 0; i < 1000000; i++) {
238
+ * for (const i of range(1000000)) {
238
239
  * dataQueue.enqueue(i); // Each operation is O(1) amortized
239
240
  * }
240
241
  *
@@ -259,12 +260,13 @@ class QueueClass<T> implements Queue<T> {
259
260
  */
260
261
  #resize(): void {
261
262
  const newCapacity = asUint32(this.#capacity * 2);
262
- const newBuffer = castMutable(
263
- Arr.create<T | undefined, Uint32>(newCapacity, undefined),
263
+ const newBuffer = Array.from<unknown, T | undefined>(
264
+ { length: newCapacity },
265
+ () => undefined,
264
266
  );
265
267
 
266
268
  // Copy elements in order from head to tail
267
- for (let i = 0; i < this.#mut_size; i++) {
269
+ for (const i of range(asSafeUint(this.#mut_size))) {
268
270
  const sourceIndex = (this.#head + i) % this.#capacity;
269
271
  newBuffer[i] = this.#buffer[sourceIndex];
270
272
  }
@@ -329,7 +331,7 @@ class QueueClass<T> implements Queue<T> {
329
331
  * const eventQueue = createQueue<Event>();
330
332
  *
331
333
  * // Simulate high-volume event ingestion
332
- * for (let i = 0; i < 10000; i++) {
334
+ * for (const i of range(10000)) {
333
335
  * eventQueue.enqueue({
334
336
  * timestamp: Date.now(),
335
337
  * type: `event-${i % 5}`,