@rimbu/common 2.0.0 → 2.0.2
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/README.md +42 -42
- package/dist/bun/err.mts +1 -1
- package/dist/cjs/async-optlazy.cjs +60 -42
- package/dist/cjs/async-optlazy.cjs.map +1 -0
- package/dist/cjs/async-optlazy.d.cts +46 -0
- package/dist/cjs/collect.cjs +9 -31
- package/dist/cjs/collect.cjs.map +1 -0
- package/dist/cjs/collect.d.cts +29 -0
- package/dist/cjs/comp.cjs +518 -707
- package/dist/cjs/comp.cjs.map +1 -0
- package/dist/cjs/comp.d.cts +239 -0
- package/dist/cjs/eq.cjs +375 -203
- package/dist/cjs/eq.cjs.map +1 -0
- package/dist/cjs/err.cjs +57 -50
- package/dist/cjs/err.cjs.map +1 -0
- package/dist/cjs/index-range.cjs +105 -109
- package/dist/cjs/index-range.cjs.map +1 -0
- package/dist/cjs/index-range.d.cts +42 -0
- package/dist/cjs/index.cjs +9 -797
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +6 -0
- package/dist/cjs/internal.cjs +14 -797
- package/dist/cjs/internal.cjs.map +1 -0
- package/dist/cjs/internal.d.cts +11 -0
- package/dist/cjs/optlazy.cjs +43 -37
- package/dist/cjs/optlazy.cjs.map +1 -0
- package/dist/cjs/range.cjs +35 -49
- package/dist/cjs/range.cjs.map +1 -0
- package/dist/cjs/traverse-state.cjs +29 -46
- package/dist/cjs/traverse-state.cjs.map +1 -0
- package/dist/cjs/types.cjs +2 -17
- package/dist/cjs/types.cjs.map +1 -0
- package/dist/cjs/update.cjs +20 -32
- package/dist/cjs/update.cjs.map +1 -0
- package/dist/esm/eq.d.mts +196 -0
- package/dist/esm/err.d.mts +33 -0
- package/dist/esm/optlazy.d.mts +42 -0
- package/dist/esm/range.d.mts +35 -0
- package/dist/esm/traverse-state.d.mts +33 -0
- package/dist/esm/types.d.mts +31 -0
- package/dist/esm/update.d.mts +18 -0
- package/package.json +19 -12
- package/src/err.mts +1 -1
- /package/dist/{types/eq.d.mts → cjs/eq.d.cts} +0 -0
- /package/dist/{types/err.d.mts → cjs/err.d.cts} +0 -0
- /package/dist/{types/optlazy.d.mts → cjs/optlazy.d.cts} +0 -0
- /package/dist/{types/range.d.mts → cjs/range.d.cts} +0 -0
- /package/dist/{types/traverse-state.d.mts → cjs/traverse-state.d.cts} +0 -0
- /package/dist/{types/types.d.mts → cjs/types.d.cts} +0 -0
- /package/dist/{types/update.d.mts → cjs/update.d.cts} +0 -0
- /package/dist/{types → esm}/async-optlazy.d.mts +0 -0
- /package/dist/{types → esm}/collect.d.mts +0 -0
- /package/dist/{types → esm}/comp.d.mts +0 -0
- /package/dist/{types → esm}/index-range.d.mts +0 -0
- /package/dist/{types → esm}/index.d.mts +0 -0
- /package/dist/{types → esm}/internal.d.mts +0 -0
package/README.md
CHANGED
|
@@ -8,62 +8,64 @@
|
|
|
8
8
|
|
|
9
9
|
# @rimbu/common
|
|
10
10
|
|
|
11
|
-
This package exports
|
|
11
|
+
Welcome to `@rimbu/common`! This package exports essential types and utilities that are widely used across various Rimbu packages. It provides a robust foundation for building efficient and reliable applications.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Overview of most important Exported Types:
|
|
14
14
|
|
|
15
|
-
| Name | Description
|
|
16
|
-
| --------------- |
|
|
17
|
-
| `CollectFun` |
|
|
18
|
-
| `Comp` |
|
|
19
|
-
| `Eq` |
|
|
20
|
-
| `Err` |
|
|
21
|
-
| `FastIterable` |
|
|
22
|
-
| `IndexRange` |
|
|
23
|
-
| `OptLazy` |
|
|
24
|
-
| `Range` |
|
|
25
|
-
| `Reducer` |
|
|
26
|
-
| `TraverseState` |
|
|
27
|
-
| `Update` |
|
|
15
|
+
| Name | Description |
|
|
16
|
+
| --------------- | ----------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `CollectFun` | Types and values used in various `collect` methods within collections. |
|
|
18
|
+
| `Comp` | Interface and default implementations of comparison functions for ordering/sorting values. |
|
|
19
|
+
| `Eq` | Interface and default implementations of equality functions for checking value equality. |
|
|
20
|
+
| `Err` | Functions to easily create error-throwing behavior as fallback values. |
|
|
21
|
+
| `FastIterable` | An `Iterable` implementation that offers better performance than standard iterables. |
|
|
22
|
+
| `IndexRange` | Utilities for selecting index ranges in indexed collections. |
|
|
23
|
+
| `OptLazy` | A utility to provide values that can optionally be lazy. |
|
|
24
|
+
| `Range` | Utility types to specify ranges for comparable types. |
|
|
25
|
+
| `Reducer` | An API to create reusable logic pieces that process data streams, which can be processed in parallel. |
|
|
26
|
+
| `TraverseState` | A utility for loops to maintain traversal state. |
|
|
27
|
+
| `Update` | A standard way to update a value. |
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
### Documentation
|
|
30
30
|
|
|
31
|
-
For complete documentation please visit the
|
|
31
|
+
For complete documentation, please visit the [Rimbu Docs](https://rimbu.org), or directly explore the [Rimbu Common API Docs](https://rimbu.org/api/rimbu/common).
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
### Try It Out
|
|
34
|
+
|
|
35
|
+
Experience `@rimbu/common` in action! [Try Out Rimbu](https://codesandbox.io/s/github/vitoke/rimbu-sandbox/tree/main?previewwindow=console&view=split&editorsize=65&moduleview=1&module=/src/index.ts) on CodeSandBox.
|
|
34
36
|
|
|
35
37
|
## Installation
|
|
36
38
|
|
|
37
39
|
### Compabitity
|
|
38
40
|
|
|
39
|
-
- [`Node
|
|
41
|
+
- [`Node` ](https://nodejs.org)
|
|
40
42
|
- [`Deno` ](https://deno.com/runtime)
|
|
41
|
-
- [`Bun
|
|
43
|
+
- [`Bun` ](https://bun.sh/)
|
|
42
44
|
- `Web` 
|
|
43
45
|
|
|
44
|
-
###
|
|
45
|
-
|
|
46
|
-
For convenience, all main types are also exported through [`@rimbu/core`](../core).
|
|
47
|
-
|
|
48
|
-
To install this package only:
|
|
49
|
-
|
|
50
|
-
For `yarn`:
|
|
46
|
+
### Package Managers
|
|
51
47
|
|
|
52
|
-
|
|
48
|
+
**Yarn:**
|
|
53
49
|
|
|
54
|
-
|
|
50
|
+
```sh
|
|
51
|
+
yarn add @rimbu/common
|
|
52
|
+
```
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
**npm:**
|
|
57
55
|
|
|
58
|
-
|
|
56
|
+
```sh
|
|
57
|
+
npm install @rimbu/common
|
|
58
|
+
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
**Bun:**
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
```sh
|
|
63
|
+
bun add @rimbu/common
|
|
64
|
+
```
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
### Deno Setup
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
Create or edit `import_map.json` in your project root:
|
|
67
69
|
|
|
68
70
|
```json
|
|
69
71
|
{
|
|
@@ -73,7 +75,7 @@ In the root folder of your project, create or edit a file called `import_map.jso
|
|
|
73
75
|
}
|
|
74
76
|
```
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
_Replace `x.y.z` with the desired version._
|
|
77
79
|
|
|
78
80
|
In this way you can use relative imports from Rimbu in your code, like so:
|
|
79
81
|
|
|
@@ -103,20 +105,18 @@ console.log(Eq.stringCaseInsentitive()('abc', 'AbC'));
|
|
|
103
105
|
|
|
104
106
|
## Author
|
|
105
107
|
|
|
106
|
-
[Arvid Nicolaas](https://github.com/vitoke)
|
|
108
|
+
Created and maintained by [Arvid Nicolaas](https://github.com/vitoke).
|
|
107
109
|
|
|
108
110
|
## Contributing
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
We welcome contributions! Please read our [Contributing guide](https://github.com/rimbu-org/rimbu/blob/main/CONTRIBUTING.md).
|
|
111
113
|
|
|
112
114
|
## Contributors
|
|
113
115
|
|
|
114
116
|
<img src = "https://contrib.rocks/image?repo=rimbu-org/rimbu"/>
|
|
115
117
|
|
|
116
|
-
|
|
118
|
+
_Made with [contributors-img](https://contrib.rocks)._
|
|
117
119
|
|
|
118
120
|
## License
|
|
119
121
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
See [LICENSE](./LICENSE) for more information.
|
|
122
|
+
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) for details.
|
package/dist/bun/err.mts
CHANGED
|
@@ -1,44 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/async-optlazy.mts
|
|
21
|
-
var async_optlazy_exports = {};
|
|
22
|
-
__export(async_optlazy_exports, {
|
|
23
|
-
AsyncOptLazy: () => AsyncOptLazy
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(async_optlazy_exports);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncOptLazy = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
26
5
|
var AsyncOptLazy;
|
|
27
|
-
((
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
6
|
+
(function (AsyncOptLazy) {
|
|
7
|
+
/**
|
|
8
|
+
* Returns the value or promised value contained in an `AsyncOptLazy` instance of type T.
|
|
9
|
+
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
10
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
11
|
+
* @typeparam T - the value type
|
|
12
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* AsyncOptLazy.toMaybePromise(1) // => 1
|
|
16
|
+
* AsyncOptLazy.toMaybePromise(() => 1) // => 1
|
|
17
|
+
* AsyncOptLazy.toMaybePromise(() => () => 1) // => () => 1
|
|
18
|
+
* AsyncOptLazy.toMaybePromise(async () => 1) // => Promise(1)
|
|
19
|
+
* AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function toMaybePromise(optLazy) {
|
|
23
|
+
var args = [];
|
|
24
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
25
|
+
args[_i - 1] = arguments[_i];
|
|
26
|
+
}
|
|
27
|
+
if (optLazy instanceof Function)
|
|
28
|
+
return optLazy.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(args), false));
|
|
29
|
+
return optLazy;
|
|
30
|
+
}
|
|
31
|
+
AsyncOptLazy.toMaybePromise = toMaybePromise;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
|
|
34
|
+
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
35
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
36
|
+
* @typeparam T - the value type
|
|
37
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* AsyncOptLazy.toPromise(1) // => Promise(1)
|
|
41
|
+
* AsyncOptLazy.toPromise(() => 1) // => Promise(1)
|
|
42
|
+
* AsyncOptLazy.toPromise(() => () => 1) // => Promise(() => 1)
|
|
43
|
+
* AsyncOptLazy.toPromise(async () => 1) // => Promise(1)
|
|
44
|
+
* AsyncOptLazy.toPromise(Promise.resolve(1)) // => Promise(1)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
function toPromise(optLazy) {
|
|
48
|
+
var args = [];
|
|
49
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
50
|
+
args[_i - 1] = arguments[_i];
|
|
51
|
+
}
|
|
52
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
53
|
+
return tslib_1.__generator(this, function (_a) {
|
|
54
|
+
if (optLazy instanceof Function)
|
|
55
|
+
return [2 /*return*/, optLazy.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(args), false))];
|
|
56
|
+
return [2 /*return*/, optLazy];
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
AsyncOptLazy.toPromise = toPromise;
|
|
61
|
+
})(AsyncOptLazy || (exports.AsyncOptLazy = AsyncOptLazy = {}));
|
|
62
|
+
//# sourceMappingURL=async-optlazy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-optlazy.cjs","sourceRoot":"","sources":["../../_cjs_prepare/async-optlazy.cts"],"names":[],"mappings":";;;;AAeA,IAAiB,YAAY,CA8C5B;AA9CD,WAAiB,YAAY;IAC3B;;;;;;;;;;;;;;OAcG;IACH,SAAgB,cAAc,CAC5B,OAA2B;QAC3B,cAAU;aAAV,UAAU,EAAV,qBAAU,EAAV,IAAU;YAAV,6BAAU;;QAEV,IAAI,OAAO,YAAY,QAAQ;YAAE,OAAO,OAAO,wDAAI,IAAI,WAAE;QACzD,OAAO,OAAO,CAAC;IACjB,CAAC;IANe,2BAAc,iBAM7B,CAAA;IAED;;;;;;;;;;;;;;OAcG;IACH,SAAsB,SAAS,CAC7B,OAA2B;QAC3B,cAAU;aAAV,UAAU,EAAV,qBAAU,EAAV,IAAU;YAAV,6BAAU;;;;gBAEV,IAAI,OAAO,YAAY,QAAQ;oBAAE,sBAAO,OAAO,wDAAI,IAAI,YAAE;gBACzD,sBAAO,OAAO,EAAC;;;KAChB;IANqB,sBAAS,YAM9B,CAAA;AACH,CAAC,EA9CgB,YAAY,4BAAZ,YAAY,QA8C5B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { OptLazy } from './internal.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* A type that is either a value T or a promise yielding a value of type T.
|
|
4
|
+
* @typeparam T - the value type
|
|
5
|
+
*/
|
|
6
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
7
|
+
/**
|
|
8
|
+
* A potentially lazy and/or asynchronous value of type T.
|
|
9
|
+
* @typeparam T - the value type
|
|
10
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
11
|
+
*/
|
|
12
|
+
export type AsyncOptLazy<T, A extends any[] = []> = OptLazy<MaybePromise<T>, A>;
|
|
13
|
+
export declare namespace AsyncOptLazy {
|
|
14
|
+
/**
|
|
15
|
+
* Returns the value or promised value contained in an `AsyncOptLazy` instance of type T.
|
|
16
|
+
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
17
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
18
|
+
* @typeparam T - the value type
|
|
19
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* AsyncOptLazy.toMaybePromise(1) // => 1
|
|
23
|
+
* AsyncOptLazy.toMaybePromise(() => 1) // => 1
|
|
24
|
+
* AsyncOptLazy.toMaybePromise(() => () => 1) // => () => 1
|
|
25
|
+
* AsyncOptLazy.toMaybePromise(async () => 1) // => Promise(1)
|
|
26
|
+
* AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function toMaybePromise<T, A extends any[] = []>(optLazy: AsyncOptLazy<T, A>, ...args: A): MaybePromise<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
|
|
32
|
+
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
33
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
34
|
+
* @typeparam T - the value type
|
|
35
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* AsyncOptLazy.toPromise(1) // => Promise(1)
|
|
39
|
+
* AsyncOptLazy.toPromise(() => 1) // => Promise(1)
|
|
40
|
+
* AsyncOptLazy.toPromise(() => () => 1) // => Promise(() => 1)
|
|
41
|
+
* AsyncOptLazy.toPromise(async () => 1) // => Promise(1)
|
|
42
|
+
* AsyncOptLazy.toPromise(Promise.resolve(1)) // => Promise(1)
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function toPromise<T, A extends any[] = []>(optLazy: AsyncOptLazy<T, A>, ...args: A): Promise<T>;
|
|
46
|
+
}
|
package/dist/cjs/collect.cjs
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/collect.mts
|
|
21
|
-
var collect_exports = {};
|
|
22
|
-
__export(collect_exports, {
|
|
23
|
-
CollectFun: () => CollectFun
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(collect_exports);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CollectFun = void 0;
|
|
26
4
|
var CollectFun;
|
|
27
|
-
((
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
5
|
+
(function (CollectFun) {
|
|
6
|
+
/**
|
|
7
|
+
* Indicates, when returned from a collect function, to skip the value.
|
|
8
|
+
*/
|
|
9
|
+
CollectFun.Skip = Symbol('Skip');
|
|
10
|
+
})(CollectFun || (exports.CollectFun = CollectFun = {}));
|
|
11
|
+
//# sourceMappingURL=collect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect.cjs","sourceRoot":"","sources":["../../_cjs_prepare/collect.cts"],"names":[],"mappings":";;;AAiBA,IAAiB,UAAU,CAU1B;AAVD,WAAiB,UAAU;IACzB;;OAEG;IACU,eAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAMrC,CAAC,EAVgB,UAAU,0BAAV,UAAU,QAU1B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MaybePromise } from './internal.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* A function used in `collect` methods to collect values from a collection. This is basically a single-pass map and filter.
|
|
4
|
+
* @param value - the input value
|
|
5
|
+
* @param index - the index of the input value
|
|
6
|
+
* @param skip - a token that can be returned to skip the value
|
|
7
|
+
* @param halt - a function that, when called, ensures no more values are passed
|
|
8
|
+
* @returns either a new value to collect, or the `skip` token indicating to skip the value
|
|
9
|
+
*/
|
|
10
|
+
export type CollectFun<T, R> = (value: T, index: number, skip: CollectFun.Skip, halt: () => void) => R | CollectFun.Skip;
|
|
11
|
+
export declare namespace CollectFun {
|
|
12
|
+
/**
|
|
13
|
+
* Indicates, when returned from a collect function, to skip the value.
|
|
14
|
+
*/
|
|
15
|
+
const Skip: unique symbol;
|
|
16
|
+
/**
|
|
17
|
+
* Indicates, when returned from a collect function, to skip the value.
|
|
18
|
+
*/
|
|
19
|
+
type Skip = typeof Skip;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A potentially asynchronous function used in `collect` methods to collect values from a collection. This is basically a single-pass map and filter.
|
|
23
|
+
* @param value - the input value
|
|
24
|
+
* @param index - the index of the input value
|
|
25
|
+
* @param skip - a token that can be returned to skip the value
|
|
26
|
+
* @param halt - a function that, when called, ensures no more values are passed
|
|
27
|
+
* @returns either a new value to collect, or the `skip` token indicating to skip the value
|
|
28
|
+
*/
|
|
29
|
+
export type AsyncCollectFun<T, R> = (value: T, index: number, skip: CollectFun.Skip, halt: () => void) => MaybePromise<R | CollectFun.Skip>;
|