es-toolkit 1.51.0-dev.2065 → 1.51.0-dev.2070

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 (150) hide show
  1. package/dist/browser.global.js +1 -1
  2. package/dist/compat/function/debounce.js +1 -1
  3. package/dist/compat/function/debounce.mjs +1 -1
  4. package/dist/fp/iterator/cartesianProduct.d.mts +23 -0
  5. package/dist/fp/iterator/cartesianProduct.d.ts +23 -0
  6. package/dist/fp/iterator/cartesianProduct.js +28 -0
  7. package/dist/fp/iterator/cartesianProduct.mjs +28 -0
  8. package/dist/fp/iterator/chunk.d.mts +19 -0
  9. package/dist/fp/iterator/chunk.d.ts +19 -0
  10. package/dist/fp/iterator/chunk.js +24 -0
  11. package/dist/fp/iterator/chunk.mjs +24 -0
  12. package/dist/fp/iterator/count.d.mts +20 -0
  13. package/dist/fp/iterator/count.d.ts +20 -0
  14. package/dist/fp/iterator/count.js +25 -0
  15. package/dist/fp/iterator/count.mjs +25 -0
  16. package/dist/fp/iterator/drop.d.mts +20 -0
  17. package/dist/fp/iterator/drop.d.ts +20 -0
  18. package/dist/fp/iterator/drop.js +24 -0
  19. package/dist/fp/iterator/drop.mjs +24 -0
  20. package/dist/fp/iterator/dropWhile.d.mts +18 -0
  21. package/dist/fp/iterator/dropWhile.d.ts +18 -0
  22. package/dist/fp/iterator/dropWhile.js +23 -0
  23. package/dist/fp/iterator/dropWhile.mjs +23 -0
  24. package/dist/fp/iterator/every.d.mts +20 -0
  25. package/dist/fp/iterator/every.d.ts +20 -0
  26. package/dist/fp/iterator/every.js +24 -0
  27. package/dist/fp/iterator/every.mjs +24 -0
  28. package/dist/fp/iterator/filter.d.mts +37 -0
  29. package/dist/fp/iterator/filter.d.ts +37 -0
  30. package/dist/fp/iterator/filter.js +8 -0
  31. package/dist/fp/iterator/filter.mjs +8 -0
  32. package/dist/fp/iterator/find.d.mts +20 -0
  33. package/dist/fp/iterator/find.d.ts +20 -0
  34. package/dist/fp/iterator/find.js +24 -0
  35. package/dist/fp/iterator/find.mjs +24 -0
  36. package/dist/fp/iterator/flatMap.d.mts +20 -0
  37. package/dist/fp/iterator/flatMap.d.ts +20 -0
  38. package/dist/fp/iterator/flatMap.js +24 -0
  39. package/dist/fp/iterator/flatMap.mjs +24 -0
  40. package/dist/fp/iterator/forEach.d.mts +22 -0
  41. package/dist/fp/iterator/forEach.d.ts +22 -0
  42. package/dist/fp/iterator/forEach.js +26 -0
  43. package/dist/fp/iterator/forEach.mjs +26 -0
  44. package/dist/fp/iterator/head.d.mts +19 -0
  45. package/dist/fp/iterator/head.d.ts +19 -0
  46. package/dist/fp/iterator/head.js +24 -0
  47. package/dist/fp/iterator/head.mjs +24 -0
  48. package/dist/fp/iterator/index.d.mts +22 -0
  49. package/dist/fp/iterator/index.d.ts +22 -0
  50. package/dist/fp/iterator/index.js +43 -0
  51. package/dist/fp/iterator/index.mjs +22 -0
  52. package/dist/fp/iterator/map.d.mts +20 -0
  53. package/dist/fp/iterator/map.d.ts +20 -0
  54. package/dist/fp/iterator/map.js +24 -0
  55. package/dist/fp/iterator/map.mjs +24 -0
  56. package/dist/fp/iterator/partition.d.mts +22 -0
  57. package/dist/fp/iterator/partition.d.ts +22 -0
  58. package/dist/fp/iterator/partition.js +27 -0
  59. package/dist/fp/iterator/partition.mjs +27 -0
  60. package/dist/fp/iterator/reduce.d.mts +24 -0
  61. package/dist/fp/iterator/reduce.d.ts +24 -0
  62. package/dist/fp/iterator/reduce.js +28 -0
  63. package/dist/fp/iterator/reduce.mjs +28 -0
  64. package/dist/fp/iterator/scan.d.mts +21 -0
  65. package/dist/fp/iterator/scan.d.ts +21 -0
  66. package/dist/fp/iterator/scan.js +26 -0
  67. package/dist/fp/iterator/scan.mjs +26 -0
  68. package/dist/fp/iterator/some.d.mts +20 -0
  69. package/dist/fp/iterator/some.d.ts +20 -0
  70. package/dist/fp/iterator/some.js +24 -0
  71. package/dist/fp/iterator/some.mjs +24 -0
  72. package/dist/fp/iterator/take.d.mts +21 -0
  73. package/dist/fp/iterator/take.d.ts +21 -0
  74. package/dist/fp/iterator/take.js +25 -0
  75. package/dist/fp/iterator/take.mjs +25 -0
  76. package/dist/fp/iterator/takeWhile.d.mts +19 -0
  77. package/dist/fp/iterator/takeWhile.d.ts +19 -0
  78. package/dist/fp/iterator/takeWhile.js +24 -0
  79. package/dist/fp/iterator/takeWhile.mjs +24 -0
  80. package/dist/fp/iterator/toArray.d.mts +21 -0
  81. package/dist/fp/iterator/toArray.d.ts +21 -0
  82. package/dist/fp/iterator/toArray.js +25 -0
  83. package/dist/fp/iterator/toArray.mjs +25 -0
  84. package/dist/fp/iterator/uniqBy.d.mts +20 -0
  85. package/dist/fp/iterator/uniqBy.d.ts +20 -0
  86. package/dist/fp/iterator/uniqBy.js +25 -0
  87. package/dist/fp/iterator/uniqBy.mjs +25 -0
  88. package/dist/fp/iterator/zip.d.mts +20 -0
  89. package/dist/fp/iterator/zip.d.ts +20 -0
  90. package/dist/fp/iterator/zip.js +25 -0
  91. package/dist/fp/iterator/zip.mjs +25 -0
  92. package/dist/iterator/_internal/iterator.js +74 -0
  93. package/dist/iterator/_internal/iterator.mjs +74 -0
  94. package/dist/iterator/cartesianProduct.d.mts +33 -0
  95. package/dist/iterator/cartesianProduct.d.ts +33 -0
  96. package/dist/iterator/cartesianProduct.js +95 -0
  97. package/dist/iterator/cartesianProduct.mjs +95 -0
  98. package/dist/iterator/chunk.d.mts +21 -0
  99. package/dist/iterator/chunk.d.ts +21 -0
  100. package/dist/iterator/chunk.js +40 -0
  101. package/dist/iterator/chunk.mjs +40 -0
  102. package/dist/iterator/count.d.mts +18 -0
  103. package/dist/iterator/count.d.ts +18 -0
  104. package/dist/iterator/count.js +26 -0
  105. package/dist/iterator/count.mjs +26 -0
  106. package/dist/iterator/dropWhile.d.mts +20 -0
  107. package/dist/iterator/dropWhile.d.ts +20 -0
  108. package/dist/iterator/dropWhile.js +52 -0
  109. package/dist/iterator/dropWhile.mjs +52 -0
  110. package/dist/iterator/head.d.mts +21 -0
  111. package/dist/iterator/head.d.ts +21 -0
  112. package/dist/iterator/head.js +26 -0
  113. package/dist/iterator/head.mjs +26 -0
  114. package/dist/iterator/index.d.mts +13 -0
  115. package/dist/iterator/index.d.ts +13 -0
  116. package/dist/iterator/index.js +25 -0
  117. package/dist/iterator/index.mjs +13 -0
  118. package/dist/iterator/iterate.d.mts +20 -0
  119. package/dist/iterator/iterate.d.ts +20 -0
  120. package/dist/iterator/iterate.js +32 -0
  121. package/dist/iterator/iterate.mjs +32 -0
  122. package/dist/iterator/partition.d.mts +18 -0
  123. package/dist/iterator/partition.d.ts +18 -0
  124. package/dist/iterator/partition.js +36 -0
  125. package/dist/iterator/partition.mjs +36 -0
  126. package/dist/iterator/range.d.mts +42 -0
  127. package/dist/iterator/range.d.ts +42 -0
  128. package/dist/iterator/range.js +25 -0
  129. package/dist/iterator/range.mjs +25 -0
  130. package/dist/iterator/scan.d.mts +23 -0
  131. package/dist/iterator/scan.d.ts +23 -0
  132. package/dist/iterator/scan.js +47 -0
  133. package/dist/iterator/scan.mjs +47 -0
  134. package/dist/iterator/takeWhile.d.mts +20 -0
  135. package/dist/iterator/takeWhile.d.ts +20 -0
  136. package/dist/iterator/takeWhile.js +34 -0
  137. package/dist/iterator/takeWhile.mjs +34 -0
  138. package/dist/iterator/uniqBy.d.mts +22 -0
  139. package/dist/iterator/uniqBy.d.ts +22 -0
  140. package/dist/iterator/uniqBy.js +43 -0
  141. package/dist/iterator/uniqBy.mjs +43 -0
  142. package/dist/iterator/zip.d.mts +23 -0
  143. package/dist/iterator/zip.d.ts +23 -0
  144. package/dist/iterator/zip.js +45 -0
  145. package/dist/iterator/zip.mjs +45 -0
  146. package/fp/iterator.d.ts +1 -0
  147. package/fp/iterator.js +1 -0
  148. package/iterator.d.ts +1 -0
  149. package/iterator.js +1 -0
  150. package/package.json +44 -1
@@ -0,0 +1,52 @@
1
+ import { iterator } from "./_internal/iterator.mjs";
2
+ //#region src/iterator/dropWhile.ts
3
+ /**
4
+ * Lazily skips elements from `source` as long as `shouldDrop` returns a truthy
5
+ * value, then yields every remaining element (including the one that first
6
+ * failed the predicate).
7
+ *
8
+ * The native iterator helpers offer `drop` (by count) but not a predicate-based
9
+ * `dropWhile`, which is why this is provided.
10
+ *
11
+ * @template T - The type of elements produced by the iterator.
12
+ * @param source - The iterator to drop elements from.
13
+ * @param shouldDrop - Called with `(value, index)`; elements are skipped while it returns truthy.
14
+ * @returns A lazy iterator over the elements after the dropped leading run.
15
+ *
16
+ * @example
17
+ * dropWhile([1, 2, 3, 1].values(), x => x < 3).toArray(); // => [3, 1]
18
+ */
19
+ function dropWhile(source, shouldDrop) {
20
+ let index = 0;
21
+ let dropping = true;
22
+ return iterator(function() {
23
+ while (dropping) {
24
+ const result = source.next();
25
+ if (result.done) {
26
+ dropping = false;
27
+ return {
28
+ value: void 0,
29
+ done: true
30
+ };
31
+ }
32
+ if (!shouldDrop(result.value, index++)) {
33
+ dropping = false;
34
+ return {
35
+ value: result.value,
36
+ done: false
37
+ };
38
+ }
39
+ }
40
+ const result = source.next();
41
+ if (result.done) return {
42
+ value: void 0,
43
+ done: true
44
+ };
45
+ return {
46
+ value: result.value,
47
+ done: false
48
+ };
49
+ }, () => void source.return?.());
50
+ }
51
+ //#endregion
52
+ export { dropWhile };
@@ -0,0 +1,21 @@
1
+ //#region src/iterator/head.d.ts
2
+ /**
3
+ * Returns the first element produced by `source`, or `undefined` if it is empty.
4
+ * This pulls a single element and then stops, so it is safe to use on an
5
+ * infinite iterator.
6
+ *
7
+ * This consumes the iterator rather than peeking at it: after reading the first
8
+ * element, `source` is closed via its `return` method (matching the native
9
+ * `Iterator.prototype.find`), so it cannot be iterated further.
10
+ *
11
+ * @template T - The type of elements produced by the iterator.
12
+ * @param source - The iterator to read the first element from.
13
+ * @returns The first element, or `undefined` when the iterator yields nothing.
14
+ *
15
+ * @example
16
+ * head([1, 2, 3].values()); // => 1
17
+ * head([].values()); // => undefined
18
+ */
19
+ declare function head<T>(source: Iterator<T>): T | undefined;
20
+ //#endregion
21
+ export { head };
@@ -0,0 +1,21 @@
1
+ //#region src/iterator/head.d.ts
2
+ /**
3
+ * Returns the first element produced by `source`, or `undefined` if it is empty.
4
+ * This pulls a single element and then stops, so it is safe to use on an
5
+ * infinite iterator.
6
+ *
7
+ * This consumes the iterator rather than peeking at it: after reading the first
8
+ * element, `source` is closed via its `return` method (matching the native
9
+ * `Iterator.prototype.find`), so it cannot be iterated further.
10
+ *
11
+ * @template T - The type of elements produced by the iterator.
12
+ * @param source - The iterator to read the first element from.
13
+ * @returns The first element, or `undefined` when the iterator yields nothing.
14
+ *
15
+ * @example
16
+ * head([1, 2, 3].values()); // => 1
17
+ * head([].values()); // => undefined
18
+ */
19
+ declare function head<T>(source: Iterator<T>): T | undefined;
20
+ //#endregion
21
+ export { head };
@@ -0,0 +1,26 @@
1
+ //#region src/iterator/head.ts
2
+ /**
3
+ * Returns the first element produced by `source`, or `undefined` if it is empty.
4
+ * This pulls a single element and then stops, so it is safe to use on an
5
+ * infinite iterator.
6
+ *
7
+ * This consumes the iterator rather than peeking at it: after reading the first
8
+ * element, `source` is closed via its `return` method (matching the native
9
+ * `Iterator.prototype.find`), so it cannot be iterated further.
10
+ *
11
+ * @template T - The type of elements produced by the iterator.
12
+ * @param source - The iterator to read the first element from.
13
+ * @returns The first element, or `undefined` when the iterator yields nothing.
14
+ *
15
+ * @example
16
+ * head([1, 2, 3].values()); // => 1
17
+ * head([].values()); // => undefined
18
+ */
19
+ function head(source) {
20
+ const result = source.next();
21
+ if (result.done) return;
22
+ source.return?.();
23
+ return result.value;
24
+ }
25
+ //#endregion
26
+ exports.head = head;
@@ -0,0 +1,26 @@
1
+ //#region src/iterator/head.ts
2
+ /**
3
+ * Returns the first element produced by `source`, or `undefined` if it is empty.
4
+ * This pulls a single element and then stops, so it is safe to use on an
5
+ * infinite iterator.
6
+ *
7
+ * This consumes the iterator rather than peeking at it: after reading the first
8
+ * element, `source` is closed via its `return` method (matching the native
9
+ * `Iterator.prototype.find`), so it cannot be iterated further.
10
+ *
11
+ * @template T - The type of elements produced by the iterator.
12
+ * @param source - The iterator to read the first element from.
13
+ * @returns The first element, or `undefined` when the iterator yields nothing.
14
+ *
15
+ * @example
16
+ * head([1, 2, 3].values()); // => 1
17
+ * head([].values()); // => undefined
18
+ */
19
+ function head(source) {
20
+ const result = source.next();
21
+ if (result.done) return;
22
+ source.return?.();
23
+ return result.value;
24
+ }
25
+ //#endregion
26
+ export { head };
@@ -0,0 +1,13 @@
1
+ import { cartesianProduct } from "./cartesianProduct.mjs";
2
+ import { chunk } from "./chunk.mjs";
3
+ import { count } from "./count.mjs";
4
+ import { dropWhile } from "./dropWhile.mjs";
5
+ import { head } from "./head.mjs";
6
+ import { iterate } from "./iterate.mjs";
7
+ import { partition } from "./partition.mjs";
8
+ import { range } from "./range.mjs";
9
+ import { scan } from "./scan.mjs";
10
+ import { takeWhile } from "./takeWhile.mjs";
11
+ import { uniqBy } from "./uniqBy.mjs";
12
+ import { zip } from "./zip.mjs";
13
+ export { cartesianProduct, chunk, count, dropWhile, head, iterate, partition, range, scan, takeWhile, uniqBy, zip };
@@ -0,0 +1,13 @@
1
+ import { cartesianProduct } from "./cartesianProduct.js";
2
+ import { chunk } from "./chunk.js";
3
+ import { count } from "./count.js";
4
+ import { dropWhile } from "./dropWhile.js";
5
+ import { head } from "./head.js";
6
+ import { iterate } from "./iterate.js";
7
+ import { partition } from "./partition.js";
8
+ import { range } from "./range.js";
9
+ import { scan } from "./scan.js";
10
+ import { takeWhile } from "./takeWhile.js";
11
+ import { uniqBy } from "./uniqBy.js";
12
+ import { zip } from "./zip.js";
13
+ export { cartesianProduct, chunk, count, dropWhile, head, iterate, partition, range, scan, takeWhile, uniqBy, zip };
@@ -0,0 +1,25 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_cartesianProduct = require("./cartesianProduct.js");
3
+ const require_chunk = require("./chunk.js");
4
+ const require_count = require("./count.js");
5
+ const require_dropWhile = require("./dropWhile.js");
6
+ const require_head = require("./head.js");
7
+ const require_partition = require("./partition.js");
8
+ const require_scan = require("./scan.js");
9
+ const require_takeWhile = require("./takeWhile.js");
10
+ const require_uniqBy = require("./uniqBy.js");
11
+ const require_zip = require("./zip.js");
12
+ const require_iterate = require("./iterate.js");
13
+ const require_range = require("./range.js");
14
+ exports.cartesianProduct = require_cartesianProduct.cartesianProduct;
15
+ exports.chunk = require_chunk.chunk;
16
+ exports.count = require_count.count;
17
+ exports.dropWhile = require_dropWhile.dropWhile;
18
+ exports.head = require_head.head;
19
+ exports.iterate = require_iterate.iterate;
20
+ exports.partition = require_partition.partition;
21
+ exports.range = require_range.range;
22
+ exports.scan = require_scan.scan;
23
+ exports.takeWhile = require_takeWhile.takeWhile;
24
+ exports.uniqBy = require_uniqBy.uniqBy;
25
+ exports.zip = require_zip.zip;
@@ -0,0 +1,13 @@
1
+ import { cartesianProduct } from "./cartesianProduct.mjs";
2
+ import { chunk } from "./chunk.mjs";
3
+ import { count } from "./count.mjs";
4
+ import { dropWhile } from "./dropWhile.mjs";
5
+ import { head } from "./head.mjs";
6
+ import { partition } from "./partition.mjs";
7
+ import { scan } from "./scan.mjs";
8
+ import { takeWhile } from "./takeWhile.mjs";
9
+ import { uniqBy } from "./uniqBy.mjs";
10
+ import { zip } from "./zip.mjs";
11
+ import { iterate } from "./iterate.mjs";
12
+ import { range } from "./range.mjs";
13
+ export { cartesianProduct, chunk, count, dropWhile, head, iterate, partition, range, scan, takeWhile, uniqBy, zip };
@@ -0,0 +1,20 @@
1
+ //#region src/iterator/iterate.d.ts
2
+ /**
3
+ * Creates an infinite lazy iterator that starts with `seed` and repeatedly
4
+ * applies `getNext` to produce the following value: `seed`, `getNext(seed)`,
5
+ * `getNext(getNext(seed))`, and so on.
6
+ *
7
+ * Because the iterator is infinite, it must be bounded by a short-circuiting
8
+ * helper such as the native `take` or {@link takeWhile} before being consumed.
9
+ *
10
+ * @template T - The type of values produced by the iterator.
11
+ * @param seed - The first value of the sequence.
12
+ * @param getNext - Computes the next value from the current one.
13
+ * @returns An infinite lazy iterator over the generated sequence.
14
+ *
15
+ * @example
16
+ * iterate(1, x => x * 2).take(5).toArray(); // => [1, 2, 4, 8, 16]
17
+ */
18
+ declare function iterate<T>(seed: T, getNext: (value: T) => T): IteratorObject<T, undefined>;
19
+ //#endregion
20
+ export { iterate };
@@ -0,0 +1,20 @@
1
+ //#region src/iterator/iterate.d.ts
2
+ /**
3
+ * Creates an infinite lazy iterator that starts with `seed` and repeatedly
4
+ * applies `getNext` to produce the following value: `seed`, `getNext(seed)`,
5
+ * `getNext(getNext(seed))`, and so on.
6
+ *
7
+ * Because the iterator is infinite, it must be bounded by a short-circuiting
8
+ * helper such as the native `take` or {@link takeWhile} before being consumed.
9
+ *
10
+ * @template T - The type of values produced by the iterator.
11
+ * @param seed - The first value of the sequence.
12
+ * @param getNext - Computes the next value from the current one.
13
+ * @returns An infinite lazy iterator over the generated sequence.
14
+ *
15
+ * @example
16
+ * iterate(1, x => x * 2).take(5).toArray(); // => [1, 2, 4, 8, 16]
17
+ */
18
+ declare function iterate<T>(seed: T, getNext: (value: T) => T): IteratorObject<T, undefined>;
19
+ //#endregion
20
+ export { iterate };
@@ -0,0 +1,32 @@
1
+ const require_iterator = require("./_internal/iterator.js");
2
+ //#region src/iterator/iterate.ts
3
+ /**
4
+ * Creates an infinite lazy iterator that starts with `seed` and repeatedly
5
+ * applies `getNext` to produce the following value: `seed`, `getNext(seed)`,
6
+ * `getNext(getNext(seed))`, and so on.
7
+ *
8
+ * Because the iterator is infinite, it must be bounded by a short-circuiting
9
+ * helper such as the native `take` or {@link takeWhile} before being consumed.
10
+ *
11
+ * @template T - The type of values produced by the iterator.
12
+ * @param seed - The first value of the sequence.
13
+ * @param getNext - Computes the next value from the current one.
14
+ * @returns An infinite lazy iterator over the generated sequence.
15
+ *
16
+ * @example
17
+ * iterate(1, x => x * 2).take(5).toArray(); // => [1, 2, 4, 8, 16]
18
+ */
19
+ function iterate(seed, getNext) {
20
+ let current = seed;
21
+ let started = false;
22
+ return require_iterator.iterator(function() {
23
+ if (started) current = getNext(current);
24
+ else started = true;
25
+ return {
26
+ value: current,
27
+ done: false
28
+ };
29
+ });
30
+ }
31
+ //#endregion
32
+ exports.iterate = iterate;
@@ -0,0 +1,32 @@
1
+ import { iterator } from "./_internal/iterator.mjs";
2
+ //#region src/iterator/iterate.ts
3
+ /**
4
+ * Creates an infinite lazy iterator that starts with `seed` and repeatedly
5
+ * applies `getNext` to produce the following value: `seed`, `getNext(seed)`,
6
+ * `getNext(getNext(seed))`, and so on.
7
+ *
8
+ * Because the iterator is infinite, it must be bounded by a short-circuiting
9
+ * helper such as the native `take` or {@link takeWhile} before being consumed.
10
+ *
11
+ * @template T - The type of values produced by the iterator.
12
+ * @param seed - The first value of the sequence.
13
+ * @param getNext - Computes the next value from the current one.
14
+ * @returns An infinite lazy iterator over the generated sequence.
15
+ *
16
+ * @example
17
+ * iterate(1, x => x * 2).take(5).toArray(); // => [1, 2, 4, 8, 16]
18
+ */
19
+ function iterate(seed, getNext) {
20
+ let current = seed;
21
+ let started = false;
22
+ return iterator(function() {
23
+ if (started) current = getNext(current);
24
+ else started = true;
25
+ return {
26
+ value: current,
27
+ done: false
28
+ };
29
+ });
30
+ }
31
+ //#endregion
32
+ export { iterate };
@@ -0,0 +1,18 @@
1
+ //#region src/iterator/partition.d.ts
2
+ /**
3
+ * Consumes `source` and splits its elements into two arrays: the first holds the
4
+ * elements for which `predicate` returns truthy, the second holds the rest.
5
+ * Relative order is preserved within each group. This is a terminal operation:
6
+ * it pulls every element, so it must not be used on an infinite iterator.
7
+ *
8
+ * @template T - The type of elements produced by the iterator.
9
+ * @param source - The iterator to partition.
10
+ * @param predicate - Called with `(value, index)`; truthy sends the element to the first array.
11
+ * @returns A two-element tuple of `[matched, unmatched]` arrays.
12
+ *
13
+ * @example
14
+ * partition([1, 2, 3, 4].values(), x => x % 2 === 0); // => [[2, 4], [1, 3]]
15
+ */
16
+ declare function partition<T>(source: Iterator<T>, predicate: (value: T, index: number) => boolean): [T[], T[]];
17
+ //#endregion
18
+ export { partition };
@@ -0,0 +1,18 @@
1
+ //#region src/iterator/partition.d.ts
2
+ /**
3
+ * Consumes `source` and splits its elements into two arrays: the first holds the
4
+ * elements for which `predicate` returns truthy, the second holds the rest.
5
+ * Relative order is preserved within each group. This is a terminal operation:
6
+ * it pulls every element, so it must not be used on an infinite iterator.
7
+ *
8
+ * @template T - The type of elements produced by the iterator.
9
+ * @param source - The iterator to partition.
10
+ * @param predicate - Called with `(value, index)`; truthy sends the element to the first array.
11
+ * @returns A two-element tuple of `[matched, unmatched]` arrays.
12
+ *
13
+ * @example
14
+ * partition([1, 2, 3, 4].values(), x => x % 2 === 0); // => [[2, 4], [1, 3]]
15
+ */
16
+ declare function partition<T>(source: Iterator<T>, predicate: (value: T, index: number) => boolean): [T[], T[]];
17
+ //#endregion
18
+ export { partition };
@@ -0,0 +1,36 @@
1
+ //#region src/iterator/partition.ts
2
+ /**
3
+ * Consumes `source` and splits its elements into two arrays: the first holds the
4
+ * elements for which `predicate` returns truthy, the second holds the rest.
5
+ * Relative order is preserved within each group. This is a terminal operation:
6
+ * it pulls every element, so it must not be used on an infinite iterator.
7
+ *
8
+ * @template T - The type of elements produced by the iterator.
9
+ * @param source - The iterator to partition.
10
+ * @param predicate - Called with `(value, index)`; truthy sends the element to the first array.
11
+ * @returns A two-element tuple of `[matched, unmatched]` arrays.
12
+ *
13
+ * @example
14
+ * partition([1, 2, 3, 4].values(), x => x % 2 === 0); // => [[2, 4], [1, 3]]
15
+ */
16
+ function partition(source, predicate) {
17
+ const matched = [];
18
+ const unmatched = [];
19
+ let index = 0;
20
+ let next = source.next();
21
+ while (!next.done) {
22
+ let isMatch;
23
+ try {
24
+ isMatch = predicate(next.value, index++);
25
+ } catch (error) {
26
+ source.return?.();
27
+ throw error;
28
+ }
29
+ if (isMatch) matched.push(next.value);
30
+ else unmatched.push(next.value);
31
+ next = source.next();
32
+ }
33
+ return [matched, unmatched];
34
+ }
35
+ //#endregion
36
+ exports.partition = partition;
@@ -0,0 +1,36 @@
1
+ //#region src/iterator/partition.ts
2
+ /**
3
+ * Consumes `source` and splits its elements into two arrays: the first holds the
4
+ * elements for which `predicate` returns truthy, the second holds the rest.
5
+ * Relative order is preserved within each group. This is a terminal operation:
6
+ * it pulls every element, so it must not be used on an infinite iterator.
7
+ *
8
+ * @template T - The type of elements produced by the iterator.
9
+ * @param source - The iterator to partition.
10
+ * @param predicate - Called with `(value, index)`; truthy sends the element to the first array.
11
+ * @returns A two-element tuple of `[matched, unmatched]` arrays.
12
+ *
13
+ * @example
14
+ * partition([1, 2, 3, 4].values(), x => x % 2 === 0); // => [[2, 4], [1, 3]]
15
+ */
16
+ function partition(source, predicate) {
17
+ const matched = [];
18
+ const unmatched = [];
19
+ let index = 0;
20
+ let next = source.next();
21
+ while (!next.done) {
22
+ let isMatch;
23
+ try {
24
+ isMatch = predicate(next.value, index++);
25
+ } catch (error) {
26
+ source.return?.();
27
+ throw error;
28
+ }
29
+ if (isMatch) matched.push(next.value);
30
+ else unmatched.push(next.value);
31
+ next = source.next();
32
+ }
33
+ return [matched, unmatched];
34
+ }
35
+ //#endregion
36
+ export { partition };
@@ -0,0 +1,42 @@
1
+ //#region src/iterator/range.d.ts
2
+ /**
3
+ * Lazily yields numbers from `0` (inclusive) up to `end` (exclusive), incrementing by `1`.
4
+ *
5
+ * Unlike `es-toolkit`'s array `range`, this produces a lazy {@link IteratorObject}:
6
+ * no numbers are computed until the iterator is consumed, so it composes with
7
+ * other iterator helpers and supports early termination.
8
+ *
9
+ * @param end - The end number of the range (exclusive).
10
+ * @returns A lazy iterator over the numbers in the range.
11
+ *
12
+ * @example
13
+ * range(4).toArray(); // => [0, 1, 2, 3]
14
+ */
15
+ declare function range(end: number): IteratorObject<number, undefined>;
16
+ /**
17
+ * Lazily yields numbers from `start` (inclusive) up to `end` (exclusive), incrementing by `1`.
18
+ *
19
+ * @param start - The starting number of the range (inclusive).
20
+ * @param end - The end number of the range (exclusive).
21
+ * @returns A lazy iterator over the numbers in the range.
22
+ *
23
+ * @example
24
+ * range(1, 4).toArray(); // => [1, 2, 3]
25
+ */
26
+ declare function range(start: number, end: number): IteratorObject<number, undefined>;
27
+ /**
28
+ * Lazily yields numbers from `start` (inclusive) up to `end` (exclusive), incrementing by `step`.
29
+ *
30
+ * @param start - The starting number of the range (inclusive).
31
+ * @param end - The end number of the range (exclusive).
32
+ * @param step - The step value for the range.
33
+ * @returns A lazy iterator over the numbers in the range.
34
+ * @throws {Error} Throws an error if the step value is not a non-zero integer.
35
+ *
36
+ * @example
37
+ * range(0, 20, 5).toArray(); // => [0, 5, 10, 15]
38
+ * range(0, -4, -1).toArray(); // => [0, -1, -2, -3]
39
+ */
40
+ declare function range(start: number, end: number, step: number): IteratorObject<number, undefined>;
41
+ //#endregion
42
+ export { range };
@@ -0,0 +1,42 @@
1
+ //#region src/iterator/range.d.ts
2
+ /**
3
+ * Lazily yields numbers from `0` (inclusive) up to `end` (exclusive), incrementing by `1`.
4
+ *
5
+ * Unlike `es-toolkit`'s array `range`, this produces a lazy {@link IteratorObject}:
6
+ * no numbers are computed until the iterator is consumed, so it composes with
7
+ * other iterator helpers and supports early termination.
8
+ *
9
+ * @param end - The end number of the range (exclusive).
10
+ * @returns A lazy iterator over the numbers in the range.
11
+ *
12
+ * @example
13
+ * range(4).toArray(); // => [0, 1, 2, 3]
14
+ */
15
+ declare function range(end: number): IteratorObject<number, undefined>;
16
+ /**
17
+ * Lazily yields numbers from `start` (inclusive) up to `end` (exclusive), incrementing by `1`.
18
+ *
19
+ * @param start - The starting number of the range (inclusive).
20
+ * @param end - The end number of the range (exclusive).
21
+ * @returns A lazy iterator over the numbers in the range.
22
+ *
23
+ * @example
24
+ * range(1, 4).toArray(); // => [1, 2, 3]
25
+ */
26
+ declare function range(start: number, end: number): IteratorObject<number, undefined>;
27
+ /**
28
+ * Lazily yields numbers from `start` (inclusive) up to `end` (exclusive), incrementing by `step`.
29
+ *
30
+ * @param start - The starting number of the range (inclusive).
31
+ * @param end - The end number of the range (exclusive).
32
+ * @param step - The step value for the range.
33
+ * @returns A lazy iterator over the numbers in the range.
34
+ * @throws {Error} Throws an error if the step value is not a non-zero integer.
35
+ *
36
+ * @example
37
+ * range(0, 20, 5).toArray(); // => [0, 5, 10, 15]
38
+ * range(0, -4, -1).toArray(); // => [0, -1, -2, -3]
39
+ */
40
+ declare function range(start: number, end: number, step: number): IteratorObject<number, undefined>;
41
+ //#endregion
42
+ export { range };
@@ -0,0 +1,25 @@
1
+ const require_iterator = require("./_internal/iterator.js");
2
+ //#region src/iterator/range.ts
3
+ function range(start, end, step = 1) {
4
+ if (end == null) {
5
+ end = start;
6
+ start = 0;
7
+ }
8
+ if (!Number.isInteger(step) || step === 0) throw new Error(`The step value must be a non-zero integer, but got ${step}.`);
9
+ const finalEnd = end;
10
+ let current = start;
11
+ return require_iterator.iterator(function() {
12
+ if (step > 0 ? current >= finalEnd : current <= finalEnd) return {
13
+ value: void 0,
14
+ done: true
15
+ };
16
+ const value = current;
17
+ current += step;
18
+ return {
19
+ value,
20
+ done: false
21
+ };
22
+ });
23
+ }
24
+ //#endregion
25
+ exports.range = range;
@@ -0,0 +1,25 @@
1
+ import { iterator } from "./_internal/iterator.mjs";
2
+ //#region src/iterator/range.ts
3
+ function range(start, end, step = 1) {
4
+ if (end == null) {
5
+ end = start;
6
+ start = 0;
7
+ }
8
+ if (!Number.isInteger(step) || step === 0) throw new Error(`The step value must be a non-zero integer, but got ${step}.`);
9
+ const finalEnd = end;
10
+ let current = start;
11
+ return iterator(function() {
12
+ if (step > 0 ? current >= finalEnd : current <= finalEnd) return {
13
+ value: void 0,
14
+ done: true
15
+ };
16
+ const value = current;
17
+ current += step;
18
+ return {
19
+ value,
20
+ done: false
21
+ };
22
+ });
23
+ }
24
+ //#endregion
25
+ export { range };
@@ -0,0 +1,23 @@
1
+ //#region src/iterator/scan.d.ts
2
+ /**
3
+ * Lazily yields the running accumulation of `source` under `callback`, like a
4
+ * `reduce` that emits every intermediate result. The `initial` value is emitted
5
+ * first, followed by the accumulator after each element.
6
+ *
7
+ * For an input of length `n`, the output has length `n + 1`. This is the
8
+ * "scan-left" / prefix-scan behavior and has no native iterator-helper
9
+ * equivalent.
10
+ *
11
+ * @template T - The type of elements produced by `source`.
12
+ * @template U - The type of the accumulated value.
13
+ * @param source - The iterator to accumulate over.
14
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
15
+ * @param initial - The initial accumulator, emitted as the first value.
16
+ * @returns A lazy iterator over the initial value and each successive accumulator.
17
+ *
18
+ * @example
19
+ * scan([1, 2, 3].values(), (acc, x) => acc + x, 0).toArray(); // => [0, 1, 3, 6]
20
+ */
21
+ declare function scan<T, U>(source: Iterator<T>, callback: (accumulator: U, value: T, index: number) => U, initial: U): IteratorObject<U, undefined>;
22
+ //#endregion
23
+ export { scan };
@@ -0,0 +1,23 @@
1
+ //#region src/iterator/scan.d.ts
2
+ /**
3
+ * Lazily yields the running accumulation of `source` under `callback`, like a
4
+ * `reduce` that emits every intermediate result. The `initial` value is emitted
5
+ * first, followed by the accumulator after each element.
6
+ *
7
+ * For an input of length `n`, the output has length `n + 1`. This is the
8
+ * "scan-left" / prefix-scan behavior and has no native iterator-helper
9
+ * equivalent.
10
+ *
11
+ * @template T - The type of elements produced by `source`.
12
+ * @template U - The type of the accumulated value.
13
+ * @param source - The iterator to accumulate over.
14
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
15
+ * @param initial - The initial accumulator, emitted as the first value.
16
+ * @returns A lazy iterator over the initial value and each successive accumulator.
17
+ *
18
+ * @example
19
+ * scan([1, 2, 3].values(), (acc, x) => acc + x, 0).toArray(); // => [0, 1, 3, 6]
20
+ */
21
+ declare function scan<T, U>(source: Iterator<T>, callback: (accumulator: U, value: T, index: number) => U, initial: U): IteratorObject<U, undefined>;
22
+ //#endregion
23
+ export { scan };