synstate 1.0.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -17
- 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 +42 -29
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":["import { Optional, pipe } from 'ts-data-forge';\nimport { SyncChildObservableClass } from '../class/index.mjs';\nimport {\n type DropInitialValueOperator,\n type Observable,\n type UpdateToken,\n type WithCurrentValueFromOperatorObservable,\n} from '../types/index.mjs';\nimport { maxDepth } from '../utils/index.mjs';\n\n/**\n * Samples the current value from another observable each time the source emits.\n * Emits a tuple of [sourceValue, sampledValue].\n *\n * @template A - The type of values from the source observable\n * @template B - The type of values from the sampled observable\n * @param observable - The observable to sample from\n * @returns An operator that emits tuples of source and sampled values\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // name$ \"Alice\" \"Bob\" \"Charlie\"\n * // age$ 25 30\n * // result$ (skip) [\"Bob\",25] [\"Charlie\",30]\n * //\n * // Explanation:\n * // - withCurrentValueFrom samples the current value from another observable\n * // - Emits a tuple [sourceValue, sampledValue] each time the SOURCE emits\n * // - Does NOT emit when the sampled observable (age$) emits\n * // - Does not emit until both observables have emitted at least once\n * // - \"Alice\" is skipped because age$ hasn't emitted yet\n *\n * const name$ = source<string>();\n *\n * const age$ = source<number>();\n *\n * const result$ = name$.pipe(withCurrentValueFrom(age$));\n *\n * const valueHistory: (readonly [string, number])[] = [];\n *\n * result$.subscribe(([name_, currentAge]) => {\n * valueHistory.push([name_, currentAge]);\n * });\n *\n * name$.next('Alice'); // nothing logged (age$ hasn't emitted)\n *\n * assert.deepStrictEqual(valueHistory, []);\n *\n * age$.next(25);\n *\n * name$.next('Bob'); // logs: Bob is 25 years old\n *\n * assert.deepStrictEqual(valueHistory, [['Bob', 25]]);\n *\n * age$.next(30);\n *\n * name$.next('Charlie'); // logs: Charlie is 30 years old\n *\n * assert.deepStrictEqual(valueHistory, [\n * ['Bob', 25],\n * ['Charlie', 30],\n * ]);\n * ```\n */\nexport const withCurrentValueFrom =\n <A, B>(\n observable: Observable<B>,\n ): DropInitialValueOperator<A, readonly [A, B]> =>\n (parentObservable) =>\n new WithCurrentValueFromObservableClass(parentObservable, observable);\n\n/**\n * Alias for `withCurrentValueFrom`.\n * @see withCurrentValueFrom\n */\nexport const withLatestFrom = withCurrentValueFrom;\n\nclass WithCurrentValueFromObservableClass<A, B>\n extends SyncChildObservableClass<readonly [A, B], readonly [A]>\n implements WithCurrentValueFromOperatorObservable<A, B>\n{\n readonly #observable: Observable<B>;\n\n constructor(parentObservable: Observable<A>, observable: Observable<B>) {\n super({\n parents: [parentObservable],\n depth: 1 + maxDepth([parentObservable, observable]),\n initialValue: pipe({\n par: parentObservable.getSnapshot(),\n me: observable.getSnapshot(),\n }).map(({ me, par }) =>\n Optional.isNone(par) || Optional.isNone(me)\n ? Optional.none\n : Optional.some([par.value, me.value] as const),\n ).value,\n });\n\n this.#observable = observable;\n }\n\n override tryUpdate(updateToken: UpdateToken): void {\n const par = this.parents[0];\n\n const ps = par.getSnapshot();\n\n if (par.updateToken !== updateToken || Optional.isNone(ps)) {\n return; // skip update\n }\n\n const curr = this.#observable.getSnapshot();\n\n if (Optional.isNone(curr)) return; // skip update\n\n this.setNext([ps.value, curr.value], updateToken);\n }\n}\n"],"names":[],"mappings":";;;;;AAkEO,MAAM,oBAAA,GACX,CACE,UAAA,KAEF,CAAC,qBACC,IAAI,mCAAA,CAAoC,kBAAkB,UAAU;AAMjE,MAAM,cAAA,GAAiB;AAE9B,MAAM,4CACI,wBAAA,CAEV;AAAA,EACW,WAAA;AAAA,EAET,WAAA,CAAY,kBAAiC,UAAA,EAA2B;AACtE,IAAA,KAAA,CAAM;AAAA,MACJ,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,MAC1B,OAAO,CAAA,GAAI,QAAA,CAAS,CAAC,gBAAA,EAAkB,UAAU,CAAC,CAAA;AAAA,MAClD,cAAc,IAAA,CAAK;AAAA,QACjB,GAAA,EAAK,iBAAiB,WAAA,EAAY;AAAA,QAClC,EAAA,EAAI,WAAW,WAAA;AAAY,OAC5B,CAAA,CAAE,GAAA;AAAA,QAAI,CAAC,EAAE,EAAA,EAAI,GAAA,OACZ,QAAA,CAAS,MAAA,CAAO,GAAG,CAAA,IAAK,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,GACtC,QAAA,CAAS,OACT,QAAA,CAAS,IAAA,CAAK,CAAC,GAAA,CAAI,KAAA,EAAO,EAAA,CAAG,KAAK,CAAU;AAAA,OAClD,CAAE;AAAA,KACH,CAAA;AAED,IAAA,IAAA,CAAK,WAAA,GAAc,UAAA;AAAA,EACrB;AAAA,EAES,UAAU,WAAA,EAAgC;AACjD,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAA;AAE1B,IAAA,MAAM,EAAA,GAAK,IAAI,WAAA,EAAY;AAE3B,IAAA,IAAI,IAAI,WAAA,KAAgB,WAAA,IAAe,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAAG;AAC1D,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,WAAA,CAAY,WAAA,EAAY;AAE1C,IAAA,IAAI,QAAA,CAAS,MAAA,CAAO,IAAI,CAAA,EAAG;AAE3B,IAAA,IAAA,CAAK,QAAQ,CAAC,EAAA,CAAG,OAAO,IAAA,CAAK,KAAK,GAAG,WAAW,CAAA;AAAA,EAClD;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-initial-value.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-initial-value.mts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,wBAAwB,EAE9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,EAAE,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"with-initial-value.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-initial-value.mts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,wBAAwB,EAE9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAEO,CAAC"}
|
|
@@ -2,67 +2,22 @@ import { Optional } from 'ts-data-forge';
|
|
|
2
2
|
import { InitializedSyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
3
|
import '../utils/id-maker.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Provides an initial value for an observable that doesn't have one.
|
|
7
|
-
* The resulting observable will immediately emit the initial value upon subscription,
|
|
8
|
-
* and then emit all subsequent values from the source.
|
|
9
|
-
*
|
|
10
|
-
* @template A - The type of values from the source
|
|
11
|
-
* @template I - The type of the initial value (defaults to A)
|
|
12
|
-
* @param initialValue - The initial value to emit
|
|
13
|
-
* @returns An operator that sets the initial value
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* // Timeline:
|
|
18
|
-
* //
|
|
19
|
-
* // num$ 1 2 3
|
|
20
|
-
* // withInitial$ 0 1 2 3
|
|
21
|
-
* // ^
|
|
22
|
-
* // initial value
|
|
23
|
-
* //
|
|
24
|
-
* // Explanation:
|
|
25
|
-
* // - withInitialValue provides an initial value before the source emits
|
|
26
|
-
* // - Converts an uninitialized observable to an initialized one
|
|
27
|
-
* // - Useful when you need a default value immediately
|
|
28
|
-
*
|
|
29
|
-
* const num$ = source<number>();
|
|
30
|
-
*
|
|
31
|
-
* const initialized$ = num$.pipe(withInitialValue(0));
|
|
32
|
-
*
|
|
33
|
-
* const valueHistory: number[] = [];
|
|
34
|
-
*
|
|
35
|
-
* initialized$.subscribe((x) => {
|
|
36
|
-
* valueHistory.push(x);
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* assert.deepStrictEqual(valueHistory, [0]);
|
|
40
|
-
*
|
|
41
|
-
* num$.next(1); // logs: 1
|
|
42
|
-
*
|
|
43
|
-
* assert.deepStrictEqual(valueHistory, [0, 1]);
|
|
44
|
-
*
|
|
45
|
-
* num$.next(2); // logs: 2
|
|
46
|
-
*
|
|
47
|
-
* assert.deepStrictEqual(valueHistory, [0, 1, 2]);
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
5
|
const withInitialValue = (initialValue) => (parentObservable) => new WithInitialValueObservableClass(parentObservable, initialValue);
|
|
51
6
|
class WithInitialValueObservableClass extends InitializedSyncChildObservableClass {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
this.setNext(sn.value, updateToken);
|
|
7
|
+
constructor(parentObservable, initialValue) {
|
|
8
|
+
super({
|
|
9
|
+
parents: [parentObservable],
|
|
10
|
+
initialValue: Optional.some(initialValue)
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
tryUpdate(updateToken) {
|
|
14
|
+
const par = this.parents[0];
|
|
15
|
+
const sn = par.getSnapshot();
|
|
16
|
+
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
17
|
+
return;
|
|
65
18
|
}
|
|
19
|
+
this.setNext(sn.value, updateToken);
|
|
20
|
+
}
|
|
66
21
|
}
|
|
67
22
|
|
|
68
23
|
export { withInitialValue };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":["import { expectType, Optional } from 'ts-data-forge';\nimport { InitializedSyncChildObservableClass } from '../class/index.mjs';\nimport { source } from '../create/index.mjs';\nimport {\n type InitializedObservable,\n type Observable,\n type UpdateToken,\n type WithInitialValueOperator,\n type WithInitialValueOperatorObservable,\n} from '../types/index.mjs';\n\n/**\n * Provides an initial value for an observable that doesn't have one.\n * The resulting observable will immediately emit the initial value upon subscription,\n * and then emit all subsequent values from the source.\n *\n * @template A - The type of values from the source\n * @template I - The type of the initial value (defaults to A)\n * @param initialValue - The initial value to emit\n * @returns An operator that sets the initial value\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // num$ 1 2 3\n * // withInitial$ 0 1 2 3\n * // ^\n * // initial value\n * //\n * // Explanation:\n * // - withInitialValue provides an initial value before the source emits\n * // - Converts an uninitialized observable to an initialized one\n * // - Useful when you need a default value immediately\n *\n * const num$ = source<number>();\n *\n * const initialized$ = num$.pipe(withInitialValue(0));\n *\n * const valueHistory: number[] = [];\n *\n * initialized$.subscribe((x) => {\n * valueHistory.push(x);\n * });\n *\n * assert.deepStrictEqual(valueHistory, [0]);\n *\n * num$.next(1); // logs: 1\n *\n * assert.deepStrictEqual(valueHistory, [0, 1]);\n *\n * num$.next(2); // logs: 2\n *\n * assert.deepStrictEqual(valueHistory, [0, 1, 2]);\n * ```\n */\nexport const withInitialValue =\n <A, I = A>(initialValue: I): WithInitialValueOperator<A, A | I> =>\n (parentObservable) =>\n new WithInitialValueObservableClass(parentObservable, initialValue);\n\nclass WithInitialValueObservableClass<A, I>\n extends InitializedSyncChildObservableClass<A | I, readonly [A]>\n implements WithInitialValueOperatorObservable<A, I>\n{\n constructor(parentObservable: Observable<A>, initialValue: I) {\n super({\n parents: [parentObservable],\n initialValue: Optional.some(initialValue),\n });\n }\n\n override tryUpdate(updateToken: UpdateToken): void {\n const par = this.parents[0];\n\n const sn = par.getSnapshot();\n\n if (par.updateToken !== updateToken || Optional.isNone(sn)) {\n return; // skip update\n }\n\n this.setNext(sn.value, updateToken);\n }\n}\n\nif (import.meta.vitest !== undefined) {\n test('type test', () => {\n expect(1).toBe(1); // dummy\n });\n\n {\n const s = source<number>();\n\n const _d: InitializedObservable<number> = s.pipe(withInitialValue(0));\n\n expectType<typeof _d, InitializedObservable<number>>('=');\n }\n}\n"],"names":[],"mappings":";;;;AAwDO,MAAM,gBAAA,GACX,CAAW,YAAA,KACX,CAAC,qBACC,IAAI,+BAAA,CAAgC,kBAAkB,YAAY;AAEtE,MAAM,wCACI,mCAAA,CAEV;AAAA,EACE,WAAA,CAAY,kBAAiC,YAAA,EAAiB;AAC5D,IAAA,KAAA,CAAM;AAAA,MACJ,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,MAC1B,YAAA,EAAc,QAAA,CAAS,IAAA,CAAK,YAAY;AAAA,KACzC,CAAA;AAAA,EAAA;AACH,EAES,UAAU,WAAA,EAAgC;AACjD,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAA;AAE1B,IAAA,MAAM,EAAA,GAAK,IAAI,WAAA,EAAY;AAE3B,IAAA,IAAI,IAAI,WAAA,KAAgB,WAAA,IAAe,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAAG;AAC1D,MAAA;AAAA,IAAA;AAGF,IAAA,IAAA,CAAK,OAAA,CAAQ,EAAA,CAAG,KAAA,EAAO,WAAW,CAAA;AAAA,EAAA;AAEtC;;;;"}
|
|
@@ -54,5 +54,5 @@ export declare const withIndex: <A>() => KeepInitialValueOperator<A, readonly [S
|
|
|
54
54
|
* Alias for `withIndex`.
|
|
55
55
|
* @see withIndex
|
|
56
56
|
*/
|
|
57
|
-
export declare const attachIndex:
|
|
57
|
+
export declare const attachIndex: typeof withIndex;
|
|
58
58
|
//# sourceMappingURL=attach-index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-index.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,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,
|
|
1
|
+
{"version":3,"file":"attach-index.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,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,kBAAY,CAAC"}
|
|
@@ -2,60 +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
|
-
* 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
5
|
const withIndex = () => map((a, i) => [i, a]);
|
|
55
|
-
/**
|
|
56
|
-
* Alias for `withIndex`.
|
|
57
|
-
* @see withIndex
|
|
58
|
-
*/
|
|
59
6
|
const attachIndex = withIndex;
|
|
60
7
|
|
|
61
8
|
export { attachIndex, withIndex };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-index.mjs","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"attach-index.mjs","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"sourcesContent":["import { type SafeUint } from 'ts-type-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Attaches a sequential index to each emitted value, producing `[index, value]` tuples.\n * Index starts at 0 and increments with each emission.\n *\n * @template A - The type of values from the source\n * @returns An operator that emits `[index, value]` tuples\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // letter$ \"A\" \"B\" \"C\"\n * // indexed$ [0,\"A\"] [1,\"B\"] [2,\"C\"]\n * //\n * // Explanation:\n * // - attachIndex attaches a sequential index to each emitted value\n * // - Produces [index, value] tuples\n * // - Index starts at 0 and increments with each emission\n *\n * const letter$ = source<string>();\n *\n * const indexed$ = letter$.pipe(attachIndex());\n *\n * const valueHistory: (readonly [number, string])[] = [];\n *\n * indexed$.subscribe(([i, letter]) => {\n * valueHistory.push([i, letter]);\n * });\n *\n * letter$.next('A');\n *\n * assert.deepStrictEqual(valueHistory, [[0, 'A']]);\n *\n * letter$.next('B');\n *\n * assert.deepStrictEqual(valueHistory, [\n * [0, 'A'],\n * [1, 'B'],\n * ]);\n *\n * letter$.next('C');\n *\n * assert.deepStrictEqual(valueHistory, [\n * [0, 'A'],\n * [1, 'B'],\n * [2, 'C'],\n * ]);\n * ```\n */\nexport const withIndex = <A,>(): KeepInitialValueOperator<\n A,\n readonly [SafeUint | -1, A]\n> => map((a, i) => [i, a] as const);\n\n/**\n * Alias for `withIndex`.\n * @see withIndex\n */\nexport const attachIndex = withIndex;\n"],"names":[],"mappings":";;;;AAqDO,MAAM,SAAA,GAAY,MAGpB,GAAA,CAAI,CAAC,GAAG,CAAA,KAAM,CAAC,CAAA,EAAG,CAAC,CAAU;AAM3B,MAAM,WAAA,GAAc;;;;"}
|
|
@@ -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,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,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,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,SAC/C,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAClC,wBAAwB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAA6B,CAAC"}
|
|
@@ -2,54 +2,7 @@ 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
|
-
* 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
|
-
*/
|
|
52
|
-
const mapOptional = (mapFn) => map((a) => Optional.map(a, mapFn));
|
|
5
|
+
const mapOptional = (mapFn) => map(Optional.map(mapFn));
|
|
53
6
|
|
|
54
7
|
export { mapOptional };
|
|
55
8
|
//# sourceMappingURL=map-optional.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-optional.mjs","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"map-optional.mjs","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"sourcesContent":["import { Optional, type UnknownOptional } from 'ts-data-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Transforms the inner value of an `Optional` type emitted by the source.\n * If the value is `Some`, the mapping function is applied; if `None`, it remains `None`.\n *\n * @template O - The Optional type from the source\n * @template B - The type of the mapped inner value\n * @param mapFn - A function to transform the unwrapped value\n * @returns An operator that maps the inner value of Optional emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // value$ Some(2) None Some(5)\n * // doubled$ Some(4) None Some(10)\n * //\n * // Explanation:\n * // - mapOptional transforms the inner value of Optional emissions\n * // - Some values are mapped; None values pass through unchanged\n *\n * const value$ = source<Optional<number>>();\n *\n * const doubled$ = value$.pipe(mapOptional((x) => x * 2));\n *\n * const valueHistory: Optional<number>[] = [];\n *\n * doubled$.subscribe((v) => {\n * valueHistory.push(v);\n * });\n *\n * value$.next(Optional.some(2));\n *\n * assert.deepStrictEqual(valueHistory, [Optional.some(4)]);\n *\n * value$.next(Optional.none);\n *\n * assert.deepStrictEqual(valueHistory, [Optional.some(4), Optional.none]);\n *\n * value$.next(Optional.some(5));\n *\n * assert.deepStrictEqual(valueHistory, [\n * Optional.some(4),\n * Optional.none,\n * Optional.some(10),\n * ]);\n * ```\n */\nexport const mapOptional = <O extends UnknownOptional, B>(\n mapFn: (x: Optional.Unwrap<O>) => B,\n): KeepInitialValueOperator<O, Optional<B>> => map(Optional.map(mapFn));\n"],"names":[],"mappings":";;;;AAmDO,MAAM,cAAc,CACzB,KAAA,KAC6C,IAAI,QAAA,CAAS,GAAA,CAAI,KAAK,CAAC;;;;"}
|
|
@@ -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,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,
|
|
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,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,SAC/C,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,CAClC,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 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;;;;"}
|