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.
- package/dist/browser.global.js +1 -1
- package/dist/compat/function/debounce.js +1 -1
- package/dist/compat/function/debounce.mjs +1 -1
- package/dist/fp/iterator/chunk.d.mts +19 -0
- package/dist/fp/iterator/chunk.d.ts +19 -0
- package/dist/fp/iterator/chunk.js +24 -0
- package/dist/fp/iterator/chunk.mjs +24 -0
- package/dist/fp/iterator/count.d.mts +20 -0
- package/dist/fp/iterator/count.d.ts +20 -0
- package/dist/fp/iterator/count.js +25 -0
- package/dist/fp/iterator/count.mjs +25 -0
- package/dist/fp/iterator/drop.d.mts +20 -0
- package/dist/fp/iterator/drop.d.ts +20 -0
- package/dist/fp/iterator/drop.js +24 -0
- package/dist/fp/iterator/drop.mjs +24 -0
- package/dist/fp/iterator/dropWhile.d.mts +18 -0
- package/dist/fp/iterator/dropWhile.d.ts +18 -0
- package/dist/fp/iterator/dropWhile.js +23 -0
- package/dist/fp/iterator/dropWhile.mjs +23 -0
- package/dist/fp/iterator/every.d.mts +20 -0
- package/dist/fp/iterator/every.d.ts +20 -0
- package/dist/fp/iterator/every.js +24 -0
- package/dist/fp/iterator/every.mjs +24 -0
- package/dist/fp/iterator/filter.d.mts +37 -0
- package/dist/fp/iterator/filter.d.ts +37 -0
- package/dist/fp/iterator/filter.js +8 -0
- package/dist/fp/iterator/filter.mjs +8 -0
- package/dist/fp/iterator/find.d.mts +20 -0
- package/dist/fp/iterator/find.d.ts +20 -0
- package/dist/fp/iterator/find.js +24 -0
- package/dist/fp/iterator/find.mjs +24 -0
- package/dist/fp/iterator/flatMap.d.mts +20 -0
- package/dist/fp/iterator/flatMap.d.ts +20 -0
- package/dist/fp/iterator/flatMap.js +24 -0
- package/dist/fp/iterator/flatMap.mjs +24 -0
- package/dist/fp/iterator/forEach.d.mts +22 -0
- package/dist/fp/iterator/forEach.d.ts +22 -0
- package/dist/fp/iterator/forEach.js +26 -0
- package/dist/fp/iterator/forEach.mjs +26 -0
- package/dist/fp/iterator/head.d.mts +19 -0
- package/dist/fp/iterator/head.d.ts +19 -0
- package/dist/fp/iterator/head.js +24 -0
- package/dist/fp/iterator/head.mjs +24 -0
- package/dist/fp/iterator/index.d.mts +21 -0
- package/dist/fp/iterator/index.d.ts +21 -0
- package/dist/fp/iterator/index.js +41 -0
- package/dist/fp/iterator/index.mjs +21 -0
- package/dist/fp/iterator/map.d.mts +20 -0
- package/dist/fp/iterator/map.d.ts +20 -0
- package/dist/fp/iterator/map.js +24 -0
- package/dist/fp/iterator/map.mjs +24 -0
- package/dist/fp/iterator/partition.d.mts +22 -0
- package/dist/fp/iterator/partition.d.ts +22 -0
- package/dist/fp/iterator/partition.js +27 -0
- package/dist/fp/iterator/partition.mjs +27 -0
- package/dist/fp/iterator/reduce.d.mts +24 -0
- package/dist/fp/iterator/reduce.d.ts +24 -0
- package/dist/fp/iterator/reduce.js +28 -0
- package/dist/fp/iterator/reduce.mjs +28 -0
- package/dist/fp/iterator/scan.d.mts +21 -0
- package/dist/fp/iterator/scan.d.ts +21 -0
- package/dist/fp/iterator/scan.js +26 -0
- package/dist/fp/iterator/scan.mjs +26 -0
- package/dist/fp/iterator/some.d.mts +20 -0
- package/dist/fp/iterator/some.d.ts +20 -0
- package/dist/fp/iterator/some.js +24 -0
- package/dist/fp/iterator/some.mjs +24 -0
- package/dist/fp/iterator/take.d.mts +21 -0
- package/dist/fp/iterator/take.d.ts +21 -0
- package/dist/fp/iterator/take.js +25 -0
- package/dist/fp/iterator/take.mjs +25 -0
- package/dist/fp/iterator/takeWhile.d.mts +19 -0
- package/dist/fp/iterator/takeWhile.d.ts +19 -0
- package/dist/fp/iterator/takeWhile.js +24 -0
- package/dist/fp/iterator/takeWhile.mjs +24 -0
- package/dist/fp/iterator/toArray.d.mts +21 -0
- package/dist/fp/iterator/toArray.d.ts +21 -0
- package/dist/fp/iterator/toArray.js +25 -0
- package/dist/fp/iterator/toArray.mjs +25 -0
- package/dist/fp/iterator/uniqBy.d.mts +20 -0
- package/dist/fp/iterator/uniqBy.d.ts +20 -0
- package/dist/fp/iterator/uniqBy.js +25 -0
- package/dist/fp/iterator/uniqBy.mjs +25 -0
- package/dist/fp/iterator/zip.d.mts +20 -0
- package/dist/fp/iterator/zip.d.ts +20 -0
- package/dist/fp/iterator/zip.js +25 -0
- package/dist/fp/iterator/zip.mjs +25 -0
- package/dist/iterator/_internal/iterator.js +74 -0
- package/dist/iterator/_internal/iterator.mjs +74 -0
- package/dist/iterator/chunk.d.mts +21 -0
- package/dist/iterator/chunk.d.ts +21 -0
- package/dist/iterator/chunk.js +40 -0
- package/dist/iterator/chunk.mjs +40 -0
- package/dist/iterator/count.d.mts +18 -0
- package/dist/iterator/count.d.ts +18 -0
- package/dist/iterator/count.js +26 -0
- package/dist/iterator/count.mjs +26 -0
- package/dist/iterator/dropWhile.d.mts +20 -0
- package/dist/iterator/dropWhile.d.ts +20 -0
- package/dist/iterator/dropWhile.js +52 -0
- package/dist/iterator/dropWhile.mjs +52 -0
- package/dist/iterator/head.d.mts +21 -0
- package/dist/iterator/head.d.ts +21 -0
- package/dist/iterator/head.js +26 -0
- package/dist/iterator/head.mjs +26 -0
- package/dist/iterator/index.d.mts +12 -0
- package/dist/iterator/index.d.ts +12 -0
- package/dist/iterator/index.js +23 -0
- package/dist/iterator/index.mjs +12 -0
- package/dist/iterator/iterate.d.mts +20 -0
- package/dist/iterator/iterate.d.ts +20 -0
- package/dist/iterator/iterate.js +32 -0
- package/dist/iterator/iterate.mjs +32 -0
- package/dist/iterator/partition.d.mts +18 -0
- package/dist/iterator/partition.d.ts +18 -0
- package/dist/iterator/partition.js +36 -0
- package/dist/iterator/partition.mjs +36 -0
- package/dist/iterator/range.d.mts +42 -0
- package/dist/iterator/range.d.ts +42 -0
- package/dist/iterator/range.js +25 -0
- package/dist/iterator/range.mjs +25 -0
- package/dist/iterator/scan.d.mts +23 -0
- package/dist/iterator/scan.d.ts +23 -0
- package/dist/iterator/scan.js +47 -0
- package/dist/iterator/scan.mjs +47 -0
- package/dist/iterator/takeWhile.d.mts +20 -0
- package/dist/iterator/takeWhile.d.ts +20 -0
- package/dist/iterator/takeWhile.js +34 -0
- package/dist/iterator/takeWhile.mjs +34 -0
- package/dist/iterator/uniqBy.d.mts +22 -0
- package/dist/iterator/uniqBy.d.ts +22 -0
- package/dist/iterator/uniqBy.js +43 -0
- package/dist/iterator/uniqBy.mjs +43 -0
- package/dist/iterator/zip.d.mts +23 -0
- package/dist/iterator/zip.d.ts +23 -0
- package/dist/iterator/zip.js +45 -0
- package/dist/iterator/zip.mjs +45 -0
- package/fp/iterator.d.ts +1 -0
- package/fp/iterator.js +1 -0
- package/iterator.d.ts +1 -0
- package/iterator.js +1 -0
- 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,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 };
|