synstate 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/dist/core/base/create-child-observable.mjs +164 -140
  2. package/dist/core/base/create-child-observable.mjs.map +1 -1
  3. package/dist/core/base/create-observable-base.mjs +148 -152
  4. package/dist/core/base/create-observable-base.mjs.map +1 -1
  5. package/dist/core/base/create-root-observable.mjs +48 -34
  6. package/dist/core/base/create-root-observable.mjs.map +1 -1
  7. package/dist/core/base/index.mjs +3 -3
  8. package/dist/core/base/index.mjs.map +1 -1
  9. package/dist/core/combine/combine.mjs +129 -37
  10. package/dist/core/combine/combine.mjs.map +1 -1
  11. package/dist/core/combine/index.mjs +4 -4
  12. package/dist/core/combine/index.mjs.map +1 -1
  13. package/dist/core/combine/merge.mjs +75 -24
  14. package/dist/core/combine/merge.mjs.map +1 -1
  15. package/dist/core/combine/zip.mjs +120 -39
  16. package/dist/core/combine/zip.mjs.map +1 -1
  17. package/dist/core/create/counter.mjs +81 -45
  18. package/dist/core/create/counter.mjs.map +1 -1
  19. package/dist/core/create/from-abortable-promise.mjs +63 -38
  20. package/dist/core/create/from-abortable-promise.mjs.map +1 -1
  21. package/dist/core/create/from-promise.mjs +67 -25
  22. package/dist/core/create/from-promise.mjs.map +1 -1
  23. package/dist/core/create/from-subscribable.mjs +70 -26
  24. package/dist/core/create/from-subscribable.mjs.map +1 -1
  25. package/dist/core/create/index.mjs +8 -8
  26. package/dist/core/create/index.mjs.map +1 -1
  27. package/dist/core/create/just.mjs +36 -13
  28. package/dist/core/create/just.mjs.map +1 -1
  29. package/dist/core/create/source.mjs +15 -19
  30. package/dist/core/create/source.mjs.map +1 -1
  31. package/dist/core/create/timer.mjs +66 -37
  32. package/dist/core/create/timer.mjs.map +1 -1
  33. package/dist/core/index.mjs +6 -41
  34. package/dist/core/index.mjs.map +1 -1
  35. package/dist/core/operators/audit.mjs +126 -39
  36. package/dist/core/operators/audit.mjs.map +1 -1
  37. package/dist/core/operators/debounce.mjs +114 -37
  38. package/dist/core/operators/debounce.mjs.map +1 -1
  39. package/dist/core/operators/filter.mjs +39 -24
  40. package/dist/core/operators/filter.mjs.map +1 -1
  41. package/dist/core/operators/index.mjs +18 -18
  42. package/dist/core/operators/index.mjs.map +1 -1
  43. package/dist/core/operators/map.mjs +74 -26
  44. package/dist/core/operators/map.mjs.map +1 -1
  45. package/dist/core/operators/merge-map.mjs +128 -35
  46. package/dist/core/operators/merge-map.mjs.map +1 -1
  47. package/dist/core/operators/pairwise.mjs +73 -23
  48. package/dist/core/operators/pairwise.mjs.map +1 -1
  49. package/dist/core/operators/scan.mjs +59 -15
  50. package/dist/core/operators/scan.mjs.map +1 -1
  51. package/dist/core/operators/skip-if-no-change.mjs +89 -31
  52. package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
  53. package/dist/core/operators/skip-until.mjs +71 -29
  54. package/dist/core/operators/skip-until.mjs.map +1 -1
  55. package/dist/core/operators/skip-while.mjs +79 -27
  56. package/dist/core/operators/skip-while.mjs.map +1 -1
  57. package/dist/core/operators/switch-map.mjs +118 -31
  58. package/dist/core/operators/switch-map.mjs.map +1 -1
  59. package/dist/core/operators/take-until.mjs +70 -35
  60. package/dist/core/operators/take-until.mjs.map +1 -1
  61. package/dist/core/operators/take-while.mjs +97 -25
  62. package/dist/core/operators/take-while.mjs.map +1 -1
  63. package/dist/core/operators/throttle.mjs +108 -38
  64. package/dist/core/operators/throttle.mjs.map +1 -1
  65. package/dist/core/operators/with-buffered-from.mjs +94 -47
  66. package/dist/core/operators/with-buffered-from.mjs.map +1 -1
  67. package/dist/core/operators/with-current-value-from.mjs +78 -23
  68. package/dist/core/operators/with-current-value-from.mjs.map +1 -1
  69. package/dist/core/operators/with-initial-value.mjs +64 -14
  70. package/dist/core/operators/with-initial-value.mjs.map +1 -1
  71. package/dist/core/predefined/index.mjs +2 -12
  72. package/dist/core/predefined/index.mjs.map +1 -1
  73. package/dist/core/predefined/operators/attach-index.mjs +55 -7
  74. package/dist/core/predefined/operators/attach-index.mjs.map +1 -1
  75. package/dist/core/predefined/operators/index.mjs +12 -12
  76. package/dist/core/predefined/operators/index.mjs.map +1 -1
  77. package/dist/core/predefined/operators/map-optional.mjs +48 -5
  78. package/dist/core/predefined/operators/map-optional.mjs.map +1 -1
  79. package/dist/core/predefined/operators/map-result-err.mjs +48 -5
  80. package/dist/core/predefined/operators/map-result-err.mjs.map +1 -1
  81. package/dist/core/predefined/operators/map-result-ok.mjs +48 -5
  82. package/dist/core/predefined/operators/map-result-ok.mjs.map +1 -1
  83. package/dist/core/predefined/operators/map-to.mjs +41 -6
  84. package/dist/core/predefined/operators/map-to.mjs.map +1 -1
  85. package/dist/core/predefined/operators/pluck.mjs +45 -7
  86. package/dist/core/predefined/operators/pluck.mjs.map +1 -1
  87. package/dist/core/predefined/operators/skip.mjs +49 -6
  88. package/dist/core/predefined/operators/skip.mjs.map +1 -1
  89. package/dist/core/predefined/operators/take.mjs +42 -6
  90. package/dist/core/predefined/operators/take.mjs.map +1 -1
  91. package/dist/core/predefined/operators/unwrap-optional.mjs +43 -8
  92. package/dist/core/predefined/operators/unwrap-optional.mjs.map +1 -1
  93. package/dist/core/predefined/operators/unwrap-result-err.mjs +41 -5
  94. package/dist/core/predefined/operators/unwrap-result-err.mjs.map +1 -1
  95. package/dist/core/predefined/operators/unwrap-result-ok.mjs +43 -8
  96. package/dist/core/predefined/operators/unwrap-result-ok.mjs.map +1 -1
  97. package/dist/core/types/id.mjs +2 -2
  98. package/dist/core/types/id.mjs.map +1 -1
  99. package/dist/core/types/index.mjs +7 -3
  100. package/dist/core/types/index.mjs.map +1 -1
  101. package/dist/core/types/observable-family.mjs +14 -2
  102. package/dist/core/types/observable-family.mjs.map +1 -1
  103. package/dist/core/types/observable-kind.mjs +2 -2
  104. package/dist/core/types/observable-kind.mjs.map +1 -1
  105. package/dist/core/types/observable.mjs +14 -6
  106. package/dist/core/types/observable.mjs.map +1 -1
  107. package/dist/core/types/timer.mjs +2 -2
  108. package/dist/core/types/timer.mjs.map +1 -1
  109. package/dist/core/types/types.mjs +9 -2
  110. package/dist/core/types/types.mjs.map +1 -1
  111. package/dist/core/utils/id-maker.mjs +10 -11
  112. package/dist/core/utils/id-maker.mjs.map +1 -1
  113. package/dist/core/utils/index.mjs +5 -5
  114. package/dist/core/utils/index.mjs.map +1 -1
  115. package/dist/core/utils/max-depth.mjs +7 -4
  116. package/dist/core/utils/max-depth.mjs.map +1 -1
  117. package/dist/core/utils/observable-utils.mjs +4 -7
  118. package/dist/core/utils/observable-utils.mjs.map +1 -1
  119. package/dist/core/utils/utils.mjs +32 -28
  120. package/dist/core/utils/utils.mjs.map +1 -1
  121. package/dist/entry-point.mjs +2 -46
  122. package/dist/entry-point.mjs.map +1 -1
  123. package/dist/index.mjs +3 -46
  124. package/dist/index.mjs.map +1 -1
  125. package/dist/utils/collect-to-array.mjs +8 -13
  126. package/dist/utils/collect-to-array.mjs.map +1 -1
  127. package/dist/utils/create-boolean-state.mjs +47 -22
  128. package/dist/utils/create-boolean-state.mjs.map +1 -1
  129. package/dist/utils/create-event-emitter.mjs +67 -19
  130. package/dist/utils/create-event-emitter.mjs.map +1 -1
  131. package/dist/utils/create-reducer.mjs +54 -16
  132. package/dist/utils/create-reducer.mjs.map +1 -1
  133. package/dist/utils/create-state.mjs +54 -27
  134. package/dist/utils/create-state.mjs.map +1 -1
  135. package/dist/utils/index.mjs +6 -6
  136. package/dist/utils/index.mjs.map +1 -1
  137. package/package.json +11 -12
@@ -1,49 +1,96 @@
1
- import { Optional, pipe, Arr } from 'ts-data-forge';
2
- import { createSyncChildObservable } from '../base/create-child-observable.mjs';
3
- import '../utils/id-maker.mjs';
4
- import { maxDepth } from '../utils/max-depth.mjs';
5
-
6
- const withBufferedFrom = (observable) => (
7
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
8
- ((parentObservable) => createWithBufferedFromObservable(
9
- parentObservable,
10
- observable
11
- ))
12
- );
13
- const withBuffered = withBufferedFrom;
1
+ import { Arr, Optional, pipe } from 'ts-data-forge';
2
+ import { createSyncChildObservable } from '../base/index.mjs';
3
+ import { maxDepth } from '../utils/index.mjs';
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+ export const withBufferedFrom = (observable) =>
58
+
59
+ ((parentObservable) => createWithBufferedFromObservable(parentObservable, observable));
60
+
61
+
62
+
63
+
64
+ export const withBuffered = withBufferedFrom;
14
65
  const createWithBufferedFromObservable = (parentObservable, observable) => {
15
- let mut_bufferedValues = [];
16
- const clearBuffer = () => {
17
- mut_bufferedValues = [];
18
- };
19
- const result = createSyncChildObservable(
20
- {
21
- parents: [parentObservable],
22
- depth: 1 + maxDepth([parentObservable, observable]),
23
- initialValue: pipe({
24
- par: parentObservable.getSnapshot(),
25
- me: observable.getSnapshot()
26
- }).map(
27
- ({ par, me }) => Optional.isNone(par) ? Optional.none : Optional.some([
28
- par.value,
29
- Optional.isNone(me) ? [] : [me.value]
30
- ])
31
- ).value
32
- },
33
- ({ setNext }) => (updateToken) => {
34
- const sn = parentObservable.getSnapshot();
35
- if (parentObservable.updateToken !== updateToken || Optional.isNone(sn)) {
36
- return;
37
- }
38
- setNext([sn.value, mut_bufferedValues], updateToken);
39
- clearBuffer();
40
- }
41
- );
42
- observable.subscribe((value) => {
43
- mut_bufferedValues = Arr.toPushed(mut_bufferedValues, value);
44
- });
45
- return result;
66
+ let mut_bufferedValues = [];
67
+ const clearBuffer = () => {
68
+ mut_bufferedValues = [];
69
+ };
70
+ const result = createSyncChildObservable({
71
+ parents: [parentObservable],
72
+ depth: 1 + maxDepth([parentObservable, observable]),
73
+ initialValue: pipe({
74
+ par: parentObservable.getSnapshot(),
75
+ me: observable.getSnapshot(),
76
+ }).map(({ par, me }) => Optional.isNone(par)
77
+ ? Optional.none
78
+ : Optional.some([
79
+ par.value,
80
+ Optional.isNone(me) ? [] : [me.value],
81
+ ])).value,
82
+ }, ({ setNext }) => (updateToken) => {
83
+ const sn = parentObservable.getSnapshot();
84
+ if (parentObservable.updateToken !== updateToken ||
85
+ Optional.isNone(sn)) {
86
+ return;
87
+ }
88
+ setNext([sn.value, mut_bufferedValues], updateToken);
89
+ clearBuffer();
90
+ });
91
+ observable.subscribe((value) => {
92
+ mut_bufferedValues = Arr.toPushed(mut_bufferedValues, value);
93
+ });
94
+ return result;
46
95
  };
47
-
48
- export { withBuffered, withBufferedFrom };
49
- //# sourceMappingURL=with-buffered-from.mjs.map
96
+ //# sourceMappingURL=with-buffered-from.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-buffered-from.mjs","sources":["../../../src/core/operators/with-buffered-from.mts"],"sourcesContent":["import { Arr, Optional, pipe } from 'ts-data-forge';\nimport { createSyncChildObservable } from '../base/index.mjs';\nimport {\n type KeepInitialValueOperator,\n type Observable,\n type WithBufferedFromOperatorObservable,\n} from '../types/index.mjs';\nimport { maxDepth } from '../utils/index.mjs';\n\n/**\n * Buffers values from the source observable and emits them along with the parent value\n * when the parent emits. The buffer is cleared after each emission.\n *\n * @template A - The type of values from the parent observable\n * @template B - The type of values from the source observable\n * @param observable - The observable whose values will be buffered\n * @returns An operator that emits tuples of [parentValue, bufferedValues]\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // data$ d1 d2 d3 d4 d5 d6 d7 d8\n * // trigger$ T1 T2 T3\n * // result$ [T1,[d1,d2,d3]] [T2,[d4,d5,d6]] [T3,[d7,d8]]\n * //\n * // Explanation:\n * // - withBufferedFrom collects values from the source observable\n * // - When the trigger emits, it emits a tuple of [triggerValue, bufferedValues]\n * // - Buffer is cleared after each emission\n * // - Useful for batching data collection triggered by events\n *\n * const data$ = source<string>();\n *\n * const trigger$ = source<number>();\n *\n * const result$ = trigger$.pipe(withBufferedFrom(data$));\n *\n * const valueHistory: (readonly [number, readonly string[]])[] = [];\n *\n * result$.subscribe(([triggerValue, bufferedData]) => {\n * valueHistory.push([triggerValue, bufferedData]);\n * });\n *\n * data$.next('A');\n *\n * data$.next('B');\n *\n * trigger$.next(1);\n *\n * assert.deepStrictEqual(valueHistory, [[1, ['A', 'B']]]);\n *\n * data$.next('C');\n *\n * trigger$.next(2);\n *\n * assert.deepStrictEqual(valueHistory, [\n * [1, ['A', 'B']],\n * [2, ['C']],\n * ]);\n * ```\n */\nexport const withBufferedFrom = <A, B>(\n observable: Observable<B>,\n): KeepInitialValueOperator<A, readonly [A, readonly B[]]> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n ((parentObservable) =>\n createWithBufferedFromObservable(\n parentObservable,\n observable,\n )) as KeepInitialValueOperator<A, readonly [A, readonly B[]]>;\n\n/**\n * Alias for `withBufferedFrom`.\n * @see withBufferedFrom\n */\nexport const withBuffered = withBufferedFrom;\n\nconst createWithBufferedFromObservable = <A, B>(\n parentObservable: Observable<A>,\n observable: Observable<B>,\n): WithBufferedFromOperatorObservable<A, B> => {\n let mut_bufferedValues: readonly B[] = [];\n\n const clearBuffer = (): void => {\n mut_bufferedValues = [];\n };\n\n const result = createSyncChildObservable<\n readonly [A, readonly B[]],\n readonly [A]\n >(\n {\n parents: [parentObservable],\n depth: 1 + maxDepth([parentObservable, observable]),\n initialValue: pipe({\n par: parentObservable.getSnapshot(),\n me: observable.getSnapshot(),\n }).map(({ par, me }) =>\n Optional.isNone(par)\n ? Optional.none\n : Optional.some([\n par.value,\n Optional.isNone(me) ? [] : [me.value],\n ] as const),\n ).value,\n },\n ({ setNext }) =>\n (updateToken) => {\n const sn = parentObservable.getSnapshot();\n\n if (\n parentObservable.updateToken !== updateToken ||\n Optional.isNone(sn)\n ) {\n return; // skip update\n }\n\n setNext([sn.value, mut_bufferedValues], updateToken);\n\n clearBuffer();\n },\n );\n\n observable.subscribe((value) => {\n mut_bufferedValues = Arr.toPushed(mut_bufferedValues, value);\n });\n\n return result;\n};\n"],"names":[],"mappings":";;;;;AA8DO,MAAM,mBAAmB,CAC9B,UAAA;AAAA;AAAA,GAGC,CAAC,gBAAA,KACA,gCAAA;AAAA,IACE,gBAAA;AAAA,IACA;AAAA,GACF;AAAA;AAMG,MAAM,YAAA,GAAe;AAE5B,MAAM,gCAAA,GAAmC,CACvC,gBAAA,EACA,UAAA,KAC6C;AAC7C,EAAA,IAAI,qBAAmC,EAAC;AAExC,EAAA,MAAM,cAAc,MAAY;AAC9B,IAAA,kBAAA,GAAqB,EAAC;AAAA,EACxB,CAAA;AAEA,EAAA,MAAM,MAAA,GAAS,yBAAA;AAAA,IAIb;AAAA,MACE,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,GAAA,EAAK,EAAA,EAAG,KAChB,QAAA,CAAS,MAAA,CAAO,GAAG,CAAA,GACf,QAAA,CAAS,IAAA,GACT,QAAA,CAAS,IAAA,CAAK;AAAA,UACZ,GAAA,CAAI,KAAA;AAAA,UACJ,QAAA,CAAS,OAAO,EAAE,CAAA,GAAI,EAAC,GAAI,CAAC,GAAG,KAAK;AAAA,SAC5B;AAAA,OAChB,CAAE;AAAA,KACJ;AAAA,IACA,CAAC,EAAE,OAAA,EAAQ,KACT,CAAC,WAAA,KAAgB;AACf,MAAA,MAAM,EAAA,GAAK,iBAAiB,WAAA,EAAY;AAExC,MAAA,IACE,iBAAiB,WAAA,KAAgB,WAAA,IACjC,QAAA,C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-data-forge';
2
- import { createSyncChildObservable } from '../base/create-child-observable.mjs';
3
- import '../utils/id-maker.mjs';
4
- import { maxDepth } from '../utils/max-depth.mjs';
5
-
6
- const withCurrentValueFrom = (observable) => (parentObservable) => createWithCurrentValueFromObservable(parentObservable, observable);
7
- const withLatestFrom = withCurrentValueFrom;
8
- const createWithCurrentValueFromObservable = (parentObservable, observable) => createSyncChildObservable(
9
- {
2
+ import { createSyncChildObservable } from '../base/index.mjs';
3
+ import { maxDepth } from '../utils/index.mjs';
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+ export const withCurrentValueFrom = (observable) => (parentObservable) => createWithCurrentValueFromObservable(parentObservable, observable);
61
+
62
+
63
+
64
+
65
+ export const withLatestFrom = withCurrentValueFrom;
66
+ const createWithCurrentValueFromObservable = (parentObservable, observable) => createSyncChildObservable({
10
67
  parents: [parentObservable],
11
68
  depth: 1 + maxDepth([parentObservable, observable]),
12
69
  initialValue: pipe({
13
- par: parentObservable.getSnapshot(),
14
- me: observable.getSnapshot()
15
- }).map(
16
- ({ me, par }) => Optional.isNone(par) || Optional.isNone(me) ? Optional.none : Optional.some([par.value, me.value])
17
- ).value
18
- },
19
- ({ setNext }) => (updateToken) => {
70
+ par: parentObservable.getSnapshot(),
71
+ me: observable.getSnapshot(),
72
+ }).map(({ me, par }) => Optional.isNone(par) || Optional.isNone(me)
73
+ ? Optional.none
74
+ : Optional.some([par.value, me.value])).value,
75
+ }, ({ setNext }) => (updateToken) => {
20
76
  const ps = parentObservable.getSnapshot();
21
- if (parentObservable.updateToken !== updateToken || Optional.isNone(ps)) {
22
- return;
77
+ if (parentObservable.updateToken !== updateToken ||
78
+ Optional.isNone(ps)) {
79
+ return;
23
80
  }
24
81
  const curr = observable.getSnapshot();
25
- if (Optional.isNone(curr)) return;
82
+ if (Optional.isNone(curr))
83
+ return;
26
84
  setNext([ps.value, curr.value], updateToken);
27
- }
28
- );
29
-
30
- export { withCurrentValueFrom, withLatestFrom };
31
- //# sourceMappingURL=with-current-value-from.mjs.map
85
+ });
86
+ //# sourceMappingURL=with-current-value-from.mjs.map
@@ -1 +1 @@
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 { createSyncChildObservable } from '../base/index.mjs';\nimport {\n type DropInitialValueOperator,\n type Observable,\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 createWithCurrentValueFromObservable(parentObservable, observable);\n\n/**\n * Alias for `withCurrentValueFrom`.\n * @see withCurrentValueFrom\n */\nexport const withLatestFrom = withCurrentValueFrom;\n\nconst createWithCurrentValueFromObservable = <A, B>(\n parentObservable: Observable<A>,\n observable: Observable<B>,\n): WithCurrentValueFromOperatorObservable<A, B> =>\n createSyncChildObservable<readonly [A, B], readonly [A]>(\n {\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 ({ setNext }) =>\n (updateToken) => {\n const ps = parentObservable.getSnapshot();\n\n if (\n parentObservable.updateToken !== updateToken ||\n Optional.isNone(ps)\n ) {\n return; // skip update\n }\n\n const curr = observable.getSnapshot();\n\n if (Optional.isNone(curr)) return; // skip update\n\n setNext([ps.value, curr.value], updateToken);\n },\n );\n"],"names":[],"mappings":";;;;;AAiEO,MAAM,uBACX,CACE,UAAA,KAEF,CAAC,gBAAA,KACC,oCAAA,CAAqC,kBAAkB,UAAU;AAM9D,MAAM,cAAA,GAAiB;AAE9B,MAAM,oCAAA,GAAuC,CAC3C,gBAAA,EACA,UAAA,KAEA,yBAAA;AAAA,EACE;AAAA,IACE,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,IAC1B,OAAO,CAAA,GAAI,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IAAI,CAAC;QAAE,OAAO,CAAC,cAAc;IAEjD,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,CAAC;AAC/C,CAAC,CACJ,CAAC"}
@@ -1,21 +1,71 @@
1
1
  import { Optional } from 'ts-data-forge';
2
- import { createInitializedSyncChildObservable } from '../base/create-child-observable.mjs';
3
- import '../utils/id-maker.mjs';
2
+ import { createInitializedSyncChildObservable } from '../base/index.mjs';
4
3
 
5
- const withInitialValue = (initialValue) => (parentObservable) => createWithInitialValueObservable(parentObservable, initialValue);
6
- const createWithInitialValueObservable = (parentObservable, initialValue) => createInitializedSyncChildObservable(
7
- {
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ export const withInitialValue = (initialValue) => (parentObservable) => createWithInitialValueObservable(parentObservable, initialValue);
50
+ const createWithInitialValueObservable = (parentObservable, initialValue) => createInitializedSyncChildObservable({
8
51
  parents: [parentObservable],
9
- initialValue: Optional.some(initialValue)
10
- },
11
- ({ setNext }) => (updateToken) => {
52
+ initialValue: Optional.some(initialValue),
53
+ }, ({ setNext }) => (updateToken) => {
12
54
  const sn = parentObservable.getSnapshot();
13
- if (parentObservable.updateToken !== updateToken || Optional.isNone(sn)) {
14
- return;
55
+ if (parentObservable.updateToken !== updateToken ||
56
+ Optional.isNone(sn)) {
57
+ return;
15
58
  }
16
59
  setNext(sn.value, updateToken);
17
- }
18
- );
60
+ });
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
19
70
 
20
- export { withInitialValue };
21
- //# sourceMappingURL=with-initial-value.mjs.map
71
+ //# sourceMappingURL=with-initial-value.mjs.map
@@ -1 +1 @@
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 { createInitializedSyncChildObservable } from '../base/index.mjs';\nimport { source } from '../create/index.mjs';\nimport {\n type InitializedObservable,\n type Observable,\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 createWithInitialValueObservable(parentObservable, initialValue);\n\nconst createWithInitialValueObservable = <A, I>(\n parentObservable: Observable<A>,\n initialValue: I,\n): WithInitialValueOperatorObservable<A, I> =>\n createInitializedSyncChildObservable<A | I, readonly [A]>(\n {\n parents: [parentObservable],\n initialValue: Optional.some(initialValue),\n },\n ({ setNext }) =>\n (updateToken) => {\n const sn = parentObservable.getSnapshot();\n\n if (\n parentObservable.updateToken !== updateToken ||\n Optional.isNone(sn)\n ) {\n return; // skip update\n }\n\n 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":";;;;AAuDO,MAAM,mBACX,CAAW,YAAA,KACX,CAAC,gBAAA,KACC,gCAAA,CAAiC,kBAAkB,YAAY;AAEnE,MAAM,gCAAA,GAAmC,CACvC,gBAAA,EACA,YAAA,KAEA,oCAAA;AAAA,EACE;AAAA,IACE,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,IAC1B,YAAA,EAAc,QAAA,CAAS,IAAA,CAAK,YAAY;AAAA,GAC1C;AAAA,EACA,CAAC,EAAE,OAAA,EAAQ,KACT,CAAC,WAAA,KAAgB;AACf,IAAA,MAAM,EAAA,GAAK,iBAAiB,WAAA,EAAY;AAExC,IAAA,IACE,iBAAiB,WAAA,KAAgB,WAAA,IACjC,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAClB;AACA,MAAA;AAAA,IAAA;AAGF,IAAA,OAAA,CAAQ,EAAA,CAAG,OAAO,WAAW,CAAA;AAAA,EAAA;AAEnC,CAAA;;;;"}
1
+ {"version":3,"file":"with-initial-value.mjs","sourceRoot":"","sources":["../../../src/core/operators/with-initial-value.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,oCAAoC,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAQ7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,CAAW,YAAe,EAAsC,EAAE,CAClE,CAAC,gBAAgB,EAAE,EAAE,CACnB,gCAAgC,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAErE,MAAM,gCAAgC,GAAG,CACvC,gBAA+B,EAC/B,YAAe,EAC2B,EAAE,CAC5C,oCAAoC,CAClC;IACE,OAAO,EAAE,CAAC,gBAAgB,CAAC;IAC3B,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;CAC1C,EACD,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CACd,CAAC,WAAW,EAAE,EAAE;IACd,MAAM,EAAE,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;IAE1C,IACE,gBAAgB,CAAC,WAAW,KAAK,WAAW;QAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EACnB,CAAC;QACD,OAAO,CAAC,cAAc;IACxB,CAAC;IAED,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;AACjC,CAAC,CACJ,CAAC;AAEJ,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;IACrC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;QACrB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ;IAC7B,CAAC,CAAC,CAAC;IAEH,CAAC;QACC,MAAM,CAAC,GAAG,MAAM,EAAU,CAAC;QAE3B,MAAM,EAAE,GAAkC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtE,UAAU,CAA2C,GAAG,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC"}
@@ -1,12 +1,2 @@
1
- export { attachIndex, withIndex } from './operators/attach-index.mjs';
2
- export { mapOptional } from './operators/map-optional.mjs';
3
- export { mapResultErr } from './operators/map-result-err.mjs';
4
- export { mapResultOk } from './operators/map-result-ok.mjs';
5
- export { mapTo } from './operators/map-to.mjs';
6
- export { getKey, pluck } from './operators/pluck.mjs';
7
- export { skip } from './operators/skip.mjs';
8
- export { take } from './operators/take.mjs';
9
- export { unwrapOptional } from './operators/unwrap-optional.mjs';
10
- export { unwrapResultErr } from './operators/unwrap-result-err.mjs';
11
- export { unwrapResultOk } from './operators/unwrap-result-ok.mjs';
12
- //# sourceMappingURL=index.mjs.map
1
+ export * from './operators/index.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/core/predefined/index.mts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
@@ -1,9 +1,57 @@
1
- import 'ts-data-forge';
2
- import '../../utils/id-maker.mjs';
3
- import { map } from '../../operators/map.mjs';
1
+ import { map } from '../../operators/index.mjs';
4
2
 
5
- const withIndex = () => map((a, i) => [i, a]);
6
- const attachIndex = withIndex;
7
3
 
8
- export { attachIndex, withIndex };
9
- //# sourceMappingURL=attach-index.mjs.map
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+ export const withIndex = () => map((a, i) => [i, a]);
52
+
53
+
54
+
55
+
56
+ export const attachIndex = withIndex;
57
+ //# sourceMappingURL=attach-index.mjs.map
@@ -1 +1 @@
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
+ {"version":3,"file":"attach-index.mjs","sourceRoot":"","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAGvB,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAU,CAAC,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC"}
@@ -1,12 +1,12 @@
1
- export { attachIndex, withIndex } from './attach-index.mjs';
2
- export { mapOptional } from './map-optional.mjs';
3
- export { mapResultErr } from './map-result-err.mjs';
4
- export { mapResultOk } from './map-result-ok.mjs';
5
- export { mapTo } from './map-to.mjs';
6
- export { getKey, pluck } from './pluck.mjs';
7
- export { skip } from './skip.mjs';
8
- export { take } from './take.mjs';
9
- export { unwrapOptional } from './unwrap-optional.mjs';
10
- export { unwrapResultErr } from './unwrap-result-err.mjs';
11
- export { unwrapResultOk } from './unwrap-result-ok.mjs';
12
- //# sourceMappingURL=index.mjs.map
1
+ export * from './attach-index.mjs';
2
+ export * from './map-optional.mjs';
3
+ export * from './map-result-err.mjs';
4
+ export * from './map-result-ok.mjs';
5
+ export * from './map-to.mjs';
6
+ export * from './pluck.mjs';
7
+ export * from './skip.mjs';
8
+ export * from './take.mjs';
9
+ export * from './unwrap-optional.mjs';
10
+ export * from './unwrap-result-err.mjs';
11
+ export * from './unwrap-result-ok.mjs';
12
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","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"}
@@ -1,8 +1,51 @@
1
1
  import { Optional } from 'ts-data-forge';
2
- import '../../utils/id-maker.mjs';
3
- import { map } from '../../operators/map.mjs';
2
+ import { map } from '../../operators/index.mjs';
4
3
 
5
- const mapOptional = (mapFn) => map(Optional.map(mapFn));
6
4
 
7
- export { mapOptional };
8
- //# sourceMappingURL=map-optional.mjs.map
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+ export const mapOptional = (mapFn) => map(Optional.map(mapFn));
51
+ //# sourceMappingURL=map-optional.mjs.map
@@ -1 +1 @@
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
+ {"version":3,"file":"map-optional.mjs","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,KAAmC,EACO,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC"}
@@ -1,8 +1,51 @@
1
1
  import { Result } from 'ts-data-forge';
2
- import '../../utils/id-maker.mjs';
3
- import { map } from '../../operators/map.mjs';
2
+ import { map } from '../../operators/index.mjs';
4
3
 
5
- const mapResultErr = (mapFn) => map(Result.mapErr(mapFn));
6
4
 
7
- export { mapResultErr };
8
- //# sourceMappingURL=map-result-err.mjs.map
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+ export const mapResultErr = (mapFn) => map(Result.mapErr(mapFn));
51
+ //# sourceMappingURL=map-result-err.mjs.map