@rimbu/common 1.1.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/bun/async-optlazy.mts +18 -5
  2. package/dist/bun/internal.mts +0 -2
  3. package/dist/bun/optlazy.mts +12 -3
  4. package/dist/cjs/async-optlazy.cjs +60 -42
  5. package/dist/cjs/async-optlazy.cjs.map +1 -0
  6. package/dist/cjs/async-optlazy.d.cts +46 -0
  7. package/dist/cjs/collect.cjs +9 -31
  8. package/dist/cjs/collect.cjs.map +1 -0
  9. package/dist/cjs/collect.d.cts +29 -0
  10. package/dist/cjs/comp.cjs +519 -1598
  11. package/dist/cjs/comp.cjs.map +1 -0
  12. package/dist/cjs/comp.d.cts +239 -0
  13. package/dist/cjs/eq.cjs +375 -203
  14. package/dist/cjs/eq.cjs.map +1 -0
  15. package/dist/cjs/err.cjs +57 -50
  16. package/dist/cjs/err.cjs.map +1 -0
  17. package/dist/cjs/index-range.cjs +105 -109
  18. package/dist/cjs/index-range.cjs.map +1 -0
  19. package/dist/cjs/index-range.d.cts +42 -0
  20. package/dist/cjs/index.cjs +9 -1684
  21. package/dist/cjs/index.cjs.map +1 -0
  22. package/dist/cjs/index.d.cts +6 -0
  23. package/dist/cjs/internal.cjs +14 -1684
  24. package/dist/cjs/internal.cjs.map +1 -0
  25. package/dist/cjs/internal.d.cts +11 -0
  26. package/dist/cjs/optlazy.cjs +43 -36
  27. package/dist/cjs/optlazy.cjs.map +1 -0
  28. package/dist/cjs/optlazy.d.cts +42 -0
  29. package/dist/cjs/range.cjs +35 -49
  30. package/dist/cjs/range.cjs.map +1 -0
  31. package/dist/cjs/traverse-state.cjs +30 -46
  32. package/dist/cjs/traverse-state.cjs.map +1 -0
  33. package/dist/cjs/types.cjs +2 -17
  34. package/dist/cjs/types.cjs.map +1 -0
  35. package/dist/cjs/update.cjs +21 -32
  36. package/dist/cjs/update.cjs.map +1 -0
  37. package/dist/{types → esm}/async-optlazy.d.mts +10 -3
  38. package/dist/esm/async-optlazy.mjs +10 -4
  39. package/dist/esm/async-optlazy.mjs.map +1 -1
  40. package/dist/esm/comp.mjs.map +1 -1
  41. package/dist/esm/eq.d.mts +196 -0
  42. package/dist/esm/eq.mjs.map +1 -1
  43. package/dist/esm/err.d.mts +33 -0
  44. package/dist/esm/index-range.mjs.map +1 -1
  45. package/dist/{types → esm}/internal.d.mts +0 -2
  46. package/dist/esm/internal.mjs +0 -2
  47. package/dist/esm/internal.mjs.map +1 -1
  48. package/dist/{types → esm}/optlazy.d.mts +8 -2
  49. package/dist/esm/optlazy.mjs +7 -2
  50. package/dist/esm/optlazy.mjs.map +1 -1
  51. package/dist/esm/range.d.mts +35 -0
  52. package/dist/esm/range.mjs.map +1 -1
  53. package/dist/esm/traverse-state.d.mts +33 -0
  54. package/dist/esm/types.d.mts +31 -0
  55. package/dist/esm/update.d.mts +18 -0
  56. package/dist/esm/update.mjs.map +1 -1
  57. package/package.json +21 -14
  58. package/src/async-optlazy.mts +18 -5
  59. package/src/internal.mts +0 -2
  60. package/src/optlazy.mts +12 -3
  61. package/dist/bun/async-reducer.mts +0 -1157
  62. package/dist/bun/reducer.mts +0 -1025
  63. package/dist/cjs/async-reducer.cjs +0 -1621
  64. package/dist/cjs/reducer.cjs +0 -1621
  65. package/dist/esm/async-reducer.mjs +0 -638
  66. package/dist/esm/async-reducer.mjs.map +0 -1
  67. package/dist/esm/reducer.mjs +0 -669
  68. package/dist/esm/reducer.mjs.map +0 -1
  69. package/dist/types/async-reducer.d.mts +0 -542
  70. package/dist/types/reducer.d.mts +0 -542
  71. package/src/async-reducer.mts +0 -1157
  72. package/src/reducer.mts +0 -1025
  73. /package/dist/{types/eq.d.mts → cjs/eq.d.cts} +0 -0
  74. /package/dist/{types/err.d.mts → cjs/err.d.cts} +0 -0
  75. /package/dist/{types/range.d.mts → cjs/range.d.cts} +0 -0
  76. /package/dist/{types/traverse-state.d.mts → cjs/traverse-state.d.cts} +0 -0
  77. /package/dist/{types/types.d.mts → cjs/types.d.cts} +0 -0
  78. /package/dist/{types/update.d.mts → cjs/update.d.cts} +0 -0
  79. /package/dist/{types → esm}/collect.d.mts +0 -0
  80. /package/dist/{types → esm}/comp.d.mts +0 -0
  81. /package/dist/{types → esm}/index-range.d.mts +0 -0
  82. /package/dist/{types → esm}/index.d.mts +0 -0
@@ -9,13 +9,17 @@ export type MaybePromise<T> = T | Promise<T>;
9
9
  /**
10
10
  * A potentially lazy and/or asynchronous value of type T.
11
11
  * @typeparam T - the value type
12
+ * @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
12
13
  */
13
- export type AsyncOptLazy<T> = OptLazy<MaybePromise<T>>;
14
+ export type AsyncOptLazy<T, A extends any[] = []> = OptLazy<MaybePromise<T>, A>;
14
15
 
15
16
  export namespace AsyncOptLazy {
16
17
  /**
17
18
  * Returns the value or promised value contained in an `AsyncOptLazy` instance of type T.
18
19
  * @param optLazy - the `AsyncOptLazy` value of type T
20
+ * @param args - when needed, the extra arguments to pass to the lazy invocation
21
+ * @typeparam T - the value type
22
+ * @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
19
23
  * @example
20
24
  * ```ts
21
25
  * AsyncOptLazy.toMaybePromise(1) // => 1
@@ -25,14 +29,20 @@ export namespace AsyncOptLazy {
25
29
  * AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
26
30
  * ```
27
31
  */
28
- export function toMaybePromise<T>(optLazy: AsyncOptLazy<T>): MaybePromise<T> {
29
- if (optLazy instanceof Function) return optLazy();
32
+ export function toMaybePromise<T, A extends any[] = []>(
33
+ optLazy: AsyncOptLazy<T, A>,
34
+ ...args: A
35
+ ): MaybePromise<T> {
36
+ if (optLazy instanceof Function) return optLazy(...args);
30
37
  return optLazy;
31
38
  }
32
39
 
33
40
  /**
34
41
  * Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
35
42
  * @param optLazy - the `AsyncOptLazy` value of type T
43
+ * @param args - when needed, the extra arguments to pass to the lazy invocation
44
+ * @typeparam T - the value type
45
+ * @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
36
46
  * @example
37
47
  * ```ts
38
48
  * AsyncOptLazy.toPromise(1) // => Promise(1)
@@ -42,8 +52,11 @@ export namespace AsyncOptLazy {
42
52
  * AsyncOptLazy.toPromise(Promise.resolve(1)) // => Promise(1)
43
53
  * ```
44
54
  */
45
- export async function toPromise<T>(optLazy: AsyncOptLazy<T>): Promise<T> {
46
- if (optLazy instanceof Function) return optLazy();
55
+ export async function toPromise<T, A extends any[] = []>(
56
+ optLazy: AsyncOptLazy<T, A>,
57
+ ...args: A
58
+ ): Promise<T> {
59
+ if (optLazy instanceof Function) return optLazy(...args);
47
60
  return optLazy;
48
61
  }
49
62
  }
@@ -5,9 +5,7 @@ export * from './err.mts';
5
5
  export * from './index-range.mts';
6
6
  export * from './optlazy.mts';
7
7
  export * from './range.mts';
8
- export * from './reducer.mts';
9
8
  export * from './traverse-state.mts';
10
9
  export * from './types.mts';
11
10
  export * from './update.mts';
12
11
  export * from './async-optlazy.mts';
13
- export * from './async-reducer.mts';
@@ -1,12 +1,16 @@
1
1
  /**
2
2
  * A potentially lazy value of type T.
3
3
  * @typeparam T - the value type
4
+ * @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
4
5
  */
5
- export type OptLazy<T> = T | (() => T);
6
+ export type OptLazy<T, A extends any[] = []> = T | ((...args: A) => T);
6
7
 
7
8
  /**
8
9
  * Returns the value contained in an `OptLazy` instance of type T.
9
10
  * @param optLazy - the `OptLazy` value of type T
11
+ * @param args - when needed, the extra arguments to pass to the lazy invocation
12
+ * @typeparam T - the value type
13
+ * @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
10
14
  * @example
11
15
  * ```ts
12
16
  * OptLazy(1) // => 1
@@ -14,8 +18,11 @@ export type OptLazy<T> = T | (() => T);
14
18
  * OptLazy(() => () => 1) // => () => 1
15
19
  * ```
16
20
  */
17
- export function OptLazy<T>(optLazy: OptLazy<T>): T {
18
- if (optLazy instanceof Function) return optLazy();
21
+ export function OptLazy<T, A extends any[] = []>(
22
+ optLazy: OptLazy<T, A>,
23
+ ...args: A
24
+ ): T {
25
+ if (optLazy instanceof Function) return optLazy(...args);
19
26
  return optLazy;
20
27
  }
21
28
 
@@ -32,6 +39,8 @@ export type OptLazyOr<T, O> = T | ((none: O) => T | O);
32
39
  * `otherValue` if the lazy function returns it.
33
40
  * @param optLazyOr - a value or a function returning a value or otherwise the received value
34
41
  * @param otherValue - the value to return if the optLazyOr does not return its own value
42
+ * @typeparam T - the value type
43
+ * @typeparam O - the default value type
35
44
  * @example
36
45
  * ```ts
37
46
  * OptLazyOr(1, 'a') // => 1
@@ -1,44 +1,62 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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/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
- ((AsyncOptLazy2) => {
28
- function toMaybePromise(optLazy) {
29
- if (optLazy instanceof Function)
30
- return optLazy();
31
- return optLazy;
32
- }
33
- AsyncOptLazy2.toMaybePromise = toMaybePromise;
34
- async function toPromise(optLazy) {
35
- if (optLazy instanceof Function)
36
- return optLazy();
37
- return optLazy;
38
- }
39
- AsyncOptLazy2.toPromise = toPromise;
40
- })(AsyncOptLazy || (AsyncOptLazy = {}));
41
- // Annotate the CommonJS export names for ESM import in node:
42
- 0 && (module.exports = {
43
- AsyncOptLazy
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
+ }
@@ -1,33 +1,11 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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
- ((CollectFun2) => {
28
- CollectFun2.Skip = Symbol("Skip");
29
- })(CollectFun || (CollectFun = {}));
30
- // Annotate the CommonJS export names for ESM import in node:
31
- 0 && (module.exports = {
32
- CollectFun
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>;