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