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,26 @@
1
+ //#region src/fp/iterator/forEach.ts
2
+ /**
3
+ * Creates a function that consumes an iterator and runs `callback` for each
4
+ * element, for use as the terminal step of a {@link pipe}. It delegates to the
5
+ * native `Iterator.prototype.forEach`.
6
+ *
7
+ * This is a terminal operation: it pulls every element, so it must not be used
8
+ * on an infinite iterator.
9
+ *
10
+ * @template T - The type of elements produced by the source iterator.
11
+ * @param callback - Called with `(value, index)` for each element.
12
+ * @returns A function mapping an `Iterator<T>` to `void`.
13
+ *
14
+ * @example
15
+ * import { pipe } from 'es-toolkit/fp';
16
+ * import { forEach } from 'es-toolkit/fp/iterator';
17
+ *
18
+ * pipe([1, 2, 3].values(), forEach(x => console.log(x))); // logs 1, 2, 3
19
+ */
20
+ function forEach(callback) {
21
+ return function forEachInIterator(source) {
22
+ Iterator.from(source).forEach(callback);
23
+ };
24
+ }
25
+ //#endregion
26
+ export { forEach };
@@ -0,0 +1,19 @@
1
+ //#region src/fp/iterator/head.d.ts
2
+ /**
3
+ * Creates a function that returns the first element of an iterator (or
4
+ * `undefined` if it is empty), for use as the terminal step of a {@link pipe}.
5
+ * It pulls a single element and then closes the source via its `return` method,
6
+ * so it is safe on an infinite iterator.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @returns A function mapping an `Iterator<T>` to its first element or `undefined`.
10
+ *
11
+ * @example
12
+ * import { pipe } from 'es-toolkit/fp';
13
+ * import { filter, head } from 'es-toolkit/fp/iterator';
14
+ *
15
+ * pipe([1, 2, 3, 4].values(), filter(x => x % 2 === 0), head()); // => 2
16
+ */
17
+ declare function head<T>(): (source: Iterator<T>) => T | undefined;
18
+ //#endregion
19
+ export { head };
@@ -0,0 +1,19 @@
1
+ //#region src/fp/iterator/head.d.ts
2
+ /**
3
+ * Creates a function that returns the first element of an iterator (or
4
+ * `undefined` if it is empty), for use as the terminal step of a {@link pipe}.
5
+ * It pulls a single element and then closes the source via its `return` method,
6
+ * so it is safe on an infinite iterator.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @returns A function mapping an `Iterator<T>` to its first element or `undefined`.
10
+ *
11
+ * @example
12
+ * import { pipe } from 'es-toolkit/fp';
13
+ * import { filter, head } from 'es-toolkit/fp/iterator';
14
+ *
15
+ * pipe([1, 2, 3, 4].values(), filter(x => x % 2 === 0), head()); // => 2
16
+ */
17
+ declare function head<T>(): (source: Iterator<T>) => T | undefined;
18
+ //#endregion
19
+ export { head };
@@ -0,0 +1,24 @@
1
+ const require_head = require("../../iterator/head.js");
2
+ //#region src/fp/iterator/head.ts
3
+ /**
4
+ * Creates a function that returns the first element of an iterator (or
5
+ * `undefined` if it is empty), for use as the terminal step of a {@link pipe}.
6
+ * It pulls a single element and then closes the source via its `return` method,
7
+ * so it is safe on an infinite iterator.
8
+ *
9
+ * @template T - The type of elements produced by the source iterator.
10
+ * @returns A function mapping an `Iterator<T>` to its first element or `undefined`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { filter, head } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3, 4].values(), filter(x => x % 2 === 0), head()); // => 2
17
+ */
18
+ function head() {
19
+ return function headInIterator(source) {
20
+ return require_head.head(source);
21
+ };
22
+ }
23
+ //#endregion
24
+ exports.head = head;
@@ -0,0 +1,24 @@
1
+ import { head as head$1 } from "../../iterator/head.mjs";
2
+ //#region src/fp/iterator/head.ts
3
+ /**
4
+ * Creates a function that returns the first element of an iterator (or
5
+ * `undefined` if it is empty), for use as the terminal step of a {@link pipe}.
6
+ * It pulls a single element and then closes the source via its `return` method,
7
+ * so it is safe on an infinite iterator.
8
+ *
9
+ * @template T - The type of elements produced by the source iterator.
10
+ * @returns A function mapping an `Iterator<T>` to its first element or `undefined`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { filter, head } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3, 4].values(), filter(x => x % 2 === 0), head()); // => 2
17
+ */
18
+ function head() {
19
+ return function headInIterator(source) {
20
+ return head$1(source);
21
+ };
22
+ }
23
+ //#endregion
24
+ export { head };
@@ -0,0 +1,22 @@
1
+ import { cartesianProduct } from "./cartesianProduct.mjs";
2
+ import { chunk } from "./chunk.mjs";
3
+ import { count } from "./count.mjs";
4
+ import { drop } from "./drop.mjs";
5
+ import { dropWhile } from "./dropWhile.mjs";
6
+ import { every } from "./every.mjs";
7
+ import { filter } from "./filter.mjs";
8
+ import { find } from "./find.mjs";
9
+ import { flatMap } from "./flatMap.mjs";
10
+ import { forEach } from "./forEach.mjs";
11
+ import { head } from "./head.mjs";
12
+ import { map } from "./map.mjs";
13
+ import { partition } from "./partition.mjs";
14
+ import { reduce } from "./reduce.mjs";
15
+ import { scan } from "./scan.mjs";
16
+ import { some } from "./some.mjs";
17
+ import { take } from "./take.mjs";
18
+ import { takeWhile } from "./takeWhile.mjs";
19
+ import { toArray } from "./toArray.mjs";
20
+ import { uniqBy } from "./uniqBy.mjs";
21
+ import { zip } from "./zip.mjs";
22
+ export { cartesianProduct, chunk, count, drop, dropWhile, every, filter, find, flatMap, forEach, head, map, partition, reduce, scan, some, take, takeWhile, toArray, uniqBy, zip };
@@ -0,0 +1,22 @@
1
+ import { cartesianProduct } from "./cartesianProduct.js";
2
+ import { chunk } from "./chunk.js";
3
+ import { count } from "./count.js";
4
+ import { drop } from "./drop.js";
5
+ import { dropWhile } from "./dropWhile.js";
6
+ import { every } from "./every.js";
7
+ import { filter } from "./filter.js";
8
+ import { find } from "./find.js";
9
+ import { flatMap } from "./flatMap.js";
10
+ import { forEach } from "./forEach.js";
11
+ import { head } from "./head.js";
12
+ import { map } from "./map.js";
13
+ import { partition } from "./partition.js";
14
+ import { reduce } from "./reduce.js";
15
+ import { scan } from "./scan.js";
16
+ import { some } from "./some.js";
17
+ import { take } from "./take.js";
18
+ import { takeWhile } from "./takeWhile.js";
19
+ import { toArray } from "./toArray.js";
20
+ import { uniqBy } from "./uniqBy.js";
21
+ import { zip } from "./zip.js";
22
+ export { cartesianProduct, chunk, count, drop, dropWhile, every, filter, find, flatMap, forEach, head, map, partition, reduce, scan, some, take, takeWhile, toArray, uniqBy, zip };
@@ -0,0 +1,43 @@
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_drop = require("./drop.js");
6
+ const require_dropWhile = require("./dropWhile.js");
7
+ const require_every = require("./every.js");
8
+ const require_filter = require("./filter.js");
9
+ const require_find = require("./find.js");
10
+ const require_flatMap = require("./flatMap.js");
11
+ const require_forEach = require("./forEach.js");
12
+ const require_head = require("./head.js");
13
+ const require_map = require("./map.js");
14
+ const require_partition = require("./partition.js");
15
+ const require_reduce = require("./reduce.js");
16
+ const require_scan = require("./scan.js");
17
+ const require_some = require("./some.js");
18
+ const require_take = require("./take.js");
19
+ const require_takeWhile = require("./takeWhile.js");
20
+ const require_toArray = require("./toArray.js");
21
+ const require_uniqBy = require("./uniqBy.js");
22
+ const require_zip = require("./zip.js");
23
+ exports.cartesianProduct = require_cartesianProduct.cartesianProduct;
24
+ exports.chunk = require_chunk.chunk;
25
+ exports.count = require_count.count;
26
+ exports.drop = require_drop.drop;
27
+ exports.dropWhile = require_dropWhile.dropWhile;
28
+ exports.every = require_every.every;
29
+ exports.filter = require_filter.filter;
30
+ exports.find = require_find.find;
31
+ exports.flatMap = require_flatMap.flatMap;
32
+ exports.forEach = require_forEach.forEach;
33
+ exports.head = require_head.head;
34
+ exports.map = require_map.map;
35
+ exports.partition = require_partition.partition;
36
+ exports.reduce = require_reduce.reduce;
37
+ exports.scan = require_scan.scan;
38
+ exports.some = require_some.some;
39
+ exports.take = require_take.take;
40
+ exports.takeWhile = require_takeWhile.takeWhile;
41
+ exports.toArray = require_toArray.toArray;
42
+ exports.uniqBy = require_uniqBy.uniqBy;
43
+ exports.zip = require_zip.zip;
@@ -0,0 +1,22 @@
1
+ import { cartesianProduct } from "./cartesianProduct.mjs";
2
+ import { chunk } from "./chunk.mjs";
3
+ import { count } from "./count.mjs";
4
+ import { drop } from "./drop.mjs";
5
+ import { dropWhile } from "./dropWhile.mjs";
6
+ import { every } from "./every.mjs";
7
+ import { filter } from "./filter.mjs";
8
+ import { find } from "./find.mjs";
9
+ import { flatMap } from "./flatMap.mjs";
10
+ import { forEach } from "./forEach.mjs";
11
+ import { head } from "./head.mjs";
12
+ import { map } from "./map.mjs";
13
+ import { partition } from "./partition.mjs";
14
+ import { reduce } from "./reduce.mjs";
15
+ import { scan } from "./scan.mjs";
16
+ import { some } from "./some.mjs";
17
+ import { take } from "./take.mjs";
18
+ import { takeWhile } from "./takeWhile.mjs";
19
+ import { toArray } from "./toArray.mjs";
20
+ import { uniqBy } from "./uniqBy.mjs";
21
+ import { zip } from "./zip.mjs";
22
+ export { cartesianProduct, chunk, count, drop, dropWhile, every, filter, find, flatMap, forEach, head, map, partition, reduce, scan, some, take, takeWhile, toArray, uniqBy, zip };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/map.d.ts
2
+ /**
3
+ * Creates a function that lazily transforms each element of an iterator with
4
+ * `callback`, for use with {@link pipe}. It delegates to the native
5
+ * `Iterator.prototype.map`, so the result is a lazy, single-shot iterator.
6
+ *
7
+ * @template T - The type of elements produced by the source iterator.
8
+ * @template U - The type of elements produced by the result.
9
+ * @param callback - Called with `(value, index)`; its return value is yielded.
10
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<U>`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { map } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3].values(), map(x => x * 2)).toArray(); // => [2, 4, 6]
17
+ */
18
+ declare function map<T, U>(callback: (value: T, index: number) => U): (source: Iterator<T>) => IteratorObject<U, undefined>;
19
+ //#endregion
20
+ export { map };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/map.d.ts
2
+ /**
3
+ * Creates a function that lazily transforms each element of an iterator with
4
+ * `callback`, for use with {@link pipe}. It delegates to the native
5
+ * `Iterator.prototype.map`, so the result is a lazy, single-shot iterator.
6
+ *
7
+ * @template T - The type of elements produced by the source iterator.
8
+ * @template U - The type of elements produced by the result.
9
+ * @param callback - Called with `(value, index)`; its return value is yielded.
10
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<U>`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { map } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3].values(), map(x => x * 2)).toArray(); // => [2, 4, 6]
17
+ */
18
+ declare function map<T, U>(callback: (value: T, index: number) => U): (source: Iterator<T>) => IteratorObject<U, undefined>;
19
+ //#endregion
20
+ export { map };
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/map.ts
2
+ /**
3
+ * Creates a function that lazily transforms each element of an iterator with
4
+ * `callback`, for use with {@link pipe}. It delegates to the native
5
+ * `Iterator.prototype.map`, so the result is a lazy, single-shot iterator.
6
+ *
7
+ * @template T - The type of elements produced by the source iterator.
8
+ * @template U - The type of elements produced by the result.
9
+ * @param callback - Called with `(value, index)`; its return value is yielded.
10
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<U>`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { map } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3].values(), map(x => x * 2)).toArray(); // => [2, 4, 6]
17
+ */
18
+ function map(callback) {
19
+ return function mapInIterator(source) {
20
+ return Iterator.from(source).map(callback);
21
+ };
22
+ }
23
+ //#endregion
24
+ exports.map = map;
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/map.ts
2
+ /**
3
+ * Creates a function that lazily transforms each element of an iterator with
4
+ * `callback`, for use with {@link pipe}. It delegates to the native
5
+ * `Iterator.prototype.map`, so the result is a lazy, single-shot iterator.
6
+ *
7
+ * @template T - The type of elements produced by the source iterator.
8
+ * @template U - The type of elements produced by the result.
9
+ * @param callback - Called with `(value, index)`; its return value is yielded.
10
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<U>`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { map } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3].values(), map(x => x * 2)).toArray(); // => [2, 4, 6]
17
+ */
18
+ function map(callback) {
19
+ return function mapInIterator(source) {
20
+ return Iterator.from(source).map(callback);
21
+ };
22
+ }
23
+ //#endregion
24
+ export { map };
@@ -0,0 +1,22 @@
1
+ //#region src/fp/iterator/partition.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator and splits its elements into
4
+ * `[matched, unmatched]` arrays by `predicate`, for use as the terminal step of
5
+ * a {@link pipe}.
6
+ *
7
+ * This is a terminal operation: it pulls every element, so it must not be used
8
+ * on an infinite iterator.
9
+ *
10
+ * @template T - The type of elements produced by the source iterator.
11
+ * @param predicate - Called with `(value, index)`; truthy sends the element to the first array.
12
+ * @returns A function mapping an `Iterator<T>` to a `[T[], T[]]` tuple.
13
+ *
14
+ * @example
15
+ * import { pipe } from 'es-toolkit/fp';
16
+ * import { partition } from 'es-toolkit/fp/iterator';
17
+ *
18
+ * pipe([1, 2, 3, 4].values(), partition(x => x % 2 === 0)); // => [[2, 4], [1, 3]]
19
+ */
20
+ declare function partition<T>(predicate: (value: T, index: number) => boolean): (source: Iterator<T>) => [T[], T[]];
21
+ //#endregion
22
+ export { partition };
@@ -0,0 +1,22 @@
1
+ //#region src/fp/iterator/partition.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator and splits its elements into
4
+ * `[matched, unmatched]` arrays by `predicate`, for use as the terminal step of
5
+ * a {@link pipe}.
6
+ *
7
+ * This is a terminal operation: it pulls every element, so it must not be used
8
+ * on an infinite iterator.
9
+ *
10
+ * @template T - The type of elements produced by the source iterator.
11
+ * @param predicate - Called with `(value, index)`; truthy sends the element to the first array.
12
+ * @returns A function mapping an `Iterator<T>` to a `[T[], T[]]` tuple.
13
+ *
14
+ * @example
15
+ * import { pipe } from 'es-toolkit/fp';
16
+ * import { partition } from 'es-toolkit/fp/iterator';
17
+ *
18
+ * pipe([1, 2, 3, 4].values(), partition(x => x % 2 === 0)); // => [[2, 4], [1, 3]]
19
+ */
20
+ declare function partition<T>(predicate: (value: T, index: number) => boolean): (source: Iterator<T>) => [T[], T[]];
21
+ //#endregion
22
+ export { partition };
@@ -0,0 +1,27 @@
1
+ const require_partition = require("../../iterator/partition.js");
2
+ //#region src/fp/iterator/partition.ts
3
+ /**
4
+ * Creates a function that consumes an iterator and splits its elements into
5
+ * `[matched, unmatched]` arrays by `predicate`, for use as the terminal step of
6
+ * a {@link pipe}.
7
+ *
8
+ * This is a terminal operation: it pulls every element, so it must not be used
9
+ * on an infinite iterator.
10
+ *
11
+ * @template T - The type of elements produced by the source iterator.
12
+ * @param predicate - Called with `(value, index)`; truthy sends the element to the first array.
13
+ * @returns A function mapping an `Iterator<T>` to a `[T[], T[]]` tuple.
14
+ *
15
+ * @example
16
+ * import { pipe } from 'es-toolkit/fp';
17
+ * import { partition } from 'es-toolkit/fp/iterator';
18
+ *
19
+ * pipe([1, 2, 3, 4].values(), partition(x => x % 2 === 0)); // => [[2, 4], [1, 3]]
20
+ */
21
+ function partition(predicate) {
22
+ return function partitionInIterator(source) {
23
+ return require_partition.partition(source, predicate);
24
+ };
25
+ }
26
+ //#endregion
27
+ exports.partition = partition;
@@ -0,0 +1,27 @@
1
+ import { partition as partition$1 } from "../../iterator/partition.mjs";
2
+ //#region src/fp/iterator/partition.ts
3
+ /**
4
+ * Creates a function that consumes an iterator and splits its elements into
5
+ * `[matched, unmatched]` arrays by `predicate`, for use as the terminal step of
6
+ * a {@link pipe}.
7
+ *
8
+ * This is a terminal operation: it pulls every element, so it must not be used
9
+ * on an infinite iterator.
10
+ *
11
+ * @template T - The type of elements produced by the source iterator.
12
+ * @param predicate - Called with `(value, index)`; truthy sends the element to the first array.
13
+ * @returns A function mapping an `Iterator<T>` to a `[T[], T[]]` tuple.
14
+ *
15
+ * @example
16
+ * import { pipe } from 'es-toolkit/fp';
17
+ * import { partition } from 'es-toolkit/fp/iterator';
18
+ *
19
+ * pipe([1, 2, 3, 4].values(), partition(x => x % 2 === 0)); // => [[2, 4], [1, 3]]
20
+ */
21
+ function partition(predicate) {
22
+ return function partitionInIterator(source) {
23
+ return partition$1(source, predicate);
24
+ };
25
+ }
26
+ //#endregion
27
+ export { partition };
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/reduce.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator and folds its elements into a
4
+ * single value, starting from `initial`, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.reduce`.
6
+ *
7
+ * This is a terminal operation: it pulls every element, so it must not be used
8
+ * on an infinite iterator.
9
+ *
10
+ * @template T - The type of elements produced by the source iterator.
11
+ * @template U - The type of the accumulated value.
12
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
13
+ * @param initial - The initial accumulator value.
14
+ * @returns A function mapping an `Iterator<T>` to the final accumulated value.
15
+ *
16
+ * @example
17
+ * import { pipe } from 'es-toolkit/fp';
18
+ * import { reduce } from 'es-toolkit/fp/iterator';
19
+ *
20
+ * pipe([1, 2, 3].values(), reduce((acc, x) => acc + x, 0)); // => 6
21
+ */
22
+ declare function reduce<T, U>(callback: (accumulator: U, value: T, index: number) => U, initial: U): (source: Iterator<T>) => U;
23
+ //#endregion
24
+ export { reduce };
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/reduce.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator and folds its elements into a
4
+ * single value, starting from `initial`, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.reduce`.
6
+ *
7
+ * This is a terminal operation: it pulls every element, so it must not be used
8
+ * on an infinite iterator.
9
+ *
10
+ * @template T - The type of elements produced by the source iterator.
11
+ * @template U - The type of the accumulated value.
12
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
13
+ * @param initial - The initial accumulator value.
14
+ * @returns A function mapping an `Iterator<T>` to the final accumulated value.
15
+ *
16
+ * @example
17
+ * import { pipe } from 'es-toolkit/fp';
18
+ * import { reduce } from 'es-toolkit/fp/iterator';
19
+ *
20
+ * pipe([1, 2, 3].values(), reduce((acc, x) => acc + x, 0)); // => 6
21
+ */
22
+ declare function reduce<T, U>(callback: (accumulator: U, value: T, index: number) => U, initial: U): (source: Iterator<T>) => U;
23
+ //#endregion
24
+ export { reduce };
@@ -0,0 +1,28 @@
1
+ //#region src/fp/iterator/reduce.ts
2
+ /**
3
+ * Creates a function that consumes an iterator and folds its elements into a
4
+ * single value, starting from `initial`, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.reduce`.
6
+ *
7
+ * This is a terminal operation: it pulls every element, so it must not be used
8
+ * on an infinite iterator.
9
+ *
10
+ * @template T - The type of elements produced by the source iterator.
11
+ * @template U - The type of the accumulated value.
12
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
13
+ * @param initial - The initial accumulator value.
14
+ * @returns A function mapping an `Iterator<T>` to the final accumulated value.
15
+ *
16
+ * @example
17
+ * import { pipe } from 'es-toolkit/fp';
18
+ * import { reduce } from 'es-toolkit/fp/iterator';
19
+ *
20
+ * pipe([1, 2, 3].values(), reduce((acc, x) => acc + x, 0)); // => 6
21
+ */
22
+ function reduce(callback, initial) {
23
+ return function reduceInIterator(source) {
24
+ return Iterator.from(source).reduce(callback, initial);
25
+ };
26
+ }
27
+ //#endregion
28
+ exports.reduce = reduce;
@@ -0,0 +1,28 @@
1
+ //#region src/fp/iterator/reduce.ts
2
+ /**
3
+ * Creates a function that consumes an iterator and folds its elements into a
4
+ * single value, starting from `initial`, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.reduce`.
6
+ *
7
+ * This is a terminal operation: it pulls every element, so it must not be used
8
+ * on an infinite iterator.
9
+ *
10
+ * @template T - The type of elements produced by the source iterator.
11
+ * @template U - The type of the accumulated value.
12
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
13
+ * @param initial - The initial accumulator value.
14
+ * @returns A function mapping an `Iterator<T>` to the final accumulated value.
15
+ *
16
+ * @example
17
+ * import { pipe } from 'es-toolkit/fp';
18
+ * import { reduce } from 'es-toolkit/fp/iterator';
19
+ *
20
+ * pipe([1, 2, 3].values(), reduce((acc, x) => acc + x, 0)); // => 6
21
+ */
22
+ function reduce(callback, initial) {
23
+ return function reduceInIterator(source) {
24
+ return Iterator.from(source).reduce(callback, initial);
25
+ };
26
+ }
27
+ //#endregion
28
+ export { reduce };
@@ -0,0 +1,21 @@
1
+ //#region src/fp/iterator/scan.d.ts
2
+ /**
3
+ * Creates a function that lazily yields the running accumulation of an iterator,
4
+ * emitting `initial` first and then the accumulator after each element, for use
5
+ * with {@link pipe}.
6
+ *
7
+ * @template T - The type of elements produced by the source iterator.
8
+ * @template U - The type of the accumulated value.
9
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
10
+ * @param initial - The initial accumulator, emitted as the first value.
11
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<U>`.
12
+ *
13
+ * @example
14
+ * import { pipe } from 'es-toolkit/fp';
15
+ * import { scan, toArray } from 'es-toolkit/fp/iterator';
16
+ *
17
+ * pipe([1, 2, 3].values(), scan((acc, x) => acc + x, 0), toArray()); // => [0, 1, 3, 6]
18
+ */
19
+ declare function scan<T, U>(callback: (accumulator: U, value: T, index: number) => U, initial: U): (source: Iterator<T>) => IteratorObject<U, undefined>;
20
+ //#endregion
21
+ export { scan };
@@ -0,0 +1,21 @@
1
+ //#region src/fp/iterator/scan.d.ts
2
+ /**
3
+ * Creates a function that lazily yields the running accumulation of an iterator,
4
+ * emitting `initial` first and then the accumulator after each element, for use
5
+ * with {@link pipe}.
6
+ *
7
+ * @template T - The type of elements produced by the source iterator.
8
+ * @template U - The type of the accumulated value.
9
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
10
+ * @param initial - The initial accumulator, emitted as the first value.
11
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<U>`.
12
+ *
13
+ * @example
14
+ * import { pipe } from 'es-toolkit/fp';
15
+ * import { scan, toArray } from 'es-toolkit/fp/iterator';
16
+ *
17
+ * pipe([1, 2, 3].values(), scan((acc, x) => acc + x, 0), toArray()); // => [0, 1, 3, 6]
18
+ */
19
+ declare function scan<T, U>(callback: (accumulator: U, value: T, index: number) => U, initial: U): (source: Iterator<T>) => IteratorObject<U, undefined>;
20
+ //#endregion
21
+ export { scan };
@@ -0,0 +1,26 @@
1
+ const require_scan = require("../../iterator/scan.js");
2
+ //#region src/fp/iterator/scan.ts
3
+ /**
4
+ * Creates a function that lazily yields the running accumulation of an iterator,
5
+ * emitting `initial` first and then the accumulator after each element, for use
6
+ * with {@link pipe}.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @template U - The type of the accumulated value.
10
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
11
+ * @param initial - The initial accumulator, emitted as the first value.
12
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<U>`.
13
+ *
14
+ * @example
15
+ * import { pipe } from 'es-toolkit/fp';
16
+ * import { scan, toArray } from 'es-toolkit/fp/iterator';
17
+ *
18
+ * pipe([1, 2, 3].values(), scan((acc, x) => acc + x, 0), toArray()); // => [0, 1, 3, 6]
19
+ */
20
+ function scan(callback, initial) {
21
+ return function scanInIterator(source) {
22
+ return require_scan.scan(source, callback, initial);
23
+ };
24
+ }
25
+ //#endregion
26
+ exports.scan = scan;
@@ -0,0 +1,26 @@
1
+ import { scan as scan$1 } from "../../iterator/scan.mjs";
2
+ //#region src/fp/iterator/scan.ts
3
+ /**
4
+ * Creates a function that lazily yields the running accumulation of an iterator,
5
+ * emitting `initial` first and then the accumulator after each element, for use
6
+ * with {@link pipe}.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @template U - The type of the accumulated value.
10
+ * @param callback - Called with `(accumulator, value, index)`; returns the next accumulator.
11
+ * @param initial - The initial accumulator, emitted as the first value.
12
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<U>`.
13
+ *
14
+ * @example
15
+ * import { pipe } from 'es-toolkit/fp';
16
+ * import { scan, toArray } from 'es-toolkit/fp/iterator';
17
+ *
18
+ * pipe([1, 2, 3].values(), scan((acc, x) => acc + x, 0), toArray()); // => [0, 1, 3, 6]
19
+ */
20
+ function scan(callback, initial) {
21
+ return function scanInIterator(source) {
22
+ return scan$1(source, callback, initial);
23
+ };
24
+ }
25
+ //#endregion
26
+ export { scan };