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,18 @@
1
+ //#region src/fp/iterator/dropWhile.d.ts
2
+ /**
3
+ * Creates a function that lazily skips elements of an iterator while `shouldDrop`
4
+ * returns truthy, then yields the rest, for use with {@link pipe}.
5
+ *
6
+ * @template T - The type of elements produced by the source iterator.
7
+ * @param shouldDrop - Called with `(value, index)`; elements are skipped while it returns truthy.
8
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
9
+ *
10
+ * @example
11
+ * import { pipe } from 'es-toolkit/fp';
12
+ * import { dropWhile, toArray } from 'es-toolkit/fp/iterator';
13
+ *
14
+ * pipe([1, 2, 3, 1].values(), dropWhile(x => x < 3), toArray()); // => [3, 1]
15
+ */
16
+ declare function dropWhile<T>(shouldDrop: (value: T, index: number) => boolean): (source: Iterator<T>) => IteratorObject<T, undefined>;
17
+ //#endregion
18
+ export { dropWhile };
@@ -0,0 +1,23 @@
1
+ const require_dropWhile = require("../../iterator/dropWhile.js");
2
+ //#region src/fp/iterator/dropWhile.ts
3
+ /**
4
+ * Creates a function that lazily skips elements of an iterator while `shouldDrop`
5
+ * returns truthy, then yields the rest, for use with {@link pipe}.
6
+ *
7
+ * @template T - The type of elements produced by the source iterator.
8
+ * @param shouldDrop - Called with `(value, index)`; elements are skipped while it returns truthy.
9
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
10
+ *
11
+ * @example
12
+ * import { pipe } from 'es-toolkit/fp';
13
+ * import { dropWhile, toArray } from 'es-toolkit/fp/iterator';
14
+ *
15
+ * pipe([1, 2, 3, 1].values(), dropWhile(x => x < 3), toArray()); // => [3, 1]
16
+ */
17
+ function dropWhile(shouldDrop) {
18
+ return function dropWhileInIterator(source) {
19
+ return require_dropWhile.dropWhile(source, shouldDrop);
20
+ };
21
+ }
22
+ //#endregion
23
+ exports.dropWhile = dropWhile;
@@ -0,0 +1,23 @@
1
+ import { dropWhile as dropWhile$1 } from "../../iterator/dropWhile.mjs";
2
+ //#region src/fp/iterator/dropWhile.ts
3
+ /**
4
+ * Creates a function that lazily skips elements of an iterator while `shouldDrop`
5
+ * returns truthy, then yields the rest, for use with {@link pipe}.
6
+ *
7
+ * @template T - The type of elements produced by the source iterator.
8
+ * @param shouldDrop - Called with `(value, index)`; elements are skipped while it returns truthy.
9
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
10
+ *
11
+ * @example
12
+ * import { pipe } from 'es-toolkit/fp';
13
+ * import { dropWhile, toArray } from 'es-toolkit/fp/iterator';
14
+ *
15
+ * pipe([1, 2, 3, 1].values(), dropWhile(x => x < 3), toArray()); // => [3, 1]
16
+ */
17
+ function dropWhile(shouldDrop) {
18
+ return function dropWhileInIterator(source) {
19
+ return dropWhile$1(source, shouldDrop);
20
+ };
21
+ }
22
+ //#endregion
23
+ export { dropWhile };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/every.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns falsy
4
+ * and reports whether every element matched, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.every` and stops
6
+ * pulling at the first non-match.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param predicate - Called with `(value, index)`; falsy short-circuits to `false`.
10
+ * @returns A function mapping an `Iterator<T>` to a boolean.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { every } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([2, 4, 6].values(), every(x => x % 2 === 0)); // => true
17
+ */
18
+ declare function every<T>(predicate: (value: T, index: number) => unknown): (source: Iterator<T>) => boolean;
19
+ //#endregion
20
+ export { every };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/every.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns falsy
4
+ * and reports whether every element matched, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.every` and stops
6
+ * pulling at the first non-match.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param predicate - Called with `(value, index)`; falsy short-circuits to `false`.
10
+ * @returns A function mapping an `Iterator<T>` to a boolean.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { every } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([2, 4, 6].values(), every(x => x % 2 === 0)); // => true
17
+ */
18
+ declare function every<T>(predicate: (value: T, index: number) => unknown): (source: Iterator<T>) => boolean;
19
+ //#endregion
20
+ export { every };
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/every.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns falsy
4
+ * and reports whether every element matched, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.every` and stops
6
+ * pulling at the first non-match.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param predicate - Called with `(value, index)`; falsy short-circuits to `false`.
10
+ * @returns A function mapping an `Iterator<T>` to a boolean.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { every } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([2, 4, 6].values(), every(x => x % 2 === 0)); // => true
17
+ */
18
+ function every(predicate) {
19
+ return function everyInIterator(source) {
20
+ return Iterator.from(source).every(predicate);
21
+ };
22
+ }
23
+ //#endregion
24
+ exports.every = every;
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/every.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns falsy
4
+ * and reports whether every element matched, for use as the terminal step of a
5
+ * {@link pipe}. It delegates to the native `Iterator.prototype.every` and stops
6
+ * pulling at the first non-match.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @param predicate - Called with `(value, index)`; falsy short-circuits to `false`.
10
+ * @returns A function mapping an `Iterator<T>` to a boolean.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { every } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([2, 4, 6].values(), every(x => x % 2 === 0)); // => true
17
+ */
18
+ function every(predicate) {
19
+ return function everyInIterator(source) {
20
+ return Iterator.from(source).every(predicate);
21
+ };
22
+ }
23
+ //#endregion
24
+ export { every };
@@ -0,0 +1,37 @@
1
+ //#region src/fp/iterator/filter.d.ts
2
+ /**
3
+ * Creates a function that lazily keeps the elements of an iterator for which
4
+ * `predicate` returns truthy, narrowing the element type when `predicate` is a
5
+ * type guard. For use with {@link pipe}. It delegates to the native
6
+ * `Iterator.prototype.filter`.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @template S - The narrowed element type when `predicate` is a type guard.
10
+ * @param predicate - Called with `(value, index)`; truthy keeps the element.
11
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<S>`.
12
+ *
13
+ * @example
14
+ * import { pipe } from 'es-toolkit/fp';
15
+ * import { filter } from 'es-toolkit/fp/iterator';
16
+ *
17
+ * pipe([1, 2, 3, 4].values(), filter(x => x % 2 === 0)).toArray(); // => [2, 4]
18
+ */
19
+ declare function filter<T, S extends T>(predicate: (value: T, index: number) => value is S): (source: Iterator<T>) => IteratorObject<S, undefined>;
20
+ /**
21
+ * Creates a function that lazily keeps the elements of an iterator for which
22
+ * `predicate` returns truthy, for use with {@link pipe}. It delegates to the
23
+ * native `Iterator.prototype.filter`.
24
+ *
25
+ * @template T - The type of elements produced by the source iterator.
26
+ * @param predicate - Called with `(value, index)`; truthy keeps the element.
27
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
28
+ *
29
+ * @example
30
+ * import { pipe } from 'es-toolkit/fp';
31
+ * import { filter } from 'es-toolkit/fp/iterator';
32
+ *
33
+ * pipe([1, 2, 3, 4].values(), filter(x => x % 2 === 0)).toArray(); // => [2, 4]
34
+ */
35
+ declare function filter<T>(predicate: (value: T, index: number) => unknown): (source: Iterator<T>) => IteratorObject<T, undefined>;
36
+ //#endregion
37
+ export { filter };
@@ -0,0 +1,37 @@
1
+ //#region src/fp/iterator/filter.d.ts
2
+ /**
3
+ * Creates a function that lazily keeps the elements of an iterator for which
4
+ * `predicate` returns truthy, narrowing the element type when `predicate` is a
5
+ * type guard. For use with {@link pipe}. It delegates to the native
6
+ * `Iterator.prototype.filter`.
7
+ *
8
+ * @template T - The type of elements produced by the source iterator.
9
+ * @template S - The narrowed element type when `predicate` is a type guard.
10
+ * @param predicate - Called with `(value, index)`; truthy keeps the element.
11
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<S>`.
12
+ *
13
+ * @example
14
+ * import { pipe } from 'es-toolkit/fp';
15
+ * import { filter } from 'es-toolkit/fp/iterator';
16
+ *
17
+ * pipe([1, 2, 3, 4].values(), filter(x => x % 2 === 0)).toArray(); // => [2, 4]
18
+ */
19
+ declare function filter<T, S extends T>(predicate: (value: T, index: number) => value is S): (source: Iterator<T>) => IteratorObject<S, undefined>;
20
+ /**
21
+ * Creates a function that lazily keeps the elements of an iterator for which
22
+ * `predicate` returns truthy, for use with {@link pipe}. It delegates to the
23
+ * native `Iterator.prototype.filter`.
24
+ *
25
+ * @template T - The type of elements produced by the source iterator.
26
+ * @param predicate - Called with `(value, index)`; truthy keeps the element.
27
+ * @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
28
+ *
29
+ * @example
30
+ * import { pipe } from 'es-toolkit/fp';
31
+ * import { filter } from 'es-toolkit/fp/iterator';
32
+ *
33
+ * pipe([1, 2, 3, 4].values(), filter(x => x % 2 === 0)).toArray(); // => [2, 4]
34
+ */
35
+ declare function filter<T>(predicate: (value: T, index: number) => unknown): (source: Iterator<T>) => IteratorObject<T, undefined>;
36
+ //#endregion
37
+ export { filter };
@@ -0,0 +1,8 @@
1
+ //#region src/fp/iterator/filter.ts
2
+ function filter(predicate) {
3
+ return function filterInIterator(source) {
4
+ return Iterator.from(source).filter(predicate);
5
+ };
6
+ }
7
+ //#endregion
8
+ exports.filter = filter;
@@ -0,0 +1,8 @@
1
+ //#region src/fp/iterator/filter.ts
2
+ function filter(predicate) {
3
+ return function filterInIterator(source) {
4
+ return Iterator.from(source).filter(predicate);
5
+ };
6
+ }
7
+ //#endregion
8
+ export { filter };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/find.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns truthy
4
+ * and returns that element (or `undefined` if none match), for use as the
5
+ * terminal step of a {@link pipe}. It delegates to the native
6
+ * `Iterator.prototype.find` and stops 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 selects the element.
10
+ * @returns A function mapping an `Iterator<T>` to the matching element or `undefined`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { find } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3, 4].values(), find(x => x > 2)); // => 3
17
+ */
18
+ declare function find<T>(predicate: (value: T, index: number) => unknown): (source: Iterator<T>) => T | undefined;
19
+ //#endregion
20
+ export { find };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/find.d.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns truthy
4
+ * and returns that element (or `undefined` if none match), for use as the
5
+ * terminal step of a {@link pipe}. It delegates to the native
6
+ * `Iterator.prototype.find` and stops 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 selects the element.
10
+ * @returns A function mapping an `Iterator<T>` to the matching element or `undefined`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { find } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3, 4].values(), find(x => x > 2)); // => 3
17
+ */
18
+ declare function find<T>(predicate: (value: T, index: number) => unknown): (source: Iterator<T>) => T | undefined;
19
+ //#endregion
20
+ export { find };
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/find.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns truthy
4
+ * and returns that element (or `undefined` if none match), for use as the
5
+ * terminal step of a {@link pipe}. It delegates to the native
6
+ * `Iterator.prototype.find` and stops 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 selects the element.
10
+ * @returns A function mapping an `Iterator<T>` to the matching element or `undefined`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { find } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3, 4].values(), find(x => x > 2)); // => 3
17
+ */
18
+ function find(predicate) {
19
+ return function findInIterator(source) {
20
+ return Iterator.from(source).find(predicate);
21
+ };
22
+ }
23
+ //#endregion
24
+ exports.find = find;
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/find.ts
2
+ /**
3
+ * Creates a function that consumes an iterator until `predicate` returns truthy
4
+ * and returns that element (or `undefined` if none match), for use as the
5
+ * terminal step of a {@link pipe}. It delegates to the native
6
+ * `Iterator.prototype.find` and stops 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 selects the element.
10
+ * @returns A function mapping an `Iterator<T>` to the matching element or `undefined`.
11
+ *
12
+ * @example
13
+ * import { pipe } from 'es-toolkit/fp';
14
+ * import { find } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2, 3, 4].values(), find(x => x > 2)); // => 3
17
+ */
18
+ function find(predicate) {
19
+ return function findInIterator(source) {
20
+ return Iterator.from(source).find(predicate);
21
+ };
22
+ }
23
+ //#endregion
24
+ export { find };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/flatMap.d.ts
2
+ /**
3
+ * Creates a function that lazily maps each element of an iterator to an iterable
4
+ * (or iterator) and flattens the results one level, for use with {@link pipe}.
5
+ * It delegates to the native `Iterator.prototype.flatMap`.
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)`; returns the iterable to flatten in.
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 { flatMap } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2].values(), flatMap(x => [x, x * 10])).toArray(); // => [1, 10, 2, 20]
17
+ */
18
+ declare function flatMap<T, U>(callback: (value: T, index: number) => Iterator<U, unknown, undefined> | Iterable<U, unknown, undefined>): (source: Iterator<T>) => IteratorObject<U, undefined>;
19
+ //#endregion
20
+ export { flatMap };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/iterator/flatMap.d.ts
2
+ /**
3
+ * Creates a function that lazily maps each element of an iterator to an iterable
4
+ * (or iterator) and flattens the results one level, for use with {@link pipe}.
5
+ * It delegates to the native `Iterator.prototype.flatMap`.
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)`; returns the iterable to flatten in.
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 { flatMap } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2].values(), flatMap(x => [x, x * 10])).toArray(); // => [1, 10, 2, 20]
17
+ */
18
+ declare function flatMap<T, U>(callback: (value: T, index: number) => Iterator<U, unknown, undefined> | Iterable<U, unknown, undefined>): (source: Iterator<T>) => IteratorObject<U, undefined>;
19
+ //#endregion
20
+ export { flatMap };
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/flatMap.ts
2
+ /**
3
+ * Creates a function that lazily maps each element of an iterator to an iterable
4
+ * (or iterator) and flattens the results one level, for use with {@link pipe}.
5
+ * It delegates to the native `Iterator.prototype.flatMap`.
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)`; returns the iterable to flatten in.
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 { flatMap } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2].values(), flatMap(x => [x, x * 10])).toArray(); // => [1, 10, 2, 20]
17
+ */
18
+ function flatMap(callback) {
19
+ return function flatMapInIterator(source) {
20
+ return Iterator.from(source).flatMap(callback);
21
+ };
22
+ }
23
+ //#endregion
24
+ exports.flatMap = flatMap;
@@ -0,0 +1,24 @@
1
+ //#region src/fp/iterator/flatMap.ts
2
+ /**
3
+ * Creates a function that lazily maps each element of an iterator to an iterable
4
+ * (or iterator) and flattens the results one level, for use with {@link pipe}.
5
+ * It delegates to the native `Iterator.prototype.flatMap`.
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)`; returns the iterable to flatten in.
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 { flatMap } from 'es-toolkit/fp/iterator';
15
+ *
16
+ * pipe([1, 2].values(), flatMap(x => [x, x * 10])).toArray(); // => [1, 10, 2, 20]
17
+ */
18
+ function flatMap(callback) {
19
+ return function flatMapInIterator(source) {
20
+ return Iterator.from(source).flatMap(callback);
21
+ };
22
+ }
23
+ //#endregion
24
+ export { flatMap };
@@ -0,0 +1,22 @@
1
+ //#region src/fp/iterator/forEach.d.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
+ declare function forEach<T>(callback: (value: T, index: number) => void): (source: Iterator<T>) => void;
21
+ //#endregion
22
+ export { forEach };
@@ -0,0 +1,22 @@
1
+ //#region src/fp/iterator/forEach.d.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
+ declare function forEach<T>(callback: (value: T, index: number) => void): (source: Iterator<T>) => void;
21
+ //#endregion
22
+ export { forEach };
@@ -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
+ exports.forEach = forEach;
@@ -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 };