synstate 1.0.1 → 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/README.md +9 -10
- package/dist/core/class/child-observable-class.d.mts.map +1 -1
- package/dist/core/class/child-observable-class.mjs +148 -140
- package/dist/core/class/child-observable-class.mjs.map +1 -1
- package/dist/core/class/observable-base-class.d.mts.map +1 -1
- package/dist/core/class/observable-base-class.mjs +111 -107
- package/dist/core/class/observable-base-class.mjs.map +1 -1
- package/dist/core/class/root-observable-class.d.mts.map +1 -1
- package/dist/core/class/root-observable-class.mjs +32 -24
- package/dist/core/class/root-observable-class.mjs.map +1 -1
- package/dist/core/combine/combine.d.mts +3 -3
- package/dist/core/combine/combine.d.mts.map +1 -1
- package/dist/core/combine/combine.mjs +31 -113
- package/dist/core/combine/combine.mjs.map +1 -1
- package/dist/core/combine/merge.d.mts +2 -2
- package/dist/core/combine/merge.d.mts.map +1 -1
- package/dist/core/combine/merge.mjs +21 -69
- package/dist/core/combine/merge.mjs.map +1 -1
- package/dist/core/combine/zip.d.mts +2 -2
- package/dist/core/combine/zip.d.mts.map +1 -1
- package/dist/core/combine/zip.mjs +34 -79
- package/dist/core/combine/zip.mjs.map +1 -1
- package/dist/core/create/counter.d.mts +1 -1
- package/dist/core/create/counter.d.mts.map +1 -1
- package/dist/core/create/counter.mjs +45 -84
- package/dist/core/create/counter.mjs.map +1 -1
- package/dist/core/create/from-abortable-promise.d.mts.map +1 -1
- package/dist/core/create/from-abortable-promise.mjs +29 -61
- package/dist/core/create/from-abortable-promise.mjs.map +1 -1
- package/dist/core/create/from-promise.d.mts.map +1 -1
- package/dist/core/create/from-promise.mjs +17 -66
- package/dist/core/create/from-promise.mjs.map +1 -1
- package/dist/core/create/from-subscribable.d.mts.map +1 -1
- package/dist/core/create/from-subscribable.mjs +18 -69
- package/dist/core/create/from-subscribable.mjs.map +1 -1
- package/dist/core/create/just.d.mts.map +1 -1
- package/dist/core/create/just.mjs +5 -35
- package/dist/core/create/just.mjs.map +1 -1
- package/dist/core/create/source.mjs +10 -13
- package/dist/core/create/source.mjs.map +1 -1
- package/dist/core/create/timer.d.mts.map +1 -1
- package/dist/core/create/timer.mjs +32 -68
- package/dist/core/create/timer.mjs.map +1 -1
- package/dist/core/operators/audit.d.mts.map +1 -1
- package/dist/core/operators/audit.mjs +39 -133
- package/dist/core/operators/audit.mjs.map +1 -1
- package/dist/core/operators/debounce.d.mts.map +1 -1
- package/dist/core/operators/debounce.mjs +36 -119
- package/dist/core/operators/debounce.mjs.map +1 -1
- package/dist/core/operators/filter.mjs +22 -25
- package/dist/core/operators/filter.mjs.map +1 -1
- package/dist/core/operators/map.d.mts.map +1 -1
- package/dist/core/operators/map.mjs +28 -61
- package/dist/core/operators/map.mjs.map +1 -1
- package/dist/core/operators/merge-map.d.mts +1 -1
- package/dist/core/operators/merge-map.d.mts.map +1 -1
- package/dist/core/operators/merge-map.mjs +34 -130
- package/dist/core/operators/merge-map.mjs.map +1 -1
- package/dist/core/operators/pairwise.d.mts +3 -2
- package/dist/core/operators/pairwise.d.mts.map +1 -1
- package/dist/core/operators/pairwise.mjs +19 -75
- package/dist/core/operators/pairwise.mjs.map +1 -1
- package/dist/core/operators/scan.d.mts.map +1 -1
- package/dist/core/operators/scan.mjs +16 -67
- package/dist/core/operators/scan.mjs.map +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
- package/dist/core/operators/skip-if-no-change.mjs +28 -92
- package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
- package/dist/core/operators/skip-until.d.mts.map +1 -1
- package/dist/core/operators/skip-until.mjs +23 -72
- package/dist/core/operators/skip-until.mjs.map +1 -1
- package/dist/core/operators/skip-while.d.mts.map +1 -1
- package/dist/core/operators/skip-while.mjs +26 -88
- package/dist/core/operators/skip-while.mjs.map +1 -1
- package/dist/core/operators/switch-map.d.mts.map +1 -1
- package/dist/core/operators/switch-map.mjs +31 -124
- package/dist/core/operators/switch-map.mjs.map +1 -1
- package/dist/core/operators/take-until.d.mts.map +1 -1
- package/dist/core/operators/take-until.mjs +28 -69
- package/dist/core/operators/take-until.mjs.map +1 -1
- package/dist/core/operators/take-while.d.mts.map +1 -1
- package/dist/core/operators/take-while.mjs +23 -83
- package/dist/core/operators/take-while.mjs.map +1 -1
- package/dist/core/operators/throttle.d.mts.map +1 -1
- package/dist/core/operators/throttle.mjs +38 -115
- package/dist/core/operators/throttle.mjs.map +1 -1
- package/dist/core/operators/with-buffered-from.d.mts +1 -1
- package/dist/core/operators/with-buffered-from.d.mts.map +1 -1
- package/dist/core/operators/with-buffered-from.mjs +37 -90
- package/dist/core/operators/with-buffered-from.mjs.map +1 -1
- package/dist/core/operators/with-current-value-from.d.mts +1 -1
- package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
- package/dist/core/operators/with-current-value-from.mjs +23 -84
- package/dist/core/operators/with-current-value-from.mjs.map +1 -1
- package/dist/core/operators/with-initial-value.d.mts.map +1 -1
- package/dist/core/operators/with-initial-value.mjs +13 -58
- package/dist/core/operators/with-initial-value.mjs.map +1 -1
- package/dist/core/predefined/operators/attach-index.d.mts +1 -1
- package/dist/core/predefined/operators/attach-index.d.mts.map +1 -1
- package/dist/core/predefined/operators/attach-index.mjs +0 -53
- package/dist/core/predefined/operators/attach-index.mjs.map +1 -1
- package/dist/core/predefined/operators/map-optional.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-optional.mjs +1 -48
- package/dist/core/predefined/operators/map-optional.mjs.map +1 -1
- package/dist/core/predefined/operators/map-result-err.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-result-err.mjs +1 -48
- package/dist/core/predefined/operators/map-result-err.mjs.map +1 -1
- package/dist/core/predefined/operators/map-result-ok.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-result-ok.mjs +1 -48
- package/dist/core/predefined/operators/map-result-ok.mjs.map +1 -1
- package/dist/core/predefined/operators/map-to.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-to.mjs +0 -40
- package/dist/core/predefined/operators/map-to.mjs.map +1 -1
- package/dist/core/predefined/operators/pluck.d.mts +1 -1
- package/dist/core/predefined/operators/pluck.d.mts.map +1 -1
- package/dist/core/predefined/operators/pluck.mjs +0 -43
- package/dist/core/predefined/operators/pluck.mjs.map +1 -1
- package/dist/core/predefined/operators/skip.d.mts.map +1 -1
- package/dist/core/predefined/operators/skip.mjs +0 -47
- package/dist/core/predefined/operators/skip.mjs.map +1 -1
- package/dist/core/predefined/operators/take.d.mts.map +1 -1
- package/dist/core/predefined/operators/take.mjs +0 -41
- package/dist/core/predefined/operators/take.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-optional.mjs +4 -43
- package/dist/core/predefined/operators/unwrap-optional.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-result-err.mjs +0 -40
- package/dist/core/predefined/operators/unwrap-result-err.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-result-ok.mjs +4 -43
- package/dist/core/predefined/operators/unwrap-result-ok.mjs.map +1 -1
- package/dist/core/types/observable-family.d.mts +10 -10
- package/dist/core/types/observable-family.d.mts.map +1 -1
- package/dist/core/types/observable.d.mts.map +1 -1
- package/dist/core/types/observable.mjs +3 -5
- package/dist/core/types/observable.mjs.map +1 -1
- package/dist/core/types/types.d.mts +2 -1
- package/dist/core/types/types.d.mts.map +1 -1
- package/dist/core/utils/id-maker.mjs +5 -6
- package/dist/core/utils/id-maker.mjs.map +1 -1
- package/dist/core/utils/max-depth.d.mts.map +1 -1
- package/dist/core/utils/max-depth.mjs +1 -3
- package/dist/core/utils/max-depth.mjs.map +1 -1
- package/dist/core/utils/observable-utils.d.mts.map +1 -1
- package/dist/core/utils/observable-utils.mjs +3 -2
- package/dist/core/utils/observable-utils.mjs.map +1 -1
- package/dist/core/utils/utils.d.mts.map +1 -1
- package/dist/core/utils/utils.mjs +23 -30
- package/dist/core/utils/utils.mjs.map +1 -1
- package/dist/utils/collect-to-array.d.mts.map +1 -1
- package/dist/utils/collect-to-array.mjs +9 -6
- package/dist/utils/collect-to-array.mjs.map +1 -1
- package/dist/utils/create-boolean-state.d.mts +1 -1
- package/dist/utils/create-boolean-state.d.mts.map +1 -1
- package/dist/utils/create-boolean-state.mjs +18 -46
- package/dist/utils/create-boolean-state.mjs.map +1 -1
- package/dist/utils/create-event-emitter.mjs +10 -64
- package/dist/utils/create-event-emitter.mjs.map +1 -1
- package/dist/utils/create-reducer.d.mts +1 -1
- package/dist/utils/create-reducer.d.mts.map +1 -1
- package/dist/utils/create-reducer.mjs +8 -52
- package/dist/utils/create-reducer.mjs.map +1 -1
- package/dist/utils/create-state.d.mts +1 -1
- package/dist/utils/create-state.d.mts.map +1 -1
- package/dist/utils/create-state.mjs +23 -53
- package/dist/utils/create-state.mjs.map +1 -1
- package/package.json +16 -16
- package/src/core/class/child-observable-class.mts +1 -1
- package/src/core/class/observable-base-class.mts +16 -16
- package/src/core/combine/combine.mts +38 -16
- package/src/core/combine/merge.mts +3 -3
- package/src/core/combine/zip.mts +24 -13
- package/src/core/create/counter.mts +11 -9
- package/src/core/create/counter.test.mts +11 -0
- package/src/core/create/timer.mts +6 -6
- package/src/core/create/timer.test.mts +11 -0
- package/src/core/operators/audit-throttle-teardown.test.mts +21 -0
- package/src/core/operators/audit.mts +6 -6
- package/src/core/operators/debounce.mts +6 -6
- package/src/core/operators/pairwise.mts +10 -5
- package/src/core/operators/skip-while.mts +1 -5
- package/src/core/operators/skip-while.test.mts +20 -0
- package/src/core/operators/throttle.mts +6 -6
- package/src/core/operators/with-buffered-from.mts +4 -4
- package/src/core/predefined/operators/map-optional.mts +1 -2
- package/src/core/predefined/operators/map-result-err.mts +1 -1
- package/src/core/predefined/operators/map-result-ok.mts +1 -1
- package/src/core/types/observable-family.mts +12 -11
- package/src/core/types/observable.mts +5 -7
- package/src/core/types/types.mts +2 -1
- package/src/core/utils/max-depth.mts +5 -1
- package/src/core/utils/utils.mts +1 -1
- package/src/utils/create-boolean-state.mts +1 -1
- package/src/utils/create-reducer.mts +1 -1
- package/src/utils/create-state.mts +1 -1
|
@@ -2,54 +2,7 @@ import { Result } from 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Transforms the error value (`Err`) of a `Result` type emitted by the source.
|
|
7
|
-
* If the value is `Err`, the mapping function is applied; if `Ok`, it remains unchanged.
|
|
8
|
-
*
|
|
9
|
-
* @template R - The Result type from the source
|
|
10
|
-
* @template E2 - The type of the mapped error value
|
|
11
|
-
* @param mapFn - A function to transform the Err value
|
|
12
|
-
* @returns An operator that maps the Err side of Result emissions
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* // Timeline:
|
|
17
|
-
* //
|
|
18
|
-
* // result$ Ok(1) Err("bad") Err("fail")
|
|
19
|
-
* // mapped$ Ok(1) Err("BAD") Err("FAIL")
|
|
20
|
-
* //
|
|
21
|
-
* // Explanation:
|
|
22
|
-
* // - mapResultErr transforms the Err value of Result emissions
|
|
23
|
-
* // - Ok values pass through unchanged
|
|
24
|
-
*
|
|
25
|
-
* const result$ = source<Result<number, string>>();
|
|
26
|
-
*
|
|
27
|
-
* const mapped$ = result$.pipe(mapResultErr((e) => e.toUpperCase()));
|
|
28
|
-
*
|
|
29
|
-
* const valueHistory: Result<number, string>[] = [];
|
|
30
|
-
*
|
|
31
|
-
* mapped$.subscribe((v) => {
|
|
32
|
-
* valueHistory.push(v);
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* result$.next(Result.ok(1));
|
|
36
|
-
*
|
|
37
|
-
* assert.deepStrictEqual(valueHistory, [Result.ok(1)]);
|
|
38
|
-
*
|
|
39
|
-
* result$.next(Result.err('bad'));
|
|
40
|
-
*
|
|
41
|
-
* assert.deepStrictEqual(valueHistory, [Result.ok(1), Result.err('BAD')]);
|
|
42
|
-
*
|
|
43
|
-
* result$.next(Result.err('fail'));
|
|
44
|
-
*
|
|
45
|
-
* assert.deepStrictEqual(valueHistory, [
|
|
46
|
-
* Result.ok(1),
|
|
47
|
-
* Result.err('BAD'),
|
|
48
|
-
* Result.err('FAIL'),
|
|
49
|
-
* ]);
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
const mapResultErr = (mapFn) => map((a) => Result.mapErr(a, mapFn));
|
|
5
|
+
const mapResultErr = (mapFn) => map(Result.mapErr(mapFn));
|
|
53
6
|
|
|
54
7
|
export { mapResultErr };
|
|
55
8
|
//# sourceMappingURL=map-result-err.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result-err.mjs","sources":["../../../../src/core/predefined/operators/map-result-err.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"map-result-err.mjs","sources":["../../../../src/core/predefined/operators/map-result-err.mts"],"sourcesContent":["import { Result, type UnknownResult } from 'ts-data-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Transforms the error value (`Err`) of a `Result` type emitted by the source.\n * If the value is `Err`, the mapping function is applied; if `Ok`, it remains unchanged.\n *\n * @template R - The Result type from the source\n * @template E2 - The type of the mapped error value\n * @param mapFn - A function to transform the Err value\n * @returns An operator that maps the Err side of Result emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // result$ Ok(1) Err(\"bad\") Err(\"fail\")\n * // mapped$ Ok(1) Err(\"BAD\") Err(\"FAIL\")\n * //\n * // Explanation:\n * // - mapResultErr transforms the Err value of Result emissions\n * // - Ok values pass through unchanged\n *\n * const result$ = source<Result<number, string>>();\n *\n * const mapped$ = result$.pipe(mapResultErr((e) => e.toUpperCase()));\n *\n * const valueHistory: Result<number, string>[] = [];\n *\n * mapped$.subscribe((v) => {\n * valueHistory.push(v);\n * });\n *\n * result$.next(Result.ok(1));\n *\n * assert.deepStrictEqual(valueHistory, [Result.ok(1)]);\n *\n * result$.next(Result.err('bad'));\n *\n * assert.deepStrictEqual(valueHistory, [Result.ok(1), Result.err('BAD')]);\n *\n * result$.next(Result.err('fail'));\n *\n * assert.deepStrictEqual(valueHistory, [\n * Result.ok(1),\n * Result.err('BAD'),\n * Result.err('FAIL'),\n * ]);\n * ```\n */\nexport const mapResultErr = <R extends UnknownResult, E2>(\n mapFn: (x: Result.UnwrapErr<R>) => E2,\n): KeepInitialValueOperator<R, Result<Result.UnwrapOk<R>, E2>> =>\n map(Result.mapErr(mapFn));\n"],"names":[],"mappings":";;;;AAmDO,MAAM,eAAe,CAC1B,KAAA,KAEA,IAAI,MAAA,CAAO,MAAA,CAAO,KAAK,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result-ok.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-result-ok.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"map-result-ok.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-result-ok.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,SAC9C,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,KACnC,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CACtC,CAAC"}
|
|
@@ -2,54 +2,7 @@ import { Result } from 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Transforms the success value (`Ok`) of a `Result` type emitted by the source.
|
|
7
|
-
* If the value is `Ok`, the mapping function is applied; if `Err`, it remains unchanged.
|
|
8
|
-
*
|
|
9
|
-
* @template R - The Result type from the source
|
|
10
|
-
* @template S2 - The type of the mapped success value
|
|
11
|
-
* @param mapFn - A function to transform the Ok value
|
|
12
|
-
* @returns An operator that maps the Ok side of Result emissions
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* // Timeline:
|
|
17
|
-
* //
|
|
18
|
-
* // result$ Ok(2) Err("e") Ok(5)
|
|
19
|
-
* // doubled$ Ok(4) Err("e") Ok(10)
|
|
20
|
-
* //
|
|
21
|
-
* // Explanation:
|
|
22
|
-
* // - mapResultOk transforms the Ok value of Result emissions
|
|
23
|
-
* // - Err values pass through unchanged
|
|
24
|
-
*
|
|
25
|
-
* const result$ = source<Result<number, string>>();
|
|
26
|
-
*
|
|
27
|
-
* const doubled$ = result$.pipe(mapResultOk((x) => x * 2));
|
|
28
|
-
*
|
|
29
|
-
* const valueHistory: Result<number, string>[] = [];
|
|
30
|
-
*
|
|
31
|
-
* doubled$.subscribe((v) => {
|
|
32
|
-
* valueHistory.push(v);
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* result$.next(Result.ok(2));
|
|
36
|
-
*
|
|
37
|
-
* assert.deepStrictEqual(valueHistory, [Result.ok(4)]);
|
|
38
|
-
*
|
|
39
|
-
* result$.next(Result.err('e'));
|
|
40
|
-
*
|
|
41
|
-
* assert.deepStrictEqual(valueHistory, [Result.ok(4), Result.err('e')]);
|
|
42
|
-
*
|
|
43
|
-
* result$.next(Result.ok(5));
|
|
44
|
-
*
|
|
45
|
-
* assert.deepStrictEqual(valueHistory, [
|
|
46
|
-
* Result.ok(4),
|
|
47
|
-
* Result.err('e'),
|
|
48
|
-
* Result.ok(10),
|
|
49
|
-
* ]);
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
const mapResultOk = (mapFn) => map((a) => Result.map(a, mapFn));
|
|
5
|
+
const mapResultOk = (mapFn) => map(Result.map(mapFn));
|
|
53
6
|
|
|
54
7
|
export { mapResultOk };
|
|
55
8
|
//# sourceMappingURL=map-result-ok.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result-ok.mjs","sources":["../../../../src/core/predefined/operators/map-result-ok.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"map-result-ok.mjs","sources":["../../../../src/core/predefined/operators/map-result-ok.mts"],"sourcesContent":["import { Result, type UnknownResult } from 'ts-data-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Transforms the success value (`Ok`) of a `Result` type emitted by the source.\n * If the value is `Ok`, the mapping function is applied; if `Err`, it remains unchanged.\n *\n * @template R - The Result type from the source\n * @template S2 - The type of the mapped success value\n * @param mapFn - A function to transform the Ok value\n * @returns An operator that maps the Ok side of Result emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // result$ Ok(2) Err(\"e\") Ok(5)\n * // doubled$ Ok(4) Err(\"e\") Ok(10)\n * //\n * // Explanation:\n * // - mapResultOk transforms the Ok value of Result emissions\n * // - Err values pass through unchanged\n *\n * const result$ = source<Result<number, string>>();\n *\n * const doubled$ = result$.pipe(mapResultOk((x) => x * 2));\n *\n * const valueHistory: Result<number, string>[] = [];\n *\n * doubled$.subscribe((v) => {\n * valueHistory.push(v);\n * });\n *\n * result$.next(Result.ok(2));\n *\n * assert.deepStrictEqual(valueHistory, [Result.ok(4)]);\n *\n * result$.next(Result.err('e'));\n *\n * assert.deepStrictEqual(valueHistory, [Result.ok(4), Result.err('e')]);\n *\n * result$.next(Result.ok(5));\n *\n * assert.deepStrictEqual(valueHistory, [\n * Result.ok(4),\n * Result.err('e'),\n * Result.ok(10),\n * ]);\n * ```\n */\nexport const mapResultOk = <R extends UnknownResult, S2>(\n mapFn: (x: Result.UnwrapOk<R>) => S2,\n): KeepInitialValueOperator<R, Result<S2, Result.UnwrapErr<R>>> =>\n map(Result.map(mapFn));\n"],"names":[],"mappings":";;;;AAmDO,MAAM,cAAc,CACzB,KAAA,KAEA,IAAI,MAAA,CAAO,GAAA,CAAI,KAAK,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-to.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-to.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"map-to.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-to.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,SAAS,CAAC,KAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAClD,CAAC"}
|
|
@@ -2,46 +2,6 @@ import 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Maps all emitted values to a constant value, ignoring the source values.
|
|
7
|
-
* Equivalent to `map(() => value)`.
|
|
8
|
-
*
|
|
9
|
-
* @template A - The type of values from the source
|
|
10
|
-
* @template B - The type of the constant value
|
|
11
|
-
* @param value - The constant value to emit
|
|
12
|
-
* @returns An operator that always emits the given constant
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* // Timeline:
|
|
17
|
-
* //
|
|
18
|
-
* // click$ MouseEvent MouseEvent MouseEvent
|
|
19
|
-
* // count$ 1 1 1
|
|
20
|
-
* //
|
|
21
|
-
* // Explanation:
|
|
22
|
-
* // - mapTo maps all emitted values to a constant value
|
|
23
|
-
* // - Ignores the source values entirely
|
|
24
|
-
* // - Useful for converting events to signals
|
|
25
|
-
*
|
|
26
|
-
* const click$ = source<string>();
|
|
27
|
-
*
|
|
28
|
-
* const one$ = click$.pipe(mapTo(1));
|
|
29
|
-
*
|
|
30
|
-
* const valueHistory: number[] = [];
|
|
31
|
-
*
|
|
32
|
-
* one$.subscribe((value) => {
|
|
33
|
-
* valueHistory.push(value);
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* click$.next('click1');
|
|
37
|
-
*
|
|
38
|
-
* click$.next('click2');
|
|
39
|
-
*
|
|
40
|
-
* click$.next('click3');
|
|
41
|
-
*
|
|
42
|
-
* assert.deepStrictEqual(valueHistory, [1, 1, 1]);
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
5
|
const mapTo = (value) => map(() => value);
|
|
46
6
|
|
|
47
7
|
export { mapTo };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-to.mjs","sources":["../../../../src/core/predefined/operators/map-to.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"map-to.mjs","sources":["../../../../src/core/predefined/operators/map-to.mts"],"sourcesContent":["import { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Maps all emitted values to a constant value, ignoring the source values.\n * Equivalent to `map(() => value)`.\n *\n * @template A - The type of values from the source\n * @template B - The type of the constant value\n * @param value - The constant value to emit\n * @returns An operator that always emits the given constant\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // click$ MouseEvent MouseEvent MouseEvent\n * // count$ 1 1 1\n * //\n * // Explanation:\n * // - mapTo maps all emitted values to a constant value\n * // - Ignores the source values entirely\n * // - Useful for converting events to signals\n *\n * const click$ = source<string>();\n *\n * const one$ = click$.pipe(mapTo(1));\n *\n * const valueHistory: number[] = [];\n *\n * one$.subscribe((value) => {\n * valueHistory.push(value);\n * });\n *\n * click$.next('click1');\n *\n * click$.next('click2');\n *\n * click$.next('click3');\n *\n * assert.deepStrictEqual(valueHistory, [1, 1, 1]);\n * ```\n */\nexport const mapTo = <A, B>(value: B): KeepInitialValueOperator<A, B> =>\n map(() => value);\n"],"names":[],"mappings":";;;;AA2CO,MAAM,KAAA,GAAQ,CAAO,KAAA,KAC1B,GAAA,CAAI,MAAM,KAAK;;;;"}
|
|
@@ -43,5 +43,5 @@ export declare const pluck: <A, K extends keyof A>(key: K) => KeepInitialValueOp
|
|
|
43
43
|
* Alias for `pluck`.
|
|
44
44
|
* @see pluck
|
|
45
45
|
*/
|
|
46
|
-
export declare const getKey:
|
|
46
|
+
export declare const getKey: typeof pluck;
|
|
47
47
|
//# sourceMappingURL=pluck.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pluck.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/pluck.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"pluck.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/pluck.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,OACnC,CAAC,KACL,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAuB,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,MAAM,cAAQ,CAAC"}
|
|
@@ -2,50 +2,7 @@ import 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Extracts a property value from each emitted object by key.
|
|
7
|
-
* Equivalent to `map(value => value[key])`.
|
|
8
|
-
*
|
|
9
|
-
* @template A - The type of the emitted object
|
|
10
|
-
* @template K - The key to extract
|
|
11
|
-
* @param key - The property key to pluck
|
|
12
|
-
* @returns An operator that emits the property value
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* // Timeline:
|
|
17
|
-
* //
|
|
18
|
-
* // user$ { name: "Alice", age: 25 } { name: "Bob", age: 30 }
|
|
19
|
-
* // name$ "Alice" "Bob"
|
|
20
|
-
* //
|
|
21
|
-
* // Explanation:
|
|
22
|
-
* // - getKey extracts a property value from each emitted object
|
|
23
|
-
* // - Equivalent to map(value => value[key])
|
|
24
|
-
*
|
|
25
|
-
* const user$ = source<Readonly<{ name: string; age: number }>>();
|
|
26
|
-
*
|
|
27
|
-
* const name$ = user$.pipe(getKey('name'));
|
|
28
|
-
*
|
|
29
|
-
* const valueHistory: string[] = [];
|
|
30
|
-
*
|
|
31
|
-
* name$.subscribe((n) => {
|
|
32
|
-
* valueHistory.push(n);
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* user$.next({ name: 'Alice', age: 25 });
|
|
36
|
-
*
|
|
37
|
-
* assert.deepStrictEqual(valueHistory, ['Alice']);
|
|
38
|
-
*
|
|
39
|
-
* user$.next({ name: 'Bob', age: 30 });
|
|
40
|
-
*
|
|
41
|
-
* assert.deepStrictEqual(valueHistory, ['Alice', 'Bob']);
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
5
|
const pluck = (key) => map((a) => a[key]);
|
|
45
|
-
/**
|
|
46
|
-
* Alias for `pluck`.
|
|
47
|
-
* @see pluck
|
|
48
|
-
*/
|
|
49
6
|
const getKey = pluck;
|
|
50
7
|
|
|
51
8
|
export { getKey, pluck };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pluck.mjs","sources":["../../../../src/core/predefined/operators/pluck.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"pluck.mjs","sources":["../../../../src/core/predefined/operators/pluck.mts"],"sourcesContent":["import { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Extracts a property value from each emitted object by key.\n * Equivalent to `map(value => value[key])`.\n *\n * @template A - The type of the emitted object\n * @template K - The key to extract\n * @param key - The property key to pluck\n * @returns An operator that emits the property value\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // user$ { name: \"Alice\", age: 25 } { name: \"Bob\", age: 30 }\n * // name$ \"Alice\" \"Bob\"\n * //\n * // Explanation:\n * // - getKey extracts a property value from each emitted object\n * // - Equivalent to map(value => value[key])\n *\n * const user$ = source<Readonly<{ name: string; age: number }>>();\n *\n * const name$ = user$.pipe(getKey('name'));\n *\n * const valueHistory: string[] = [];\n *\n * name$.subscribe((n) => {\n * valueHistory.push(n);\n * });\n *\n * user$.next({ name: 'Alice', age: 25 });\n *\n * assert.deepStrictEqual(valueHistory, ['Alice']);\n *\n * user$.next({ name: 'Bob', age: 30 });\n *\n * assert.deepStrictEqual(valueHistory, ['Alice', 'Bob']);\n * ```\n */\nexport const pluck = <A, K extends keyof A>(\n key: K,\n): KeepInitialValueOperator<A, A[K]> => map((a) => a[key]);\n\n/**\n * Alias for `pluck`.\n * @see pluck\n */\nexport const getKey = pluck;\n"],"names":[],"mappings":";;;;AA0CO,MAAM,KAAA,GAAQ,CACnB,GAAA,KACsC,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,GAAG,CAAC;AAMlD,MAAM,MAAA,GAAS;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skip.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/skip.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"skip.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/skip.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,KACjB,2BAA2B,KAC7B,wBAAwB,CAAC,CAAC,EAAE,CAAC,CACyC,CAAC"}
|
|
@@ -2,53 +2,6 @@ import { PositiveSafeInt } from 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { skipWhile } from '../../operators/skip-while.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Skips the first `n` emissions from the source observable.
|
|
7
|
-
* After `n` values are skipped, all subsequent values pass through.
|
|
8
|
-
*
|
|
9
|
-
* @template A - The type of values from the source
|
|
10
|
-
* @param n - The number of values to skip
|
|
11
|
-
* @returns An operator that skips the first n emissions
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Timeline:
|
|
16
|
-
* //
|
|
17
|
-
* // num$ 1 2 3 4 5
|
|
18
|
-
* // skipped$ 3 4 5
|
|
19
|
-
* // |skip 2|
|
|
20
|
-
* //
|
|
21
|
-
* // Explanation:
|
|
22
|
-
* // - skip ignores the first n emissions from the source
|
|
23
|
-
* // - After n values are skipped, all subsequent values pass through
|
|
24
|
-
*
|
|
25
|
-
* const num$ = source<number>();
|
|
26
|
-
*
|
|
27
|
-
* const skipped$ = num$.pipe(skip(2));
|
|
28
|
-
*
|
|
29
|
-
* const valueHistory: number[] = [];
|
|
30
|
-
*
|
|
31
|
-
* skipped$.subscribe((x) => {
|
|
32
|
-
* valueHistory.push(x);
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* num$.next(1); // skipped
|
|
36
|
-
*
|
|
37
|
-
* num$.next(2); // skipped
|
|
38
|
-
*
|
|
39
|
-
* assert.deepStrictEqual(valueHistory, []);
|
|
40
|
-
*
|
|
41
|
-
* num$.next(3); // logs: 3
|
|
42
|
-
*
|
|
43
|
-
* assert.deepStrictEqual(valueHistory, [3]);
|
|
44
|
-
*
|
|
45
|
-
* num$.next(4); // logs: 4
|
|
46
|
-
*
|
|
47
|
-
* num$.next(5); // logs: 5
|
|
48
|
-
*
|
|
49
|
-
* assert.deepStrictEqual(valueHistory, [3, 4, 5]);
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
5
|
const skip = (n) => !PositiveSafeInt.is(n) ? idFn : skipWhile((_, index) => index + 1 <= n);
|
|
53
6
|
const idFn = (value) => value;
|
|
54
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skip.mjs","sources":["../../../../src/core/predefined/operators/skip.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"skip.mjs","sources":["../../../../src/core/predefined/operators/skip.mts"],"sourcesContent":["import { PositiveSafeInt } from 'ts-data-forge';\nimport { type PositiveSafeIntWithSmallInt } from 'ts-type-forge';\nimport { skipWhile } from '../../operators/index.mjs';\nimport { type DropInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Skips the first `n` emissions from the source observable.\n * After `n` values are skipped, all subsequent values pass through.\n *\n * @template A - The type of values from the source\n * @param n - The number of values to skip\n * @returns An operator that skips the first n emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // num$ 1 2 3 4 5\n * // skipped$ 3 4 5\n * // |skip 2|\n * //\n * // Explanation:\n * // - skip ignores the first n emissions from the source\n * // - After n values are skipped, all subsequent values pass through\n *\n * const num$ = source<number>();\n *\n * const skipped$ = num$.pipe(skip(2));\n *\n * const valueHistory: number[] = [];\n *\n * skipped$.subscribe((x) => {\n * valueHistory.push(x);\n * });\n *\n * num$.next(1); // skipped\n *\n * num$.next(2); // skipped\n *\n * assert.deepStrictEqual(valueHistory, []);\n *\n * num$.next(3); // logs: 3\n *\n * assert.deepStrictEqual(valueHistory, [3]);\n *\n * num$.next(4); // logs: 4\n *\n * num$.next(5); // logs: 5\n *\n * assert.deepStrictEqual(valueHistory, [3, 4, 5]);\n * ```\n */\nexport const skip = <A,>(\n n: PositiveSafeIntWithSmallInt,\n): DropInitialValueOperator<A, A> =>\n !PositiveSafeInt.is(n) ? idFn : skipWhile((_, index) => index + 1 <= n);\n\nconst idFn = <T,>(value: T): T => value;\n"],"names":[],"mappings":";;;;AAoDO,MAAM,IAAA,GAAO,CAClB,CAAA,KAEA,CAAC,gBAAgB,EAAA,CAAG,CAAC,CAAA,GAAI,IAAA,GAAO,UAAU,CAAC,CAAA,EAAG,KAAA,KAAU,KAAA,GAAQ,KAAK,CAAC;AAExE,MAAM,IAAA,GAAO,CAAK,KAAA,KAAgB,KAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"take.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/take.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"take.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/take.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,KACjB,2BAA2B,KAC7B,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAA4C,CAAC"}
|
|
@@ -2,47 +2,6 @@ import 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { takeWhile } from '../../operators/take-while.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Takes only the first `n` emissions from the source observable, then completes.
|
|
7
|
-
*
|
|
8
|
-
* @template A - The type of values from the source
|
|
9
|
-
* @param n - The number of values to take
|
|
10
|
-
* @returns An operator that takes the first n emissions
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* // Timeline:
|
|
15
|
-
* //
|
|
16
|
-
* // num$ 1 2 3 4 (ignored)
|
|
17
|
-
* // taken$ 1 2 3 | (completes)
|
|
18
|
-
* //
|
|
19
|
-
* // Explanation:
|
|
20
|
-
* // - take emits only the first n values, then completes
|
|
21
|
-
* // - Subsequent emissions from the source are ignored
|
|
22
|
-
*
|
|
23
|
-
* const num$ = source<number>();
|
|
24
|
-
*
|
|
25
|
-
* const taken$ = num$.pipe(take(3));
|
|
26
|
-
*
|
|
27
|
-
* const valueHistory: number[] = [];
|
|
28
|
-
*
|
|
29
|
-
* taken$.subscribe((x) => {
|
|
30
|
-
* valueHistory.push(x);
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* num$.next(1);
|
|
34
|
-
*
|
|
35
|
-
* num$.next(2);
|
|
36
|
-
*
|
|
37
|
-
* num$.next(3);
|
|
38
|
-
*
|
|
39
|
-
* assert.deepStrictEqual(valueHistory, [1, 2, 3]);
|
|
40
|
-
*
|
|
41
|
-
* num$.next(4); // ignored (already completed)
|
|
42
|
-
*
|
|
43
|
-
* assert.deepStrictEqual(valueHistory, [1, 2, 3]);
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
5
|
const take = (n) => takeWhile((_, index) => index + 1 <= n);
|
|
47
6
|
|
|
48
7
|
export { take };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"take.mjs","sources":["../../../../src/core/predefined/operators/take.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"take.mjs","sources":["../../../../src/core/predefined/operators/take.mts"],"sourcesContent":["import { type PositiveSafeIntWithSmallInt } from 'ts-type-forge';\nimport { takeWhile } from '../../operators/index.mjs';\nimport { type DropInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Takes only the first `n` emissions from the source observable, then completes.\n *\n * @template A - The type of values from the source\n * @param n - The number of values to take\n * @returns An operator that takes the first n emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // num$ 1 2 3 4 (ignored)\n * // taken$ 1 2 3 | (completes)\n * //\n * // Explanation:\n * // - take emits only the first n values, then completes\n * // - Subsequent emissions from the source are ignored\n *\n * const num$ = source<number>();\n *\n * const taken$ = num$.pipe(take(3));\n *\n * const valueHistory: number[] = [];\n *\n * taken$.subscribe((x) => {\n * valueHistory.push(x);\n * });\n *\n * num$.next(1);\n *\n * num$.next(2);\n *\n * num$.next(3);\n *\n * assert.deepStrictEqual(valueHistory, [1, 2, 3]);\n *\n * num$.next(4); // ignored (already completed)\n *\n * assert.deepStrictEqual(valueHistory, [1, 2, 3]);\n * ```\n */\nexport const take = <A,>(\n n: PositiveSafeIntWithSmallInt,\n): DropInitialValueOperator<A, A> => takeWhile((_, index) => index + 1 <= n);\n"],"names":[],"mappings":";;;;AA6CO,MAAM,IAAA,GAAO,CAClB,CAAA,KACmC,SAAA,CAAU,CAAC,CAAA,EAAG,KAAA,KAAU,KAAA,GAAQ,CAAA,IAAK,CAAC;;;;"}
|
|
@@ -2,49 +2,10 @@ import { Optional } from 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @returns An operator that unwraps Optional emissions
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Timeline:
|
|
14
|
-
* //
|
|
15
|
-
* // opt$ Some(42) None Some(7)
|
|
16
|
-
* // unwrapped$ 42 undefined 7
|
|
17
|
-
* //
|
|
18
|
-
* // Explanation:
|
|
19
|
-
* // - unwrapOptional converts Some(value) to value, and None to undefined
|
|
20
|
-
* // - Useful for extracting raw values from Optional streams
|
|
21
|
-
*
|
|
22
|
-
* const opt$ = source<Optional<number>>();
|
|
23
|
-
*
|
|
24
|
-
* const unwrapped$ = opt$.pipe(unwrapOptional());
|
|
25
|
-
*
|
|
26
|
-
* const valueHistory: (number | undefined)[] = [];
|
|
27
|
-
*
|
|
28
|
-
* unwrapped$.subscribe((v) => {
|
|
29
|
-
* valueHistory.push(v);
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* opt$.next(Optional.some(42));
|
|
33
|
-
*
|
|
34
|
-
* assert.deepStrictEqual(valueHistory, [42]);
|
|
35
|
-
*
|
|
36
|
-
* opt$.next(Optional.none);
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(valueHistory, [42, undefined]);
|
|
39
|
-
*
|
|
40
|
-
* opt$.next(Optional.some(7));
|
|
41
|
-
*
|
|
42
|
-
* assert.deepStrictEqual(valueHistory, [42, undefined, 7]);
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
const unwrapOptional = () =>
|
|
46
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
47
|
-
map(Optional.unwrap);
|
|
5
|
+
const unwrapOptional = () => (
|
|
6
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
7
|
+
map(Optional.unwrap)
|
|
8
|
+
);
|
|
48
9
|
|
|
49
10
|
export { unwrapOptional };
|
|
50
11
|
//# sourceMappingURL=unwrap-optional.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unwrap-optional.mjs","sources":["../../../../src/core/predefined/operators/unwrap-optional.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"unwrap-optional.mjs","sources":["../../../../src/core/predefined/operators/unwrap-optional.mts"],"sourcesContent":["import { Optional, type UnknownOptional } from 'ts-data-forge';\nimport { type Fn } from 'ts-type-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Unwraps `Optional` values, converting `Some(value)` to `value` and `None` to `undefined`.\n *\n * @template O - The Optional type from the source\n * @returns An operator that unwraps Optional emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // opt$ Some(42) None Some(7)\n * // unwrapped$ 42 undefined 7\n * //\n * // Explanation:\n * // - unwrapOptional converts Some(value) to value, and None to undefined\n * // - Useful for extracting raw values from Optional streams\n *\n * const opt$ = source<Optional<number>>();\n *\n * const unwrapped$ = opt$.pipe(unwrapOptional());\n *\n * const valueHistory: (number | undefined)[] = [];\n *\n * unwrapped$.subscribe((v) => {\n * valueHistory.push(v);\n * });\n *\n * opt$.next(Optional.some(42));\n *\n * assert.deepStrictEqual(valueHistory, [42]);\n *\n * opt$.next(Optional.none);\n *\n * assert.deepStrictEqual(valueHistory, [42, undefined]);\n *\n * opt$.next(Optional.some(7));\n *\n * assert.deepStrictEqual(valueHistory, [42, undefined, 7]);\n * ```\n */\nexport const unwrapOptional = <\n O extends UnknownOptional,\n>(): KeepInitialValueOperator<O, Optional.Unwrap<O> | undefined> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n map(Optional.unwrap as Fn<O, Optional.Unwrap<O> | undefined>);\n"],"names":[],"mappings":";;;;AA6CO,MAAM,cAAA,GAAiB;AAAA;AAAA,EAI5B,GAAA,CAAI,SAAS,MAA+C;AAAA;;;;"}
|
|
@@ -2,46 +2,6 @@ import { Result } from 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Unwraps the error value from a `Result`, converting `Err(error)` to `error` and `Ok` to `undefined`.
|
|
7
|
-
*
|
|
8
|
-
* @template R - The Result type from the source
|
|
9
|
-
* @returns An operator that unwraps the Err side of Result emissions
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Timeline:
|
|
14
|
-
* //
|
|
15
|
-
* // result$ Ok(1) Err("fail") Ok(2)
|
|
16
|
-
* // unwrapped$ undefined "fail" undefined
|
|
17
|
-
* //
|
|
18
|
-
* // Explanation:
|
|
19
|
-
* // - unwrapResultErr converts Err(error) to error, and Ok to undefined
|
|
20
|
-
* // - Useful for extracting error values from Result streams
|
|
21
|
-
*
|
|
22
|
-
* const result$ = source<Result<number, string>>();
|
|
23
|
-
*
|
|
24
|
-
* const unwrapped$ = result$.pipe(unwrapResultErr());
|
|
25
|
-
*
|
|
26
|
-
* const valueHistory: (string | undefined)[] = [];
|
|
27
|
-
*
|
|
28
|
-
* unwrapped$.subscribe((v) => {
|
|
29
|
-
* valueHistory.push(v);
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* result$.next(Result.ok(1));
|
|
33
|
-
*
|
|
34
|
-
* assert.deepStrictEqual(valueHistory, [undefined]);
|
|
35
|
-
*
|
|
36
|
-
* result$.next(Result.err('fail'));
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(valueHistory, [undefined, 'fail']);
|
|
39
|
-
*
|
|
40
|
-
* result$.next(Result.ok(2));
|
|
41
|
-
*
|
|
42
|
-
* assert.deepStrictEqual(valueHistory, [undefined, 'fail', undefined]);
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
5
|
const unwrapResultErr = () => map(Result.unwrapErr);
|
|
46
6
|
|
|
47
7
|
export { unwrapResultErr };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unwrap-result-err.mjs","sources":["../../../../src/core/predefined/operators/unwrap-result-err.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"unwrap-result-err.mjs","sources":["../../../../src/core/predefined/operators/unwrap-result-err.mts"],"sourcesContent":["import { Result, type UnknownResult } from 'ts-data-forge';\nimport { type Fn } from 'ts-type-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Unwraps the error value from a `Result`, converting `Err(error)` to `error` and `Ok` to `undefined`.\n *\n * @template R - The Result type from the source\n * @returns An operator that unwraps the Err side of Result emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // result$ Ok(1) Err(\"fail\") Ok(2)\n * // unwrapped$ undefined \"fail\" undefined\n * //\n * // Explanation:\n * // - unwrapResultErr converts Err(error) to error, and Ok to undefined\n * // - Useful for extracting error values from Result streams\n *\n * const result$ = source<Result<number, string>>();\n *\n * const unwrapped$ = result$.pipe(unwrapResultErr());\n *\n * const valueHistory: (string | undefined)[] = [];\n *\n * unwrapped$.subscribe((v) => {\n * valueHistory.push(v);\n * });\n *\n * result$.next(Result.ok(1));\n *\n * assert.deepStrictEqual(valueHistory, [undefined]);\n *\n * result$.next(Result.err('fail'));\n *\n * assert.deepStrictEqual(valueHistory, [undefined, 'fail']);\n *\n * result$.next(Result.ok(2));\n *\n * assert.deepStrictEqual(valueHistory, [undefined, 'fail', undefined]);\n * ```\n */\nexport const unwrapResultErr = <\n R extends UnknownResult,\n>(): KeepInitialValueOperator<R, Result.UnwrapErr<R> | undefined> =>\n map(Result.unwrapErr as Fn<R, Result.UnwrapErr<R> | undefined>);\n"],"names":[],"mappings":";;;;AA6CO,MAAM,eAAA,GAAkB,MAG7B,GAAA,CAAI,MAAA,CAAO,SAAmD;;;;"}
|
|
@@ -2,49 +2,10 @@ import { Result } from 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @returns An operator that unwraps the Ok side of Result emissions
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Timeline:
|
|
14
|
-
* //
|
|
15
|
-
* // result$ Ok(42) Err("e") Ok(7)
|
|
16
|
-
* // unwrapped$ 42 undefined 7
|
|
17
|
-
* //
|
|
18
|
-
* // Explanation:
|
|
19
|
-
* // - unwrapResultOk converts Ok(value) to value, and Err to undefined
|
|
20
|
-
* // - Useful for extracting success values from Result streams
|
|
21
|
-
*
|
|
22
|
-
* const result$ = source<Result<number, string>>();
|
|
23
|
-
*
|
|
24
|
-
* const unwrapped$ = result$.pipe(unwrapResultOk());
|
|
25
|
-
*
|
|
26
|
-
* const valueHistory: (number | undefined)[] = [];
|
|
27
|
-
*
|
|
28
|
-
* unwrapped$.subscribe((v) => {
|
|
29
|
-
* valueHistory.push(v);
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* result$.next(Result.ok(42));
|
|
33
|
-
*
|
|
34
|
-
* assert.deepStrictEqual(valueHistory, [42]);
|
|
35
|
-
*
|
|
36
|
-
* result$.next(Result.err('e'));
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(valueHistory, [42, undefined]);
|
|
39
|
-
*
|
|
40
|
-
* result$.next(Result.ok(7));
|
|
41
|
-
*
|
|
42
|
-
* assert.deepStrictEqual(valueHistory, [42, undefined, 7]);
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
const unwrapResultOk = () =>
|
|
46
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
47
|
-
map(Result.unwrapOk);
|
|
5
|
+
const unwrapResultOk = () => (
|
|
6
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
7
|
+
map(Result.unwrapOk)
|
|
8
|
+
);
|
|
48
9
|
|
|
49
10
|
export { unwrapResultOk };
|
|
50
11
|
//# sourceMappingURL=unwrap-result-ok.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unwrap-result-ok.mjs","sources":["../../../../src/core/predefined/operators/unwrap-result-ok.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"unwrap-result-ok.mjs","sources":["../../../../src/core/predefined/operators/unwrap-result-ok.mts"],"sourcesContent":["import { Result, type UnknownResult } from 'ts-data-forge';\nimport { type Fn } from 'ts-type-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Unwraps the success value from a `Result`, converting `Ok(value)` to `value` and `Err` to `undefined`.\n *\n * @template R - The Result type from the source\n * @returns An operator that unwraps the Ok side of Result emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // result$ Ok(42) Err(\"e\") Ok(7)\n * // unwrapped$ 42 undefined 7\n * //\n * // Explanation:\n * // - unwrapResultOk converts Ok(value) to value, and Err to undefined\n * // - Useful for extracting success values from Result streams\n *\n * const result$ = source<Result<number, string>>();\n *\n * const unwrapped$ = result$.pipe(unwrapResultOk());\n *\n * const valueHistory: (number | undefined)[] = [];\n *\n * unwrapped$.subscribe((v) => {\n * valueHistory.push(v);\n * });\n *\n * result$.next(Result.ok(42));\n *\n * assert.deepStrictEqual(valueHistory, [42]);\n *\n * result$.next(Result.err('e'));\n *\n * assert.deepStrictEqual(valueHistory, [42, undefined]);\n *\n * result$.next(Result.ok(7));\n *\n * assert.deepStrictEqual(valueHistory, [42, undefined, 7]);\n * ```\n */\nexport const unwrapResultOk = <\n R extends UnknownResult,\n>(): KeepInitialValueOperator<R, Result.UnwrapOk<R> | undefined> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n map(Result.unwrapOk as Fn<R, Result.UnwrapOk<R> | undefined>);\n"],"names":[],"mappings":";;;;AA6CO,MAAM,cAAA,GAAiB;AAAA;AAAA,EAI5B,GAAA,CAAI,OAAO,QAAiD;AAAA;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Result } from 'ts-data-forge';
|
|
2
|
-
import { type ArrayElement, type
|
|
2
|
+
import { type ArrayElement, type FixedLengthTuple, type NonEmptyTuple, type SafeUint } from 'ts-type-forge';
|
|
3
3
|
import { type AsyncChildObservable, type InitializedObservable, type InitializedRootObservable, type InitializedSyncChildObservable, type Observable, type RootObservable, type SyncChildObservable, type Unwrap } from './observable.mjs';
|
|
4
4
|
import { type NonEmptyUnknownList } from './types.mjs';
|
|
5
5
|
export type InitializedSourceObservable<A> = Readonly<{
|
|
@@ -20,33 +20,33 @@ export type WithInitialValueOperatorObservable<A, I = A> = InitializedSyncChildO
|
|
|
20
20
|
export type ScanOperatorObservable<A, B> = InitializedSyncChildObservable<B, readonly [A]>;
|
|
21
21
|
declare namespace SynStateInternals {
|
|
22
22
|
type Cast<A> = A extends NonEmptyUnknownList ? A : never;
|
|
23
|
-
type EveryInitialized<OS extends
|
|
23
|
+
type EveryInitialized<OS extends NonEmptyTuple<Observable<unknown>>> = OS extends NonEmptyTuple<InitializedObservable<unknown>> ? true : false;
|
|
24
24
|
type IsInitialized<O> = readonly [O] extends readonly [
|
|
25
25
|
InitializedObservable<unknown>
|
|
26
26
|
] ? true : false;
|
|
27
27
|
/** Evaluates true | false as true instead of boolean */
|
|
28
28
|
type LogicalValue<B extends boolean> = readonly [B] extends readonly [true] ? true : readonly [B] extends readonly [false] ? false : true;
|
|
29
29
|
type SomeInitializedImpl<OS extends Observable<unknown>> = LogicalValue<OS extends OS ? IsInitialized<OS> : never>;
|
|
30
|
-
type SomeInitialized<OS extends
|
|
30
|
+
type SomeInitialized<OS extends NonEmptyTuple<Observable<unknown>>> = SomeInitializedImpl<OS[number]>;
|
|
31
31
|
type InitializedCombineObservableImpl<A extends NonEmptyUnknownList> = InitializedSyncChildObservable<A, A>;
|
|
32
32
|
export type CombineObservableImpl<A extends NonEmptyUnknownList> = SyncChildObservable<A, A>;
|
|
33
|
-
export type CombineObservableRefinedImpl<OS extends
|
|
33
|
+
export type CombineObservableRefinedImpl<OS extends NonEmptyTuple<Observable<unknown>>> = EveryInitialized<OS> extends true ? InitializedCombineObservableImpl<Cast<Unwrap<OS>>> : CombineObservableImpl<Unwrap<OS>>;
|
|
34
34
|
type InitializedZipObservableImpl<A extends NonEmptyUnknownList> = InitializedSyncChildObservable<A, A>;
|
|
35
35
|
export type ZipObservableImpl<A extends NonEmptyUnknownList> = SyncChildObservable<A, A>;
|
|
36
|
-
export type ZipObservableRefinedImpl<OS extends
|
|
36
|
+
export type ZipObservableRefinedImpl<OS extends NonEmptyTuple<Observable<unknown>>> = EveryInitialized<OS> extends true ? InitializedZipObservableImpl<Cast<Unwrap<OS>>> : ZipObservableImpl<Unwrap<OS>>;
|
|
37
37
|
type InitializedMergeObservableImpl<P extends NonEmptyUnknownList> = InitializedSyncChildObservable<ArrayElement<P>, P>;
|
|
38
38
|
export type MergeObservableImpl<P extends NonEmptyUnknownList> = SyncChildObservable<ArrayElement<P>, P>;
|
|
39
|
-
export type MergeObservableRefinedImpl<OS extends
|
|
39
|
+
export type MergeObservableRefinedImpl<OS extends NonEmptyTuple<Observable<unknown>>> = SomeInitialized<OS> extends true ? InitializedMergeObservableImpl<Cast<Unwrap<OS>>> : MergeObservableImpl<Unwrap<OS>>;
|
|
40
40
|
export {};
|
|
41
41
|
}
|
|
42
42
|
export type CombineObservable<A extends NonEmptyUnknownList> = SynStateInternals.CombineObservableImpl<A>;
|
|
43
|
-
export type CombineObservableRefined<OS extends
|
|
43
|
+
export type CombineObservableRefined<OS extends NonEmptyTuple<Observable<unknown>>> = SynStateInternals.CombineObservableRefinedImpl<OS>;
|
|
44
44
|
export type ZipObservable<A extends NonEmptyUnknownList> = SynStateInternals.ZipObservableImpl<A>;
|
|
45
|
-
export type ZipObservableRefined<OS extends
|
|
45
|
+
export type ZipObservableRefined<OS extends NonEmptyTuple<Observable<unknown>>> = SynStateInternals.ZipObservableRefinedImpl<OS>;
|
|
46
46
|
export type MergeObservable<A extends NonEmptyUnknownList> = SynStateInternals.MergeObservableImpl<A>;
|
|
47
|
-
export type MergeObservableRefined<OS extends
|
|
47
|
+
export type MergeObservableRefined<OS extends NonEmptyTuple<Observable<unknown>>> = SynStateInternals.MergeObservableRefinedImpl<OS>;
|
|
48
48
|
export type MapOperatorObservable<A, B> = SyncChildObservable<B, readonly [A]>;
|
|
49
|
-
export type PairwiseOperatorObservable<A> = SyncChildObservable<
|
|
49
|
+
export type PairwiseOperatorObservable<A> = SyncChildObservable<FixedLengthTuple<2, A>, readonly [A]>;
|
|
50
50
|
export type TakeWhileOperatorObservable<A> = SyncChildObservable<A, readonly [A]>;
|
|
51
51
|
export type TakeUntilOperatorObservable<A> = SyncChildObservable<A, readonly [A]>;
|
|
52
52
|
export type SkipWhileOperatorObservable<A> = SyncChildObservable<A, readonly [A]>;
|