@rimbu/common 1.0.0 → 2.0.0
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/bun/async-optlazy.mts +18 -5
- package/dist/bun/internal.mts +0 -2
- package/dist/bun/optlazy.mts +12 -3
- package/dist/cjs/async-optlazy.cjs +4 -4
- package/dist/cjs/comp.cjs +21 -911
- package/dist/cjs/index.cjs +23 -910
- package/dist/cjs/internal.cjs +23 -910
- package/dist/cjs/optlazy.cjs +2 -2
- package/dist/esm/async-optlazy.mjs +10 -4
- package/dist/esm/async-optlazy.mjs.map +1 -1
- package/dist/esm/comp.mjs.map +1 -1
- package/dist/esm/eq.mjs.map +1 -1
- package/dist/esm/index-range.mjs.map +1 -1
- package/dist/esm/internal.mjs +0 -2
- package/dist/esm/internal.mjs.map +1 -1
- package/dist/esm/optlazy.mjs +7 -2
- package/dist/esm/optlazy.mjs.map +1 -1
- package/dist/esm/range.mjs.map +1 -1
- package/dist/esm/update.mjs.map +1 -1
- package/dist/types/async-optlazy.d.mts +10 -3
- package/dist/types/internal.d.mts +0 -2
- package/dist/types/optlazy.d.mts +8 -2
- package/package.json +3 -3
- package/src/async-optlazy.mts +18 -5
- package/src/internal.mts +0 -2
- package/src/optlazy.mts +12 -3
- package/dist/bun/async-reducer.mts +0 -1157
- package/dist/bun/reducer.mts +0 -1025
- package/dist/cjs/async-reducer.cjs +0 -1621
- package/dist/cjs/reducer.cjs +0 -1621
- package/dist/esm/async-reducer.mjs +0 -638
- package/dist/esm/async-reducer.mjs.map +0 -1
- package/dist/esm/reducer.mjs +0 -669
- package/dist/esm/reducer.mjs.map +0 -1
- package/dist/types/async-reducer.d.mts +0 -542
- package/dist/types/reducer.d.mts +0 -542
- package/src/async-reducer.mts +0 -1157
- package/src/reducer.mts +0 -1025
|
@@ -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
|
|
29
|
-
|
|
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
|
|
46
|
-
|
|
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
|
}
|
package/dist/bun/internal.mts
CHANGED
|
@@ -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';
|
package/dist/bun/optlazy.mts
CHANGED
|
@@ -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
|
|
18
|
-
|
|
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
|
|
@@ -25,15 +25,15 @@ __export(async_optlazy_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(async_optlazy_exports);
|
|
26
26
|
var AsyncOptLazy;
|
|
27
27
|
((AsyncOptLazy2) => {
|
|
28
|
-
function toMaybePromise(optLazy) {
|
|
28
|
+
function toMaybePromise(optLazy, ...args) {
|
|
29
29
|
if (optLazy instanceof Function)
|
|
30
|
-
return optLazy();
|
|
30
|
+
return optLazy(...args);
|
|
31
31
|
return optLazy;
|
|
32
32
|
}
|
|
33
33
|
AsyncOptLazy2.toMaybePromise = toMaybePromise;
|
|
34
|
-
async function toPromise(optLazy) {
|
|
34
|
+
async function toPromise(optLazy, ...args) {
|
|
35
35
|
if (optLazy instanceof Function)
|
|
36
|
-
return optLazy();
|
|
36
|
+
return optLazy(...args);
|
|
37
37
|
return optLazy;
|
|
38
38
|
}
|
|
39
39
|
AsyncOptLazy2.toPromise = toPromise;
|