synstate 0.1.2 → 1.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 +199 -146
- package/dist/core/class/child-observable-class.d.mts.map +1 -1
- package/dist/core/class/child-observable-class.mjs +43 -10
- package/dist/core/class/child-observable-class.mjs.map +1 -1
- package/dist/core/class/observable-base-class.d.mts +4 -4
- package/dist/core/class/observable-base-class.d.mts.map +1 -1
- package/dist/core/class/observable-base-class.mjs +8 -8
- package/dist/core/class/observable-base-class.mjs.map +1 -1
- package/dist/core/class/root-observable-class.d.mts +1 -1
- package/dist/core/class/root-observable-class.d.mts.map +1 -1
- package/dist/core/class/root-observable-class.mjs +9 -9
- package/dist/core/class/root-observable-class.mjs.map +1 -1
- package/dist/core/combine/combine.d.mts +6 -6
- package/dist/core/combine/combine.mjs +11 -12
- package/dist/core/combine/combine.mjs.map +1 -1
- package/dist/core/combine/merge.d.mts +6 -6
- package/dist/core/combine/merge.mjs +9 -9
- package/dist/core/combine/merge.mjs.map +1 -1
- package/dist/core/combine/zip.d.mts +20 -19
- package/dist/core/combine/zip.d.mts.map +1 -1
- package/dist/core/combine/zip.mjs +22 -21
- package/dist/core/combine/zip.mjs.map +1 -1
- package/dist/core/create/{interval.d.mts → counter.d.mts} +14 -12
- package/dist/core/create/counter.d.mts.map +1 -0
- package/dist/core/create/{interval.mjs → counter.mjs} +21 -23
- package/dist/core/create/counter.mjs.map +1 -0
- package/dist/core/create/from-abortable-promise.d.mts +29 -0
- package/dist/core/create/from-abortable-promise.d.mts.map +1 -0
- package/dist/core/create/from-abortable-promise.mjs +70 -0
- package/dist/core/create/from-abortable-promise.mjs.map +1 -0
- package/dist/core/create/from-promise.d.mts +9 -6
- package/dist/core/create/from-promise.d.mts.map +1 -1
- package/dist/core/create/from-promise.mjs +8 -5
- package/dist/core/create/from-promise.mjs.map +1 -1
- package/dist/core/create/from-subscribable.d.mts +4 -4
- package/dist/core/create/from-subscribable.mjs +4 -4
- package/dist/core/create/index.d.mts +3 -3
- package/dist/core/create/index.d.mts.map +1 -1
- package/dist/core/create/index.mjs +4 -4
- package/dist/core/create/just.d.mts +32 -0
- package/dist/core/create/just.d.mts.map +1 -0
- package/dist/core/create/just.mjs +44 -0
- package/dist/core/create/just.mjs.map +1 -0
- package/dist/core/create/source.d.mts +7 -12
- package/dist/core/create/source.d.mts.map +1 -1
- package/dist/core/create/source.mjs +1 -6
- package/dist/core/create/source.mjs.map +1 -1
- package/dist/core/create/timer.d.mts +6 -4
- package/dist/core/create/timer.d.mts.map +1 -1
- package/dist/core/create/timer.mjs +6 -7
- package/dist/core/create/timer.mjs.map +1 -1
- package/dist/core/index.d.mts +0 -1
- package/dist/core/index.d.mts.map +1 -1
- package/dist/core/index.mjs +8 -13
- package/dist/core/index.mjs.map +1 -1
- package/dist/core/operators/audit.d.mts +97 -0
- package/dist/core/operators/audit.d.mts.map +1 -0
- package/dist/core/operators/audit.mjs +144 -0
- package/dist/core/operators/audit.mjs.map +1 -0
- package/dist/core/operators/debounce.d.mts +88 -0
- package/dist/core/operators/debounce.d.mts.map +1 -0
- package/dist/core/operators/debounce.mjs +130 -0
- package/dist/core/operators/debounce.mjs.map +1 -0
- package/dist/core/operators/filter.d.mts +5 -5
- package/dist/core/operators/filter.mjs +3 -3
- package/dist/core/operators/filter.mjs.map +1 -1
- package/dist/core/operators/index.d.mts +4 -4
- package/dist/core/operators/index.d.mts.map +1 -1
- package/dist/core/operators/index.mjs +4 -4
- package/dist/core/operators/{map-with-index.d.mts → map.d.mts} +11 -11
- package/dist/core/operators/map.d.mts.map +1 -0
- package/dist/core/operators/{map-with-index.mjs → map.mjs} +17 -17
- package/dist/core/operators/map.mjs.map +1 -0
- package/dist/core/operators/merge-map.d.mts +56 -29
- package/dist/core/operators/merge-map.d.mts.map +1 -1
- package/dist/core/operators/merge-map.mjs +58 -31
- package/dist/core/operators/merge-map.mjs.map +1 -1
- package/dist/core/operators/pairwise.d.mts +6 -6
- package/dist/core/operators/pairwise.mjs +9 -9
- package/dist/core/operators/pairwise.mjs.map +1 -1
- package/dist/core/operators/scan.d.mts +6 -6
- package/dist/core/operators/scan.mjs +9 -9
- package/dist/core/operators/scan.mjs.map +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts +20 -8
- package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
- package/dist/core/operators/skip-if-no-change.mjs +23 -11
- package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
- package/dist/core/operators/skip-until.d.mts +5 -5
- package/dist/core/operators/skip-until.mjs +8 -8
- package/dist/core/operators/skip-until.mjs.map +1 -1
- package/dist/core/operators/skip-while.d.mts +18 -8
- package/dist/core/operators/skip-while.d.mts.map +1 -1
- package/dist/core/operators/skip-while.mjs +26 -11
- package/dist/core/operators/skip-while.mjs.map +1 -1
- package/dist/core/operators/switch-map.d.mts +57 -26
- package/dist/core/operators/switch-map.d.mts.map +1 -1
- package/dist/core/operators/switch-map.mjs +59 -28
- package/dist/core/operators/switch-map.mjs.map +1 -1
- package/dist/core/operators/take-until.d.mts +5 -5
- package/dist/core/operators/take-until.mjs +8 -8
- package/dist/core/operators/take-until.mjs.map +1 -1
- package/dist/core/operators/take-while.d.mts +15 -7
- package/dist/core/operators/take-while.d.mts.map +1 -1
- package/dist/core/operators/take-while.mjs +18 -10
- package/dist/core/operators/take-while.mjs.map +1 -1
- package/dist/core/operators/throttle.d.mts +81 -0
- package/dist/core/operators/throttle.d.mts.map +1 -0
- package/dist/core/operators/throttle.mjs +126 -0
- package/dist/core/operators/throttle.mjs.map +1 -0
- package/dist/core/operators/with-buffered-from.d.mts +9 -9
- package/dist/core/operators/with-buffered-from.mjs +12 -12
- package/dist/core/operators/with-buffered-from.mjs.map +1 -1
- package/dist/core/operators/with-current-value-from.d.mts +10 -9
- package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
- package/dist/core/operators/with-current-value-from.mjs +13 -12
- package/dist/core/operators/with-current-value-from.mjs.map +1 -1
- package/dist/core/operators/with-initial-value.d.mts +5 -5
- package/dist/core/operators/with-initial-value.mjs +8 -8
- package/dist/core/operators/with-initial-value.mjs.map +1 -1
- package/dist/core/predefined/index.mjs +0 -1
- package/dist/core/predefined/index.mjs.map +1 -1
- package/dist/core/predefined/operators/attach-index.d.mts +49 -0
- package/dist/core/predefined/operators/attach-index.d.mts.map +1 -1
- package/dist/core/predefined/operators/attach-index.mjs +51 -2
- package/dist/core/predefined/operators/attach-index.mjs.map +1 -1
- package/dist/core/predefined/operators/index.d.mts +0 -1
- package/dist/core/predefined/operators/index.d.mts.map +1 -1
- package/dist/core/predefined/operators/index.mjs +0 -1
- package/dist/core/predefined/operators/index.mjs.map +1 -1
- package/dist/core/predefined/operators/map-optional.d.mts +47 -0
- package/dist/core/predefined/operators/map-optional.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-optional.mjs +49 -1
- package/dist/core/predefined/operators/map-optional.mjs.map +1 -1
- package/dist/core/predefined/operators/map-result-err.d.mts +47 -0
- package/dist/core/predefined/operators/map-result-err.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-result-err.mjs +49 -1
- package/dist/core/predefined/operators/map-result-err.mjs.map +1 -1
- package/dist/core/predefined/operators/map-result-ok.d.mts +47 -0
- package/dist/core/predefined/operators/map-result-ok.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-result-ok.mjs +49 -1
- package/dist/core/predefined/operators/map-result-ok.mjs.map +1 -1
- package/dist/core/predefined/operators/map-to.d.mts +40 -0
- package/dist/core/predefined/operators/map-to.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-to.mjs +43 -1
- package/dist/core/predefined/operators/map-to.mjs.map +1 -1
- package/dist/core/predefined/operators/pluck.d.mts +39 -0
- package/dist/core/predefined/operators/pluck.d.mts.map +1 -1
- package/dist/core/predefined/operators/pluck.mjs +42 -1
- package/dist/core/predefined/operators/pluck.mjs.map +1 -1
- package/dist/core/predefined/operators/skip.d.mts +47 -0
- package/dist/core/predefined/operators/skip.d.mts.map +1 -1
- package/dist/core/predefined/operators/skip.mjs +47 -0
- package/dist/core/predefined/operators/skip.mjs.map +1 -1
- package/dist/core/predefined/operators/take.d.mts +41 -0
- package/dist/core/predefined/operators/take.d.mts.map +1 -1
- package/dist/core/predefined/operators/take.mjs +41 -0
- package/dist/core/predefined/operators/take.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-optional.d.mts +40 -0
- package/dist/core/predefined/operators/unwrap-optional.d.mts.map +1 -1
- package/dist/core/predefined/operators/unwrap-optional.mjs +42 -1
- package/dist/core/predefined/operators/unwrap-optional.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-result-err.d.mts +40 -0
- package/dist/core/predefined/operators/unwrap-result-err.d.mts.map +1 -1
- package/dist/core/predefined/operators/unwrap-result-err.mjs +42 -1
- package/dist/core/predefined/operators/unwrap-result-err.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-result-ok.d.mts +40 -0
- package/dist/core/predefined/operators/unwrap-result-ok.d.mts.map +1 -1
- package/dist/core/predefined/operators/unwrap-result-ok.mjs +42 -1
- package/dist/core/predefined/operators/unwrap-result-ok.mjs.map +1 -1
- package/dist/core/types/id.d.mts +1 -1
- package/dist/core/types/id.d.mts.map +1 -1
- package/dist/core/types/index.d.mts +1 -0
- package/dist/core/types/index.d.mts.map +1 -1
- package/dist/core/types/observable-family.d.mts +8 -14
- package/dist/core/types/observable-family.d.mts.map +1 -1
- package/dist/core/types/observable.d.mts +3 -3
- package/dist/core/types/observable.d.mts.map +1 -1
- package/dist/core/types/timer.d.mts +2 -0
- package/dist/core/types/timer.d.mts.map +1 -0
- package/dist/core/types/timer.mjs +2 -0
- package/dist/core/types/timer.mjs.map +1 -0
- package/dist/core/utils/id-maker.d.mts +2 -2
- package/dist/core/utils/id-maker.d.mts.map +1 -1
- package/dist/core/utils/id-maker.mjs +3 -3
- package/dist/core/utils/id-maker.mjs.map +1 -1
- package/dist/core/utils/index.mjs +1 -1
- package/dist/entry-point.mjs +11 -14
- package/dist/entry-point.mjs.map +1 -1
- package/dist/globals.d.mts +0 -3
- package/dist/index.mjs +11 -14
- package/dist/index.mjs.map +1 -1
- package/dist/utils/collect-to-array.d.mts +3 -0
- package/dist/utils/collect-to-array.d.mts.map +1 -0
- package/dist/utils/collect-to-array.mjs +11 -0
- package/dist/utils/collect-to-array.mjs.map +1 -0
- package/dist/utils/create-boolean-state.d.mts +40 -0
- package/dist/utils/create-boolean-state.d.mts.map +1 -0
- package/dist/utils/create-boolean-state.mjs +53 -0
- package/dist/utils/create-boolean-state.mjs.map +1 -0
- package/dist/utils/create-event-emitter.d.mts +4 -4
- package/dist/utils/create-event-emitter.mjs +4 -4
- package/dist/utils/create-reducer.d.mts +10 -7
- package/dist/utils/create-reducer.d.mts.map +1 -1
- package/dist/utils/create-reducer.mjs +7 -7
- package/dist/utils/create-reducer.mjs.map +1 -1
- package/dist/utils/create-state.d.mts +8 -48
- package/dist/utils/create-state.d.mts.map +1 -1
- package/dist/utils/create-state.mjs +10 -60
- package/dist/utils/create-state.mjs.map +1 -1
- package/dist/utils/index.d.mts +2 -0
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +3 -1
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +17 -11
- package/src/core/class/child-observable-class.mts +65 -9
- package/src/core/class/circular-dependency-comparison.test.mts +142 -0
- package/src/core/class/circular-dependency.test.mts +251 -0
- package/src/core/class/observable-base-class.mts +9 -9
- package/src/core/class/root-observable-class.mts +14 -10
- package/src/core/combine/combine.mts +13 -13
- package/src/core/combine/merge.mts +13 -14
- package/src/core/combine/zip.mts +26 -25
- package/src/core/create/{interval.mts → counter.mts} +32 -30
- package/src/core/create/from-abortable-promise.mts +83 -0
- package/src/core/create/from-promise.mts +10 -7
- package/src/core/create/from-subscribable.mts +4 -4
- package/src/core/create/index.mts +3 -3
- package/src/core/create/just.mts +43 -0
- package/src/core/create/source.mts +10 -14
- package/src/core/create/timer.mts +12 -11
- package/src/core/index.mts +0 -1
- package/src/core/operators/audit.mts +172 -0
- package/src/core/operators/debounce.mts +154 -0
- package/src/core/operators/filter.mts +9 -9
- package/src/core/operators/index.mts +4 -4
- package/src/core/operators/{map-with-index.mts → map.mts} +20 -20
- package/src/core/operators/merge-map.mts +59 -32
- package/src/core/operators/pairwise.mts +10 -10
- package/src/core/operators/scan.mts +10 -10
- package/src/core/operators/skip-if-no-change.mts +24 -12
- package/src/core/operators/skip-until.mts +9 -9
- package/src/core/operators/skip-while.mts +29 -12
- package/src/core/operators/switch-map.mts +60 -29
- package/src/core/operators/take-until.mts +9 -9
- package/src/core/operators/take-while.mts +19 -11
- package/src/core/operators/{throttle-time.mts → throttle.mts} +58 -38
- package/src/core/operators/with-buffered-from.mts +13 -13
- package/src/core/operators/with-current-value-from.mts +14 -13
- package/src/core/operators/with-initial-value.mts +9 -9
- package/src/core/predefined/operators/attach-index.mts +51 -2
- package/src/core/predefined/operators/index.mts +0 -1
- package/src/core/predefined/operators/map-optional.mts +48 -1
- package/src/core/predefined/operators/map-result-err.mts +48 -1
- package/src/core/predefined/operators/map-result-ok.mts +48 -1
- package/src/core/predefined/operators/map-to.mts +41 -1
- package/src/core/predefined/operators/pluck.mts +40 -1
- package/src/core/predefined/operators/skip.mts +47 -0
- package/src/core/predefined/operators/take.mts +41 -0
- package/src/core/predefined/operators/unwrap-optional.mts +41 -1
- package/src/core/predefined/operators/unwrap-result-err.mts +41 -1
- package/src/core/predefined/operators/unwrap-result-ok.mts +41 -1
- package/src/core/types/id.mts +1 -1
- package/src/core/types/index.mts +1 -0
- package/src/core/types/observable-family.mts +8 -24
- package/src/core/types/observable.mts +3 -3
- package/src/core/types/timer.mts +2 -0
- package/src/core/utils/id-maker.mts +4 -4
- package/src/globals.d.mts +0 -3
- package/src/utils/collect-to-array.mts +17 -0
- package/src/utils/create-boolean-state.mts +68 -0
- package/src/utils/create-event-emitter.mts +4 -4
- package/src/utils/create-reducer.mts +11 -8
- package/src/utils/create-state.mts +10 -75
- package/src/utils/index.mts +2 -0
- package/dist/core/create/from-array.d.mts +0 -39
- package/dist/core/create/from-array.d.mts.map +0 -1
- package/dist/core/create/from-array.mjs +0 -65
- package/dist/core/create/from-array.mjs.map +0 -1
- package/dist/core/create/interval.d.mts.map +0 -1
- package/dist/core/create/interval.mjs.map +0 -1
- package/dist/core/create/of.d.mts +0 -39
- package/dist/core/create/of.d.mts.map +0 -1
- package/dist/core/create/of.mjs +0 -63
- package/dist/core/create/of.mjs.map +0 -1
- package/dist/core/operators/audit-time.d.mts +0 -62
- package/dist/core/operators/audit-time.d.mts.map +0 -1
- package/dist/core/operators/audit-time.mjs +0 -109
- package/dist/core/operators/audit-time.mjs.map +0 -1
- package/dist/core/operators/debounce-time.d.mts +0 -51
- package/dist/core/operators/debounce-time.d.mts.map +0 -1
- package/dist/core/operators/debounce-time.mjs +0 -93
- package/dist/core/operators/debounce-time.mjs.map +0 -1
- package/dist/core/operators/map-with-index.d.mts.map +0 -1
- package/dist/core/operators/map-with-index.mjs.map +0 -1
- package/dist/core/operators/throttle-time.d.mts +0 -62
- package/dist/core/operators/throttle-time.d.mts.map +0 -1
- package/dist/core/operators/throttle-time.mjs +0 -107
- package/dist/core/operators/throttle-time.mjs.map +0 -1
- package/dist/core/predefined/operators/map.d.mts +0 -3
- package/dist/core/predefined/operators/map.d.mts.map +0 -1
- package/dist/core/predefined/operators/map.mjs +0 -8
- package/dist/core/predefined/operators/map.mjs.map +0 -1
- package/src/core/create/from-array.mts +0 -76
- package/src/core/create/of.mts +0 -73
- package/src/core/operators/audit-time.mts +0 -136
- package/src/core/operators/debounce-time.mts +0 -116
- package/src/core/predefined/operators/map.mts +0 -5
|
@@ -27,21 +27,21 @@ import { type WithInitialValueOperator } from '../types/index.mjs';
|
|
|
27
27
|
*
|
|
28
28
|
* const initialized$ = num$.pipe(withInitialValue(0));
|
|
29
29
|
*
|
|
30
|
-
* const
|
|
30
|
+
* const valueHistory: number[] = [];
|
|
31
31
|
*
|
|
32
32
|
* initialized$.subscribe((x) => {
|
|
33
|
-
*
|
|
33
|
+
* valueHistory.push(x);
|
|
34
34
|
* });
|
|
35
35
|
*
|
|
36
|
-
* assert.deepStrictEqual(
|
|
36
|
+
* assert.deepStrictEqual(valueHistory, [0]);
|
|
37
37
|
*
|
|
38
38
|
* num$.next(1); // logs: 1
|
|
39
39
|
*
|
|
40
|
-
* assert.deepStrictEqual(
|
|
40
|
+
* assert.deepStrictEqual(valueHistory, [0, 1]);
|
|
41
41
|
*
|
|
42
42
|
* num$.next(2); // logs: 2
|
|
43
43
|
*
|
|
44
|
-
* assert.deepStrictEqual(
|
|
44
|
+
* assert.deepStrictEqual(valueHistory, [0, 1, 2]);
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
47
|
export declare const withInitialValue: <A, I = A>(initialValue: I) => WithInitialValueOperator<A, A | I>;
|
|
@@ -30,21 +30,21 @@ import '../utils/id-maker.mjs';
|
|
|
30
30
|
*
|
|
31
31
|
* const initialized$ = num$.pipe(withInitialValue(0));
|
|
32
32
|
*
|
|
33
|
-
* const
|
|
33
|
+
* const valueHistory: number[] = [];
|
|
34
34
|
*
|
|
35
35
|
* initialized$.subscribe((x) => {
|
|
36
|
-
*
|
|
36
|
+
* valueHistory.push(x);
|
|
37
37
|
* });
|
|
38
38
|
*
|
|
39
|
-
* assert.deepStrictEqual(
|
|
39
|
+
* assert.deepStrictEqual(valueHistory, [0]);
|
|
40
40
|
*
|
|
41
41
|
* num$.next(1); // logs: 1
|
|
42
42
|
*
|
|
43
|
-
* assert.deepStrictEqual(
|
|
43
|
+
* assert.deepStrictEqual(valueHistory, [0, 1]);
|
|
44
44
|
*
|
|
45
45
|
* num$.next(2); // logs: 2
|
|
46
46
|
*
|
|
47
|
-
* assert.deepStrictEqual(
|
|
47
|
+
* assert.deepStrictEqual(valueHistory, [0, 1, 2]);
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
50
|
const withInitialValue = (initialValue) => (parentObservable) => new WithInitialValueObservableClass(parentObservable, initialValue);
|
|
@@ -55,13 +55,13 @@ class WithInitialValueObservableClass extends InitializedSyncChildObservableClas
|
|
|
55
55
|
initialValue: Optional.some(initialValue),
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
tryUpdate(
|
|
58
|
+
tryUpdate(updateToken) {
|
|
59
59
|
const par = this.parents[0];
|
|
60
60
|
const sn = par.getSnapshot();
|
|
61
|
-
if (par.
|
|
61
|
+
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
62
62
|
return; // skip update
|
|
63
63
|
}
|
|
64
|
-
this.setNext(sn.value,
|
|
64
|
+
this.setNext(sn.value, updateToken);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CG;AACI,MAAM,gBAAgB,GAC3B,CAAW,YAAe,KAC1B,CAAC,gBAAgB,KACf,IAAI,+BAA+B,CAAC,gBAAgB,EAAE,YAAY;AAEtE,MAAM,+BACJ,SAAQ,mCAAwD,CAAA;IAGhE,WAAA,CAAY,gBAA+B,EAAE,YAAe,EAAA;AAC1D,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;AAC3B,YAAA,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;AAC1C,SAAA,CAAC;;AAGK,IAAA,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CG;AACI,MAAM,gBAAgB,GAC3B,CAAW,YAAe,KAC1B,CAAC,gBAAgB,KACf,IAAI,+BAA+B,CAAC,gBAAgB,EAAE,YAAY;AAEtE,MAAM,+BACJ,SAAQ,mCAAwD,CAAA;IAGhE,WAAA,CAAY,gBAA+B,EAAE,YAAe,EAAA;AAC1D,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;AAC3B,YAAA,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;AAC1C,SAAA,CAAC;;AAGK,IAAA,SAAS,CAAC,WAAwB,EAAA;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,WAAW,KAAK,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC1D,YAAA,OAAO;;QAGT,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC;;AAEtC;;;;"}
|
|
@@ -3,7 +3,6 @@ export { mapOptional } from './operators/map-optional.mjs';
|
|
|
3
3
|
export { mapResultErr } from './operators/map-result-err.mjs';
|
|
4
4
|
export { mapResultOk } from './operators/map-result-ok.mjs';
|
|
5
5
|
export { mapTo } from './operators/map-to.mjs';
|
|
6
|
-
export { map } from './operators/map.mjs';
|
|
7
6
|
export { getKey, pluck } from './operators/pluck.mjs';
|
|
8
7
|
export { skip } from './operators/skip.mjs';
|
|
9
8
|
export { take } from './operators/take.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1,4 +1,53 @@
|
|
|
1
1
|
import { type KeepInitialValueOperator } from '../../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Attaches a sequential index to each emitted value, producing `[index, value]` tuples.
|
|
4
|
+
* Index starts at 0 and increments with each emission.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source
|
|
7
|
+
* @returns An operator that emits `[index, value]` tuples
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Timeline:
|
|
12
|
+
* //
|
|
13
|
+
* // letter$ "A" "B" "C"
|
|
14
|
+
* // indexed$ [0,"A"] [1,"B"] [2,"C"]
|
|
15
|
+
* //
|
|
16
|
+
* // Explanation:
|
|
17
|
+
* // - attachIndex attaches a sequential index to each emitted value
|
|
18
|
+
* // - Produces [index, value] tuples
|
|
19
|
+
* // - Index starts at 0 and increments with each emission
|
|
20
|
+
*
|
|
21
|
+
* const letter$ = source<string>();
|
|
22
|
+
*
|
|
23
|
+
* const indexed$ = letter$.pipe(attachIndex());
|
|
24
|
+
*
|
|
25
|
+
* const valueHistory: (readonly [number, string])[] = [];
|
|
26
|
+
*
|
|
27
|
+
* indexed$.subscribe(([i, letter]) => {
|
|
28
|
+
* valueHistory.push([i, letter]);
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* letter$.next('A');
|
|
32
|
+
*
|
|
33
|
+
* assert.deepStrictEqual(valueHistory, [[0, 'A']]);
|
|
34
|
+
*
|
|
35
|
+
* letter$.next('B');
|
|
36
|
+
*
|
|
37
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
38
|
+
* [0, 'A'],
|
|
39
|
+
* [1, 'B'],
|
|
40
|
+
* ]);
|
|
41
|
+
*
|
|
42
|
+
* letter$.next('C');
|
|
43
|
+
*
|
|
44
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
45
|
+
* [0, 'A'],
|
|
46
|
+
* [1, 'B'],
|
|
47
|
+
* [2, 'C'],
|
|
48
|
+
* ]);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
2
51
|
export declare const withIndex: <A>() => KeepInitialValueOperator<A, readonly [SafeUint | -1, A]>;
|
|
3
52
|
/**
|
|
4
53
|
* Alias for `withIndex`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-index.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,eAAO,MAAM,SAAS,GAAI,CAAC,OAAM,wBAAwB,CACvD,CAAC,EACD,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"attach-index.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,OAAM,wBAAwB,CACvD,CAAC,EACD,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CACM,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,WAAW,GATE,CAAC,OAAM,wBAAwB,CACvD,CAAC,EACD,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAOO,CAAC"}
|
|
@@ -1,8 +1,57 @@
|
|
|
1
1
|
import 'ts-data-forge';
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Attaches a sequential index to each emitted value, producing `[index, value]` tuples.
|
|
7
|
+
* Index starts at 0 and increments with each emission.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of values from the source
|
|
10
|
+
* @returns An operator that emits `[index, value]` tuples
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Timeline:
|
|
15
|
+
* //
|
|
16
|
+
* // letter$ "A" "B" "C"
|
|
17
|
+
* // indexed$ [0,"A"] [1,"B"] [2,"C"]
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - attachIndex attaches a sequential index to each emitted value
|
|
21
|
+
* // - Produces [index, value] tuples
|
|
22
|
+
* // - Index starts at 0 and increments with each emission
|
|
23
|
+
*
|
|
24
|
+
* const letter$ = source<string>();
|
|
25
|
+
*
|
|
26
|
+
* const indexed$ = letter$.pipe(attachIndex());
|
|
27
|
+
*
|
|
28
|
+
* const valueHistory: (readonly [number, string])[] = [];
|
|
29
|
+
*
|
|
30
|
+
* indexed$.subscribe(([i, letter]) => {
|
|
31
|
+
* valueHistory.push([i, letter]);
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* letter$.next('A');
|
|
35
|
+
*
|
|
36
|
+
* assert.deepStrictEqual(valueHistory, [[0, 'A']]);
|
|
37
|
+
*
|
|
38
|
+
* letter$.next('B');
|
|
39
|
+
*
|
|
40
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
41
|
+
* [0, 'A'],
|
|
42
|
+
* [1, 'B'],
|
|
43
|
+
* ]);
|
|
44
|
+
*
|
|
45
|
+
* letter$.next('C');
|
|
46
|
+
*
|
|
47
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
48
|
+
* [0, 'A'],
|
|
49
|
+
* [1, 'B'],
|
|
50
|
+
* [2, 'C'],
|
|
51
|
+
* ]);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
const withIndex = () => map((a, i) => [i, a]);
|
|
6
55
|
/**
|
|
7
56
|
* Alias for `withIndex`.
|
|
8
57
|
* @see withIndex
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-index.mjs","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"attach-index.mjs","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDG;MACU,SAAS,GAAG,MAGpB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAU;AAElC;;;AAGG;AACI,MAAM,WAAW,GAAG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/index.mts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/index.mts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC"}
|
|
@@ -3,7 +3,6 @@ export { mapOptional } from './map-optional.mjs';
|
|
|
3
3
|
export { mapResultErr } from './map-result-err.mjs';
|
|
4
4
|
export { mapResultOk } from './map-result-ok.mjs';
|
|
5
5
|
export { mapTo } from './map-to.mjs';
|
|
6
|
-
export { map } from './map.mjs';
|
|
7
6
|
export { getKey, pluck } from './pluck.mjs';
|
|
8
7
|
export { skip } from './skip.mjs';
|
|
9
8
|
export { take } from './take.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1,4 +1,51 @@
|
|
|
1
1
|
import { Optional } from 'ts-data-forge';
|
|
2
2
|
import { type KeepInitialValueOperator } from '../../types/index.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms the inner value of an `Optional` type emitted by the source.
|
|
5
|
+
* If the value is `Some`, the mapping function is applied; if `None`, it remains `None`.
|
|
6
|
+
*
|
|
7
|
+
* @template O - The Optional type from the source
|
|
8
|
+
* @template B - The type of the mapped inner value
|
|
9
|
+
* @param mapFn - A function to transform the unwrapped value
|
|
10
|
+
* @returns An operator that maps the inner value of Optional emissions
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Timeline:
|
|
15
|
+
* //
|
|
16
|
+
* // value$ Some(2) None Some(5)
|
|
17
|
+
* // doubled$ Some(4) None Some(10)
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - mapOptional transforms the inner value of Optional emissions
|
|
21
|
+
* // - Some values are mapped; None values pass through unchanged
|
|
22
|
+
*
|
|
23
|
+
* const value$ = source<Optional<number>>();
|
|
24
|
+
*
|
|
25
|
+
* const doubled$ = value$.pipe(mapOptional((x) => x * 2));
|
|
26
|
+
*
|
|
27
|
+
* const valueHistory: Optional<number>[] = [];
|
|
28
|
+
*
|
|
29
|
+
* doubled$.subscribe((v) => {
|
|
30
|
+
* valueHistory.push(v);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* value$.next(Optional.some(2));
|
|
34
|
+
*
|
|
35
|
+
* assert.deepStrictEqual(valueHistory, [Optional.some(4)]);
|
|
36
|
+
*
|
|
37
|
+
* value$.next(Optional.none);
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(valueHistory, [Optional.some(4), Optional.none]);
|
|
40
|
+
*
|
|
41
|
+
* value$.next(Optional.some(5));
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
44
|
+
* Optional.some(4),
|
|
45
|
+
* Optional.none,
|
|
46
|
+
* Optional.some(10),
|
|
47
|
+
* ]);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
3
50
|
export declare const mapOptional: <O extends UnknownOptional, B>(mapFn: (x: Optional.Unwrap<O>) => B) => KeepInitialValueOperator<O, Optional<B>>;
|
|
4
51
|
//# sourceMappingURL=map-optional.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-optional.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"map-optional.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,EACtD,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAClC,wBAAwB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CACN,CAAC"}
|
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import
|
|
2
|
+
import '../../utils/id-maker.mjs';
|
|
3
|
+
import { map } from '../../operators/map.mjs';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Transforms the inner value of an `Optional` type emitted by the source.
|
|
7
|
+
* If the value is `Some`, the mapping function is applied; if `None`, it remains `None`.
|
|
8
|
+
*
|
|
9
|
+
* @template O - The Optional type from the source
|
|
10
|
+
* @template B - The type of the mapped inner value
|
|
11
|
+
* @param mapFn - A function to transform the unwrapped value
|
|
12
|
+
* @returns An operator that maps the inner value of Optional emissions
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Timeline:
|
|
17
|
+
* //
|
|
18
|
+
* // value$ Some(2) None Some(5)
|
|
19
|
+
* // doubled$ Some(4) None Some(10)
|
|
20
|
+
* //
|
|
21
|
+
* // Explanation:
|
|
22
|
+
* // - mapOptional transforms the inner value of Optional emissions
|
|
23
|
+
* // - Some values are mapped; None values pass through unchanged
|
|
24
|
+
*
|
|
25
|
+
* const value$ = source<Optional<number>>();
|
|
26
|
+
*
|
|
27
|
+
* const doubled$ = value$.pipe(mapOptional((x) => x * 2));
|
|
28
|
+
*
|
|
29
|
+
* const valueHistory: Optional<number>[] = [];
|
|
30
|
+
*
|
|
31
|
+
* doubled$.subscribe((v) => {
|
|
32
|
+
* valueHistory.push(v);
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* value$.next(Optional.some(2));
|
|
36
|
+
*
|
|
37
|
+
* assert.deepStrictEqual(valueHistory, [Optional.some(4)]);
|
|
38
|
+
*
|
|
39
|
+
* value$.next(Optional.none);
|
|
40
|
+
*
|
|
41
|
+
* assert.deepStrictEqual(valueHistory, [Optional.some(4), Optional.none]);
|
|
42
|
+
*
|
|
43
|
+
* value$.next(Optional.some(5));
|
|
44
|
+
*
|
|
45
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
46
|
+
* Optional.some(4),
|
|
47
|
+
* Optional.none,
|
|
48
|
+
* Optional.some(10),
|
|
49
|
+
* ]);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
4
52
|
const mapOptional = (mapFn) => map((a) => Optional.map(a, mapFn));
|
|
5
53
|
|
|
6
54
|
export { mapOptional };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-optional.mjs","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"map-optional.mjs","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CG;AACI,MAAM,WAAW,GAAG,CACzB,KAAmC,KAEnC,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC;;;;"}
|
|
@@ -1,4 +1,51 @@
|
|
|
1
1
|
import { Result } from 'ts-data-forge';
|
|
2
2
|
import { type KeepInitialValueOperator } from '../../types/index.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms the error value (`Err`) of a `Result` type emitted by the source.
|
|
5
|
+
* If the value is `Err`, the mapping function is applied; if `Ok`, it remains unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @template R - The Result type from the source
|
|
8
|
+
* @template E2 - The type of the mapped error value
|
|
9
|
+
* @param mapFn - A function to transform the Err value
|
|
10
|
+
* @returns An operator that maps the Err side of Result emissions
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Timeline:
|
|
15
|
+
* //
|
|
16
|
+
* // result$ Ok(1) Err("bad") Err("fail")
|
|
17
|
+
* // mapped$ Ok(1) Err("BAD") Err("FAIL")
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - mapResultErr transforms the Err value of Result emissions
|
|
21
|
+
* // - Ok values pass through unchanged
|
|
22
|
+
*
|
|
23
|
+
* const result$ = source<Result<number, string>>();
|
|
24
|
+
*
|
|
25
|
+
* const mapped$ = result$.pipe(mapResultErr((e) => e.toUpperCase()));
|
|
26
|
+
*
|
|
27
|
+
* const valueHistory: Result<number, string>[] = [];
|
|
28
|
+
*
|
|
29
|
+
* mapped$.subscribe((v) => {
|
|
30
|
+
* valueHistory.push(v);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* result$.next(Result.ok(1));
|
|
34
|
+
*
|
|
35
|
+
* assert.deepStrictEqual(valueHistory, [Result.ok(1)]);
|
|
36
|
+
*
|
|
37
|
+
* result$.next(Result.err('bad'));
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(valueHistory, [Result.ok(1), Result.err('BAD')]);
|
|
40
|
+
*
|
|
41
|
+
* result$.next(Result.err('fail'));
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
44
|
+
* Result.ok(1),
|
|
45
|
+
* Result.err('BAD'),
|
|
46
|
+
* Result.err('FAIL'),
|
|
47
|
+
* ]);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
3
50
|
export declare const mapResultErr: <R extends UnknownResult, E2>(mapFn: (x: Result.UnwrapErr<R>) => E2) => KeepInitialValueOperator<R, Result<Result.UnwrapOk<R>, E2>>;
|
|
4
51
|
//# sourceMappingURL=map-result-err.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result-err.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-result-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"map-result-err.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-result-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,EACtD,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,KACpC,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC"}
|
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
import { Result } from 'ts-data-forge';
|
|
2
|
-
import
|
|
2
|
+
import '../../utils/id-maker.mjs';
|
|
3
|
+
import { map } from '../../operators/map.mjs';
|
|
3
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
|
+
*/
|
|
4
52
|
const mapResultErr = (mapFn) => map((a) => Result.mapErr(a, mapFn));
|
|
5
53
|
|
|
6
54
|
export { mapResultErr };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result-err.mjs","sources":["../../../../src/core/predefined/operators/map-result-err.mts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"map-result-err.mjs","sources":["../../../../src/core/predefined/operators/map-result-err.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CG;AACI,MAAM,YAAY,GAAG,CAC1B,KAAqC,KAErC,GAAG,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC;;;;"}
|
|
@@ -1,4 +1,51 @@
|
|
|
1
1
|
import { Result } from 'ts-data-forge';
|
|
2
2
|
import { type KeepInitialValueOperator } from '../../types/index.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms the success value (`Ok`) of a `Result` type emitted by the source.
|
|
5
|
+
* If the value is `Ok`, the mapping function is applied; if `Err`, it remains unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @template R - The Result type from the source
|
|
8
|
+
* @template S2 - The type of the mapped success value
|
|
9
|
+
* @param mapFn - A function to transform the Ok value
|
|
10
|
+
* @returns An operator that maps the Ok side of Result emissions
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Timeline:
|
|
15
|
+
* //
|
|
16
|
+
* // result$ Ok(2) Err("e") Ok(5)
|
|
17
|
+
* // doubled$ Ok(4) Err("e") Ok(10)
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - mapResultOk transforms the Ok value of Result emissions
|
|
21
|
+
* // - Err values pass through unchanged
|
|
22
|
+
*
|
|
23
|
+
* const result$ = source<Result<number, string>>();
|
|
24
|
+
*
|
|
25
|
+
* const doubled$ = result$.pipe(mapResultOk((x) => x * 2));
|
|
26
|
+
*
|
|
27
|
+
* const valueHistory: Result<number, string>[] = [];
|
|
28
|
+
*
|
|
29
|
+
* doubled$.subscribe((v) => {
|
|
30
|
+
* valueHistory.push(v);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* result$.next(Result.ok(2));
|
|
34
|
+
*
|
|
35
|
+
* assert.deepStrictEqual(valueHistory, [Result.ok(4)]);
|
|
36
|
+
*
|
|
37
|
+
* result$.next(Result.err('e'));
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(valueHistory, [Result.ok(4), Result.err('e')]);
|
|
40
|
+
*
|
|
41
|
+
* result$.next(Result.ok(5));
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
44
|
+
* Result.ok(4),
|
|
45
|
+
* Result.err('e'),
|
|
46
|
+
* Result.ok(10),
|
|
47
|
+
* ]);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
3
50
|
export declare const mapResultOk: <R extends UnknownResult, S2>(mapFn: (x: Result.UnwrapOk<R>) => S2) => KeepInitialValueOperator<R, Result<S2, Result.UnwrapErr<R>>>;
|
|
4
51
|
//# sourceMappingURL=map-result-ok.d.mts.map
|
|
@@ -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,MAAM,eAAe,CAAC;
|
|
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,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,EACrD,OAAO,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,CAC5B,CAAC"}
|
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
import { Result } from 'ts-data-forge';
|
|
2
|
-
import
|
|
2
|
+
import '../../utils/id-maker.mjs';
|
|
3
|
+
import { map } from '../../operators/map.mjs';
|
|
3
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
|
+
*/
|
|
4
52
|
const mapResultOk = (mapFn) => map((a) => Result.map(a, mapFn));
|
|
5
53
|
|
|
6
54
|
export { mapResultOk };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result-ok.mjs","sources":["../../../../src/core/predefined/operators/map-result-ok.mts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"map-result-ok.mjs","sources":["../../../../src/core/predefined/operators/map-result-ok.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CG;AACI,MAAM,WAAW,GAAG,CACzB,KAAoC,KAEpC,GAAG,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC;;;;"}
|
|
@@ -1,3 +1,43 @@
|
|
|
1
1
|
import { type KeepInitialValueOperator } from '../../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Maps all emitted values to a constant value, ignoring the source values.
|
|
4
|
+
* Equivalent to `map(() => value)`.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source
|
|
7
|
+
* @template B - The type of the constant value
|
|
8
|
+
* @param value - The constant value to emit
|
|
9
|
+
* @returns An operator that always emits the given constant
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Timeline:
|
|
14
|
+
* //
|
|
15
|
+
* // click$ MouseEvent MouseEvent MouseEvent
|
|
16
|
+
* // count$ 1 1 1
|
|
17
|
+
* //
|
|
18
|
+
* // Explanation:
|
|
19
|
+
* // - mapTo maps all emitted values to a constant value
|
|
20
|
+
* // - Ignores the source values entirely
|
|
21
|
+
* // - Useful for converting events to signals
|
|
22
|
+
*
|
|
23
|
+
* const click$ = source<string>();
|
|
24
|
+
*
|
|
25
|
+
* const one$ = click$.pipe(mapTo(1));
|
|
26
|
+
*
|
|
27
|
+
* const valueHistory: number[] = [];
|
|
28
|
+
*
|
|
29
|
+
* one$.subscribe((value) => {
|
|
30
|
+
* valueHistory.push(value);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* click$.next('click1');
|
|
34
|
+
*
|
|
35
|
+
* click$.next('click2');
|
|
36
|
+
*
|
|
37
|
+
* click$.next('click3');
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(valueHistory, [1, 1, 1]);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
2
42
|
export declare const mapTo: <A, B>(value: B) => KeepInitialValueOperator<A, B>;
|
|
3
43
|
//# sourceMappingURL=map-to.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-to.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-to.mts"],"names":[],"mappings":"
|
|
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,EAAE,OAAO,CAAC,KAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAClD,CAAC"}
|