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

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 (142) 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/chunk.d.mts +19 -0
  5. package/dist/fp/iterator/chunk.d.ts +19 -0
  6. package/dist/fp/iterator/chunk.js +24 -0
  7. package/dist/fp/iterator/chunk.mjs +24 -0
  8. package/dist/fp/iterator/count.d.mts +20 -0
  9. package/dist/fp/iterator/count.d.ts +20 -0
  10. package/dist/fp/iterator/count.js +25 -0
  11. package/dist/fp/iterator/count.mjs +25 -0
  12. package/dist/fp/iterator/drop.d.mts +20 -0
  13. package/dist/fp/iterator/drop.d.ts +20 -0
  14. package/dist/fp/iterator/drop.js +24 -0
  15. package/dist/fp/iterator/drop.mjs +24 -0
  16. package/dist/fp/iterator/dropWhile.d.mts +18 -0
  17. package/dist/fp/iterator/dropWhile.d.ts +18 -0
  18. package/dist/fp/iterator/dropWhile.js +23 -0
  19. package/dist/fp/iterator/dropWhile.mjs +23 -0
  20. package/dist/fp/iterator/every.d.mts +20 -0
  21. package/dist/fp/iterator/every.d.ts +20 -0
  22. package/dist/fp/iterator/every.js +24 -0
  23. package/dist/fp/iterator/every.mjs +24 -0
  24. package/dist/fp/iterator/filter.d.mts +37 -0
  25. package/dist/fp/iterator/filter.d.ts +37 -0
  26. package/dist/fp/iterator/filter.js +8 -0
  27. package/dist/fp/iterator/filter.mjs +8 -0
  28. package/dist/fp/iterator/find.d.mts +20 -0
  29. package/dist/fp/iterator/find.d.ts +20 -0
  30. package/dist/fp/iterator/find.js +24 -0
  31. package/dist/fp/iterator/find.mjs +24 -0
  32. package/dist/fp/iterator/flatMap.d.mts +20 -0
  33. package/dist/fp/iterator/flatMap.d.ts +20 -0
  34. package/dist/fp/iterator/flatMap.js +24 -0
  35. package/dist/fp/iterator/flatMap.mjs +24 -0
  36. package/dist/fp/iterator/forEach.d.mts +22 -0
  37. package/dist/fp/iterator/forEach.d.ts +22 -0
  38. package/dist/fp/iterator/forEach.js +26 -0
  39. package/dist/fp/iterator/forEach.mjs +26 -0
  40. package/dist/fp/iterator/head.d.mts +19 -0
  41. package/dist/fp/iterator/head.d.ts +19 -0
  42. package/dist/fp/iterator/head.js +24 -0
  43. package/dist/fp/iterator/head.mjs +24 -0
  44. package/dist/fp/iterator/index.d.mts +21 -0
  45. package/dist/fp/iterator/index.d.ts +21 -0
  46. package/dist/fp/iterator/index.js +41 -0
  47. package/dist/fp/iterator/index.mjs +21 -0
  48. package/dist/fp/iterator/map.d.mts +20 -0
  49. package/dist/fp/iterator/map.d.ts +20 -0
  50. package/dist/fp/iterator/map.js +24 -0
  51. package/dist/fp/iterator/map.mjs +24 -0
  52. package/dist/fp/iterator/partition.d.mts +22 -0
  53. package/dist/fp/iterator/partition.d.ts +22 -0
  54. package/dist/fp/iterator/partition.js +27 -0
  55. package/dist/fp/iterator/partition.mjs +27 -0
  56. package/dist/fp/iterator/reduce.d.mts +24 -0
  57. package/dist/fp/iterator/reduce.d.ts +24 -0
  58. package/dist/fp/iterator/reduce.js +28 -0
  59. package/dist/fp/iterator/reduce.mjs +28 -0
  60. package/dist/fp/iterator/scan.d.mts +21 -0
  61. package/dist/fp/iterator/scan.d.ts +21 -0
  62. package/dist/fp/iterator/scan.js +26 -0
  63. package/dist/fp/iterator/scan.mjs +26 -0
  64. package/dist/fp/iterator/some.d.mts +20 -0
  65. package/dist/fp/iterator/some.d.ts +20 -0
  66. package/dist/fp/iterator/some.js +24 -0
  67. package/dist/fp/iterator/some.mjs +24 -0
  68. package/dist/fp/iterator/take.d.mts +21 -0
  69. package/dist/fp/iterator/take.d.ts +21 -0
  70. package/dist/fp/iterator/take.js +25 -0
  71. package/dist/fp/iterator/take.mjs +25 -0
  72. package/dist/fp/iterator/takeWhile.d.mts +19 -0
  73. package/dist/fp/iterator/takeWhile.d.ts +19 -0
  74. package/dist/fp/iterator/takeWhile.js +24 -0
  75. package/dist/fp/iterator/takeWhile.mjs +24 -0
  76. package/dist/fp/iterator/toArray.d.mts +21 -0
  77. package/dist/fp/iterator/toArray.d.ts +21 -0
  78. package/dist/fp/iterator/toArray.js +25 -0
  79. package/dist/fp/iterator/toArray.mjs +25 -0
  80. package/dist/fp/iterator/uniqBy.d.mts +20 -0
  81. package/dist/fp/iterator/uniqBy.d.ts +20 -0
  82. package/dist/fp/iterator/uniqBy.js +25 -0
  83. package/dist/fp/iterator/uniqBy.mjs +25 -0
  84. package/dist/fp/iterator/zip.d.mts +20 -0
  85. package/dist/fp/iterator/zip.d.ts +20 -0
  86. package/dist/fp/iterator/zip.js +25 -0
  87. package/dist/fp/iterator/zip.mjs +25 -0
  88. package/dist/iterator/_internal/iterator.js +74 -0
  89. package/dist/iterator/_internal/iterator.mjs +74 -0
  90. package/dist/iterator/chunk.d.mts +21 -0
  91. package/dist/iterator/chunk.d.ts +21 -0
  92. package/dist/iterator/chunk.js +40 -0
  93. package/dist/iterator/chunk.mjs +40 -0
  94. package/dist/iterator/count.d.mts +18 -0
  95. package/dist/iterator/count.d.ts +18 -0
  96. package/dist/iterator/count.js +26 -0
  97. package/dist/iterator/count.mjs +26 -0
  98. package/dist/iterator/dropWhile.d.mts +20 -0
  99. package/dist/iterator/dropWhile.d.ts +20 -0
  100. package/dist/iterator/dropWhile.js +52 -0
  101. package/dist/iterator/dropWhile.mjs +52 -0
  102. package/dist/iterator/head.d.mts +21 -0
  103. package/dist/iterator/head.d.ts +21 -0
  104. package/dist/iterator/head.js +26 -0
  105. package/dist/iterator/head.mjs +26 -0
  106. package/dist/iterator/index.d.mts +12 -0
  107. package/dist/iterator/index.d.ts +12 -0
  108. package/dist/iterator/index.js +23 -0
  109. package/dist/iterator/index.mjs +12 -0
  110. package/dist/iterator/iterate.d.mts +20 -0
  111. package/dist/iterator/iterate.d.ts +20 -0
  112. package/dist/iterator/iterate.js +32 -0
  113. package/dist/iterator/iterate.mjs +32 -0
  114. package/dist/iterator/partition.d.mts +18 -0
  115. package/dist/iterator/partition.d.ts +18 -0
  116. package/dist/iterator/partition.js +36 -0
  117. package/dist/iterator/partition.mjs +36 -0
  118. package/dist/iterator/range.d.mts +42 -0
  119. package/dist/iterator/range.d.ts +42 -0
  120. package/dist/iterator/range.js +25 -0
  121. package/dist/iterator/range.mjs +25 -0
  122. package/dist/iterator/scan.d.mts +23 -0
  123. package/dist/iterator/scan.d.ts +23 -0
  124. package/dist/iterator/scan.js +47 -0
  125. package/dist/iterator/scan.mjs +47 -0
  126. package/dist/iterator/takeWhile.d.mts +20 -0
  127. package/dist/iterator/takeWhile.d.ts +20 -0
  128. package/dist/iterator/takeWhile.js +34 -0
  129. package/dist/iterator/takeWhile.mjs +34 -0
  130. package/dist/iterator/uniqBy.d.mts +22 -0
  131. package/dist/iterator/uniqBy.d.ts +22 -0
  132. package/dist/iterator/uniqBy.js +43 -0
  133. package/dist/iterator/uniqBy.mjs +43 -0
  134. package/dist/iterator/zip.d.mts +23 -0
  135. package/dist/iterator/zip.d.ts +23 -0
  136. package/dist/iterator/zip.js +45 -0
  137. package/dist/iterator/zip.mjs +45 -0
  138. package/fp/iterator.d.ts +1 -0
  139. package/fp/iterator.js +1 -0
  140. package/iterator.d.ts +1 -0
  141. package/iterator.js +1 -0
  142. package/package.json +44 -1
@@ -0,0 +1,21 @@
1
+ import { chunk } from "./chunk.mjs";
2
+ import { count } from "./count.mjs";
3
+ import { drop } from "./drop.mjs";
4
+ import { dropWhile } from "./dropWhile.mjs";
5
+ import { every } from "./every.mjs";
6
+ import { filter } from "./filter.mjs";
7
+ import { find } from "./find.mjs";
8
+ import { flatMap } from "./flatMap.mjs";
9
+ import { forEach } from "./forEach.mjs";
10
+ import { head } from "./head.mjs";
11
+ import { map } from "./map.mjs";
12
+ import { partition } from "./partition.mjs";
13
+ import { reduce } from "./reduce.mjs";
14
+ import { scan } from "./scan.mjs";
15
+ import { some } from "./some.mjs";
16
+ import { take } from "./take.mjs";
17
+ import { takeWhile } from "./takeWhile.mjs";
18
+ import { toArray } from "./toArray.mjs";
19
+ import { uniqBy } from "./uniqBy.mjs";
20
+ import { zip } from "./zip.mjs";
21
+ export { chunk, count, drop, dropWhile, every, filter, find, flatMap, forEach, head, map, partition, reduce, scan, some, take, takeWhile, toArray, uniqBy, zip };
@@ -0,0 +1,21 @@
1
+ import { chunk } from "./chunk.js";
2
+ import { count } from "./count.js";
3
+ import { drop } from "./drop.js";
4
+ import { dropWhile } from "./dropWhile.js";
5
+ import { every } from "./every.js";
6
+ import { filter } from "./filter.js";
7
+ import { find } from "./find.js";
8
+ import { flatMap } from "./flatMap.js";
9
+ import { forEach } from "./forEach.js";
10
+ import { head } from "./head.js";
11
+ import { map } from "./map.js";
12
+ import { partition } from "./partition.js";
13
+ import { reduce } from "./reduce.js";
14
+ import { scan } from "./scan.js";
15
+ import { some } from "./some.js";
16
+ import { take } from "./take.js";
17
+ import { takeWhile } from "./takeWhile.js";
18
+ import { toArray } from "./toArray.js";
19
+ import { uniqBy } from "./uniqBy.js";
20
+ import { zip } from "./zip.js";
21
+ export { chunk, count, drop, dropWhile, every, filter, find, flatMap, forEach, head, map, partition, reduce, scan, some, take, takeWhile, toArray, uniqBy, zip };
@@ -0,0 +1,41 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_chunk = require("./chunk.js");
3
+ const require_count = require("./count.js");
4
+ const require_drop = require("./drop.js");
5
+ const require_dropWhile = require("./dropWhile.js");
6
+ const require_every = require("./every.js");
7
+ const require_filter = require("./filter.js");
8
+ const require_find = require("./find.js");
9
+ const require_flatMap = require("./flatMap.js");
10
+ const require_forEach = require("./forEach.js");
11
+ const require_head = require("./head.js");
12
+ const require_map = require("./map.js");
13
+ const require_partition = require("./partition.js");
14
+ const require_reduce = require("./reduce.js");
15
+ const require_scan = require("./scan.js");
16
+ const require_some = require("./some.js");
17
+ const require_take = require("./take.js");
18
+ const require_takeWhile = require("./takeWhile.js");
19
+ const require_toArray = require("./toArray.js");
20
+ const require_uniqBy = require("./uniqBy.js");
21
+ const require_zip = require("./zip.js");
22
+ exports.chunk = require_chunk.chunk;
23
+ exports.count = require_count.count;
24
+ exports.drop = require_drop.drop;
25
+ exports.dropWhile = require_dropWhile.dropWhile;
26
+ exports.every = require_every.every;
27
+ exports.filter = require_filter.filter;
28
+ exports.find = require_find.find;
29
+ exports.flatMap = require_flatMap.flatMap;
30
+ exports.forEach = require_forEach.forEach;
31
+ exports.head = require_head.head;
32
+ exports.map = require_map.map;
33
+ exports.partition = require_partition.partition;
34
+ exports.reduce = require_reduce.reduce;
35
+ exports.scan = require_scan.scan;
36
+ exports.some = require_some.some;
37
+ exports.take = require_take.take;
38
+ exports.takeWhile = require_takeWhile.takeWhile;
39
+ exports.toArray = require_toArray.toArray;
40
+ exports.uniqBy = require_uniqBy.uniqBy;
41
+ exports.zip = require_zip.zip;
@@ -0,0 +1,21 @@
1
+ import { chunk } from "./chunk.mjs";
2
+ import { count } from "./count.mjs";
3
+ import { drop } from "./drop.mjs";
4
+ import { dropWhile } from "./dropWhile.mjs";
5
+ import { every } from "./every.mjs";
6
+ import { filter } from "./filter.mjs";
7
+ import { find } from "./find.mjs";
8
+ import { flatMap } from "./flatMap.mjs";
9
+ import { forEach } from "./forEach.mjs";
10
+ import { head } from "./head.mjs";
11
+ import { map } from "./map.mjs";
12
+ import { partition } from "./partition.mjs";
13
+ import { reduce } from "./reduce.mjs";
14
+ import { scan } from "./scan.mjs";
15
+ import { some } from "./some.mjs";
16
+ import { take } from "./take.mjs";
17
+ import { takeWhile } from "./takeWhile.mjs";
18
+ import { toArray } from "./toArray.mjs";
19
+ import { uniqBy } from "./uniqBy.mjs";
20
+ import { zip } from "./zip.mjs";
21
+ export { 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 };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/some.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns truthy
4
+ * and reports whether any element matched, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.some` and stops
6
+ * pulling at the first match.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param predicate - Called with `(value, index)`; truthy short-circuits to `true`.
10
+ * @returns A function mapping an `Iterator<T>` to a boolean.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { some } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3].values(), some(x => x > 2)); // => true
17
+ */
18
+ declare function some<T>(predicate: (value: T, index: number) => unknown): (source: Iterator<T>) => boolean;
19
+ //#endregion
20
+ export { some };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/some.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns truthy
4
+ * and reports whether any element matched, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.some` and stops
6
+ * pulling at the first match.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param predicate - Called with `(value, index)`; truthy short-circuits to `true`.
10
+ * @returns A function mapping an `Iterator<T>` to a boolean.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { some } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3].values(), some(x => x > 2)); // => true
17
+ */
18
+ declare function some<T>(predicate: (value: T, index: number) => unknown): (source: Iterator<T>) => boolean;
19
+ //#endregion
20
+ export { some };
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/some.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns truthy
4
+ * and reports whether any element matched, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.some` and stops
6
+ * pulling at the first match.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param predicate - Called with `(value, index)`; truthy short-circuits to `true`.
10
+ * @returns A function mapping an `Iterator<T>` to a boolean.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { some } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3].values(), some(x => x > 2)); // => true
17
+ */
18
+ function some(predicate) {
19
+ return function someInIterator(source) {
20
+ return Iterator.from(source).some(predicate);
21
+ };
22
+ }
23
+ //#endregion
24
+ exports.some = some;
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/some.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns truthy
4
+ * and reports whether any element matched, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.some` and stops
6
+ * pulling at the first match.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param predicate - Called with `(value, index)`; truthy short-circuits to `true`.
10
+ * @returns A function mapping an `Iterator<T>` to a boolean.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { some } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3].values(), some(x => x > 2)); // => true
17
+ */
18
+ function some(predicate) {
19
+ return function someInIterator(source) {
20
+ return Iterator.from(source).some(predicate);
21
+ };
22
+ }
23
+ //#endregion
24
+ export { some };
@@ -0,0 +1,21 @@
1
+ //#region src/fp/iterator/take.d.ts
2
+ /**
3
+ * Creates a function that lazily yields the first `limit` elements of an
4
+ * iterator, for use with {@link pipe}. It delegates to the native
5
+ * `Iterator.prototype.take`, which stops pulling from the source once `limit`
6
+ * elements have been produced.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param limit - The number of elements to take; must be a non-negative integer.
10
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
11
+ * @throws {RangeError} Throws if `limit` is negative or `NaN` (native behavior).
12
+ *
13
+ * @example
14
+ * import { pipe } from 'es-toolkit/fp';
15
+ * import { take } from 'es-toolkit/fp/iterator';
16
+ *
17
+ * pipe([1, 2, 3, 4, 5].values(), take(3)).toArray(); // => [1, 2, 3]
18
+ */
19
+ declare function take<T>(limit: number): (source: Iterator<T>) => IteratorObject<T, undefined>;
20
+ //#endregion
21
+ export { take };
@@ -0,0 +1,21 @@
1
+ //#region src/fp/iterator/take.d.ts
2
+ /**
3
+ * Creates a function that lazily yields the first `limit` elements of an
4
+ * iterator, for use with {@link pipe}. It delegates to the native
5
+ * `Iterator.prototype.take`, which stops pulling from the source once `limit`
6
+ * elements have been produced.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param limit - The number of elements to take; must be a non-negative integer.
10
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
11
+ * @throws {RangeError} Throws if `limit` is negative or `NaN` (native behavior).
12
+ *
13
+ * @example
14
+ * import { pipe } from 'es-toolkit/fp';
15
+ * import { take } from 'es-toolkit/fp/iterator';
16
+ *
17
+ * pipe([1, 2, 3, 4, 5].values(), take(3)).toArray(); // => [1, 2, 3]
18
+ */
19
+ declare function take<T>(limit: number): (source: Iterator<T>) => IteratorObject<T, undefined>;
20
+ //#endregion
21
+ export { take };