es-toolkit 1.51.0-dev.2065 → 1.51.0-dev.2070
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/cartesianProduct.d.mts +23 -0
- package/dist/fp/iterator/cartesianProduct.d.ts +23 -0
- package/dist/fp/iterator/cartesianProduct.js +28 -0
- package/dist/fp/iterator/cartesianProduct.mjs +28 -0
- 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 +22 -0
- package/dist/fp/iterator/index.d.ts +22 -0
- package/dist/fp/iterator/index.js +43 -0
- package/dist/fp/iterator/index.mjs +22 -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/cartesianProduct.d.mts +33 -0
- package/dist/iterator/cartesianProduct.d.ts +33 -0
- package/dist/iterator/cartesianProduct.js +95 -0
- package/dist/iterator/cartesianProduct.mjs +95 -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 +13 -0
- package/dist/iterator/index.d.ts +13 -0
- package/dist/iterator/index.js +25 -0
- package/dist/iterator/index.mjs +13 -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,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 };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/fp/iterator/take.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
|
+
function take(limit) {
|
|
20
|
+
return function takeInIterator(source) {
|
|
21
|
+
return Iterator.from(source).take(limit);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.take = take;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/fp/iterator/take.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
|
+
function take(limit) {
|
|
20
|
+
return function takeInIterator(source) {
|
|
21
|
+
return Iterator.from(source).take(limit);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { take };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/fp/iterator/takeWhile.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that lazily yields elements of an iterator while
|
|
4
|
+
* `shouldContinue` returns truthy, stopping at the first failure, for use with
|
|
5
|
+
* {@link pipe}.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements produced by the source iterator.
|
|
8
|
+
* @param shouldContinue - Called with `(value, index)`; iteration stops once it returns falsy.
|
|
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 { takeWhile, toArray } from 'es-toolkit/fp/iterator';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3, 1].values(), takeWhile(x => x < 3), toArray()); // => [1, 2]
|
|
16
|
+
*/
|
|
17
|
+
declare function takeWhile<T>(shouldContinue: (value: T, index: number) => boolean): (source: Iterator<T>) => IteratorObject<T, undefined>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { takeWhile };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/fp/iterator/takeWhile.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that lazily yields elements of an iterator while
|
|
4
|
+
* `shouldContinue` returns truthy, stopping at the first failure, for use with
|
|
5
|
+
* {@link pipe}.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements produced by the source iterator.
|
|
8
|
+
* @param shouldContinue - Called with `(value, index)`; iteration stops once it returns falsy.
|
|
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 { takeWhile, toArray } from 'es-toolkit/fp/iterator';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3, 1].values(), takeWhile(x => x < 3), toArray()); // => [1, 2]
|
|
16
|
+
*/
|
|
17
|
+
declare function takeWhile<T>(shouldContinue: (value: T, index: number) => boolean): (source: Iterator<T>) => IteratorObject<T, undefined>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { takeWhile };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const require_takeWhile = require("../../iterator/takeWhile.js");
|
|
2
|
+
//#region src/fp/iterator/takeWhile.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that lazily yields elements of an iterator while
|
|
5
|
+
* `shouldContinue` returns truthy, stopping at the first failure, for use with
|
|
6
|
+
* {@link pipe}.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements produced by the source iterator.
|
|
9
|
+
* @param shouldContinue - Called with `(value, index)`; iteration stops once it returns falsy.
|
|
10
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
14
|
+
* import { takeWhile, toArray } from 'es-toolkit/fp/iterator';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, 2, 3, 1].values(), takeWhile(x => x < 3), toArray()); // => [1, 2]
|
|
17
|
+
*/
|
|
18
|
+
function takeWhile(shouldContinue) {
|
|
19
|
+
return function takeWhileInIterator(source) {
|
|
20
|
+
return require_takeWhile.takeWhile(source, shouldContinue);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.takeWhile = takeWhile;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { takeWhile as takeWhile$1 } from "../../iterator/takeWhile.mjs";
|
|
2
|
+
//#region src/fp/iterator/takeWhile.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that lazily yields elements of an iterator while
|
|
5
|
+
* `shouldContinue` returns truthy, stopping at the first failure, for use with
|
|
6
|
+
* {@link pipe}.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements produced by the source iterator.
|
|
9
|
+
* @param shouldContinue - Called with `(value, index)`; iteration stops once it returns falsy.
|
|
10
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
14
|
+
* import { takeWhile, toArray } from 'es-toolkit/fp/iterator';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, 2, 3, 1].values(), takeWhile(x => x < 3), toArray()); // => [1, 2]
|
|
17
|
+
*/
|
|
18
|
+
function takeWhile(shouldContinue) {
|
|
19
|
+
return function takeWhileInIterator(source) {
|
|
20
|
+
return takeWhile$1(source, shouldContinue);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { takeWhile };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fp/iterator/toArray.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that consumes an iterator and collects its elements into an
|
|
4
|
+
* array, for use as the terminal step of a {@link pipe}. It delegates to the
|
|
5
|
+
* native `Iterator.prototype.toArray`.
|
|
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
|
+
* @returns A function mapping an `Iterator<T>` to a `T[]`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
15
|
+
* import { map, toArray } from 'es-toolkit/fp/iterator';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3].values(), map(x => x * 2), toArray()); // => [2, 4, 6]
|
|
18
|
+
*/
|
|
19
|
+
declare function toArray<T>(): (source: Iterator<T>) => T[];
|
|
20
|
+
//#endregion
|
|
21
|
+
export { toArray };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fp/iterator/toArray.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that consumes an iterator and collects its elements into an
|
|
4
|
+
* array, for use as the terminal step of a {@link pipe}. It delegates to the
|
|
5
|
+
* native `Iterator.prototype.toArray`.
|
|
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
|
+
* @returns A function mapping an `Iterator<T>` to a `T[]`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
15
|
+
* import { map, toArray } from 'es-toolkit/fp/iterator';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3].values(), map(x => x * 2), toArray()); // => [2, 4, 6]
|
|
18
|
+
*/
|
|
19
|
+
declare function toArray<T>(): (source: Iterator<T>) => T[];
|
|
20
|
+
//#endregion
|
|
21
|
+
export { toArray };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/fp/iterator/toArray.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that consumes an iterator and collects its elements into an
|
|
4
|
+
* array, for use as the terminal step of a {@link pipe}. It delegates to the
|
|
5
|
+
* native `Iterator.prototype.toArray`.
|
|
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
|
+
* @returns A function mapping an `Iterator<T>` to a `T[]`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
15
|
+
* import { map, toArray } from 'es-toolkit/fp/iterator';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3].values(), map(x => x * 2), toArray()); // => [2, 4, 6]
|
|
18
|
+
*/
|
|
19
|
+
function toArray() {
|
|
20
|
+
return function toArrayInIterator(source) {
|
|
21
|
+
return Iterator.from(source).toArray();
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.toArray = toArray;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/fp/iterator/toArray.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that consumes an iterator and collects its elements into an
|
|
4
|
+
* array, for use as the terminal step of a {@link pipe}. It delegates to the
|
|
5
|
+
* native `Iterator.prototype.toArray`.
|
|
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
|
+
* @returns A function mapping an `Iterator<T>` to a `T[]`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
15
|
+
* import { map, toArray } from 'es-toolkit/fp/iterator';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3].values(), map(x => x * 2), toArray()); // => [2, 4, 6]
|
|
18
|
+
*/
|
|
19
|
+
function toArray() {
|
|
20
|
+
return function toArrayInIterator(source) {
|
|
21
|
+
return Iterator.from(source).toArray();
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { toArray };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/iterator/uniqBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that lazily yields the elements of an iterator whose mapped
|
|
4
|
+
* key has not been seen before, preserving first-occurrence order, for use with
|
|
5
|
+
* {@link pipe}. Keys are compared with SameValueZero semantics.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements produced by the source iterator.
|
|
8
|
+
* @template K - The type of the key used for comparison.
|
|
9
|
+
* @param getKey - Maps an element to the key used to detect duplicates.
|
|
10
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
14
|
+
* import { uniqBy, toArray } from 'es-toolkit/fp/iterator';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1.1, 1.2, 2.3].values(), uniqBy(Math.floor), toArray()); // => [1.1, 2.3]
|
|
17
|
+
*/
|
|
18
|
+
declare function uniqBy<T, K>(getKey: (value: T) => K): (source: Iterator<T>) => IteratorObject<T, undefined>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { uniqBy };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/iterator/uniqBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that lazily yields the elements of an iterator whose mapped
|
|
4
|
+
* key has not been seen before, preserving first-occurrence order, for use with
|
|
5
|
+
* {@link pipe}. Keys are compared with SameValueZero semantics.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements produced by the source iterator.
|
|
8
|
+
* @template K - The type of the key used for comparison.
|
|
9
|
+
* @param getKey - Maps an element to the key used to detect duplicates.
|
|
10
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
14
|
+
* import { uniqBy, toArray } from 'es-toolkit/fp/iterator';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1.1, 1.2, 2.3].values(), uniqBy(Math.floor), toArray()); // => [1.1, 2.3]
|
|
17
|
+
*/
|
|
18
|
+
declare function uniqBy<T, K>(getKey: (value: T) => K): (source: Iterator<T>) => IteratorObject<T, undefined>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { uniqBy };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_uniqBy = require("../../iterator/uniqBy.js");
|
|
2
|
+
//#region src/fp/iterator/uniqBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that lazily yields the elements of an iterator whose mapped
|
|
5
|
+
* key has not been seen before, preserving first-occurrence order, for use with
|
|
6
|
+
* {@link pipe}. Keys are compared with SameValueZero semantics.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements produced by the source iterator.
|
|
9
|
+
* @template K - The type of the key used for comparison.
|
|
10
|
+
* @param getKey - Maps an element to the key used to detect duplicates.
|
|
11
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
15
|
+
* import { uniqBy, toArray } from 'es-toolkit/fp/iterator';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1.1, 1.2, 2.3].values(), uniqBy(Math.floor), toArray()); // => [1.1, 2.3]
|
|
18
|
+
*/
|
|
19
|
+
function uniqBy(getKey) {
|
|
20
|
+
return function uniqByInIterator(source) {
|
|
21
|
+
return require_uniqBy.uniqBy(source, getKey);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.uniqBy = uniqBy;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { uniqBy as uniqBy$1 } from "../../iterator/uniqBy.mjs";
|
|
2
|
+
//#region src/fp/iterator/uniqBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that lazily yields the elements of an iterator whose mapped
|
|
5
|
+
* key has not been seen before, preserving first-occurrence order, for use with
|
|
6
|
+
* {@link pipe}. Keys are compared with SameValueZero semantics.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements produced by the source iterator.
|
|
9
|
+
* @template K - The type of the key used for comparison.
|
|
10
|
+
* @param getKey - Maps an element to the key used to detect duplicates.
|
|
11
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<T>`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
15
|
+
* import { uniqBy, toArray } from 'es-toolkit/fp/iterator';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1.1, 1.2, 2.3].values(), uniqBy(Math.floor), toArray()); // => [1.1, 2.3]
|
|
18
|
+
*/
|
|
19
|
+
function uniqBy(getKey) {
|
|
20
|
+
return function uniqByInIterator(source) {
|
|
21
|
+
return uniqBy$1(source, getKey);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { uniqBy };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/iterator/zip.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that lazily pairs the elements of the piped iterator with
|
|
4
|
+
* those of `other`, for use with {@link pipe}. Iteration stops as soon as either
|
|
5
|
+
* iterator is exhausted.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements produced by the piped iterator.
|
|
8
|
+
* @template U - The type of elements produced by `other`.
|
|
9
|
+
* @param other - The iterator to pair with the piped one.
|
|
10
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<[T, U]>`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
14
|
+
* import { zip, toArray } from 'es-toolkit/fp/iterator';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, 2, 3].values(), zip(['a', 'b'].values()), toArray()); // => [[1, 'a'], [2, 'b']]
|
|
17
|
+
*/
|
|
18
|
+
declare function zip<T, U>(other: Iterator<U>): (source: Iterator<T>) => IteratorObject<[T, U], undefined>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { zip };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/iterator/zip.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that lazily pairs the elements of the piped iterator with
|
|
4
|
+
* those of `other`, for use with {@link pipe}. Iteration stops as soon as either
|
|
5
|
+
* iterator is exhausted.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements produced by the piped iterator.
|
|
8
|
+
* @template U - The type of elements produced by `other`.
|
|
9
|
+
* @param other - The iterator to pair with the piped one.
|
|
10
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<[T, U]>`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
14
|
+
* import { zip, toArray } from 'es-toolkit/fp/iterator';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, 2, 3].values(), zip(['a', 'b'].values()), toArray()); // => [[1, 'a'], [2, 'b']]
|
|
17
|
+
*/
|
|
18
|
+
declare function zip<T, U>(other: Iterator<U>): (source: Iterator<T>) => IteratorObject<[T, U], undefined>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { zip };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_zip = require("../../iterator/zip.js");
|
|
2
|
+
//#region src/fp/iterator/zip.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that lazily pairs the elements of the piped iterator with
|
|
5
|
+
* those of `other`, for use with {@link pipe}. Iteration stops as soon as either
|
|
6
|
+
* iterator is exhausted.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements produced by the piped iterator.
|
|
9
|
+
* @template U - The type of elements produced by `other`.
|
|
10
|
+
* @param other - The iterator to pair with the piped one.
|
|
11
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<[T, U]>`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
15
|
+
* import { zip, toArray } from 'es-toolkit/fp/iterator';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3].values(), zip(['a', 'b'].values()), toArray()); // => [[1, 'a'], [2, 'b']]
|
|
18
|
+
*/
|
|
19
|
+
function zip(other) {
|
|
20
|
+
return function zipInIterator(source) {
|
|
21
|
+
return require_zip.zip(source, other);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.zip = zip;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { zip as zip$1 } from "../../iterator/zip.mjs";
|
|
2
|
+
//#region src/fp/iterator/zip.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that lazily pairs the elements of the piped iterator with
|
|
5
|
+
* those of `other`, for use with {@link pipe}. Iteration stops as soon as either
|
|
6
|
+
* iterator is exhausted.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements produced by the piped iterator.
|
|
9
|
+
* @template U - The type of elements produced by `other`.
|
|
10
|
+
* @param other - The iterator to pair with the piped one.
|
|
11
|
+
* @returns A function mapping an `Iterator<T>` to a lazy `IteratorObject<[T, U]>`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { pipe } from 'es-toolkit/fp';
|
|
15
|
+
* import { zip, toArray } from 'es-toolkit/fp/iterator';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3].values(), zip(['a', 'b'].values()), toArray()); // => [[1, 'a'], [2, 'b']]
|
|
18
|
+
*/
|
|
19
|
+
function zip(other) {
|
|
20
|
+
return function zipInIterator(source) {
|
|
21
|
+
return zip$1(source, other);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { zip };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//#region src/iterator/_internal/iterator.ts
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a `next` function into a lazy {@link IteratorObject} whose prototype is
|
|
4
|
+
* the native `Iterator.prototype`. The result therefore behaves exactly like a
|
|
5
|
+
* value returned by a built-in iterator helper (e.g. `array.values().map(...)`):
|
|
6
|
+
* it is single-shot, it is iterable via `Symbol.iterator` (returning itself),
|
|
7
|
+
* and it carries every native helper method (`map`, `filter`, `take`, `drop`,
|
|
8
|
+
* `flatMap`, `reduce`, `toArray`, ...) so results can be chained with them.
|
|
9
|
+
*
|
|
10
|
+
* The result also follows the IteratorClose protocol of the native helpers, so
|
|
11
|
+
* upstream resources (e.g. `try/finally` blocks in generator sources) are
|
|
12
|
+
* released. `onClose` runs exactly once, at whichever of these happens first:
|
|
13
|
+
* the consumer terminates early (`return()`, e.g. from `take` or a `for...of`
|
|
14
|
+
* `break`), `next` throws, or `next` reports done. After the iterator is
|
|
15
|
+
* closed, `next` is never called again and every subsequent step is done.
|
|
16
|
+
*
|
|
17
|
+
* Using a hand-rolled `next` rather than a generator function is a deliberate
|
|
18
|
+
* performance choice — driving the iterator protocol directly measured roughly
|
|
19
|
+
* twice as fast as `yield`-based generators for the same transforms, while
|
|
20
|
+
* `Object.create(Iterator.prototype)` adds no measurable overhead over a plain
|
|
21
|
+
* object literal.
|
|
22
|
+
*
|
|
23
|
+
* @template T - The type of values produced by the iterator.
|
|
24
|
+
* @param next - Called to produce each step; return `{ done: true, value: undefined }` to finish.
|
|
25
|
+
* @param onClose - Called once when the iterator closes; use it to close upstream iterators.
|
|
26
|
+
* @returns A lazy {@link IteratorObject} that yields the values produced by `next`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* function repeat<T>(value: T, times: number): IteratorObject<T, undefined> {
|
|
30
|
+
* let remaining = times;
|
|
31
|
+
* return iterator(function () {
|
|
32
|
+
* if (remaining <= 0) {
|
|
33
|
+
* return { value: undefined, done: true };
|
|
34
|
+
* }
|
|
35
|
+
* remaining--;
|
|
36
|
+
* return { value, done: false };
|
|
37
|
+
* });
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
function iterator(next, onClose) {
|
|
41
|
+
let closed = false;
|
|
42
|
+
const close = () => {
|
|
43
|
+
if (!closed) {
|
|
44
|
+
closed = true;
|
|
45
|
+
onClose?.();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const result = Object.create(Iterator.prototype);
|
|
49
|
+
result.next = function() {
|
|
50
|
+
if (closed) return {
|
|
51
|
+
value: void 0,
|
|
52
|
+
done: true
|
|
53
|
+
};
|
|
54
|
+
let step;
|
|
55
|
+
try {
|
|
56
|
+
step = next();
|
|
57
|
+
} catch (error) {
|
|
58
|
+
close();
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
if (step.done) close();
|
|
62
|
+
return step;
|
|
63
|
+
};
|
|
64
|
+
result.return = function() {
|
|
65
|
+
close();
|
|
66
|
+
return {
|
|
67
|
+
value: void 0,
|
|
68
|
+
done: true
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.iterator = iterator;
|