modern-ts 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +223 -0
  3. package/README.zh-CN.md +223 -0
  4. package/dist/chunks/Errors-BWEYu-AB.cjs +2 -0
  5. package/dist/chunks/Errors-BWEYu-AB.cjs.map +1 -0
  6. package/dist/chunks/Errors-DwUAvFIF.mjs +63 -0
  7. package/dist/chunks/Errors-DwUAvFIF.mjs.map +1 -0
  8. package/dist/chunks/Math-CGEH1ClN.mjs +68 -0
  9. package/dist/chunks/Math-CGEH1ClN.mjs.map +1 -0
  10. package/dist/chunks/Math-CWZVxSF-.cjs +2 -0
  11. package/dist/chunks/Math-CWZVxSF-.cjs.map +1 -0
  12. package/dist/chunks/base-B9k8Lqvf.mjs +56 -0
  13. package/dist/chunks/base-B9k8Lqvf.mjs.map +1 -0
  14. package/dist/chunks/base-BTXL1y_I.cjs +2 -0
  15. package/dist/chunks/base-BTXL1y_I.cjs.map +1 -0
  16. package/dist/chunks/base-BpECeKwU.mjs +19 -0
  17. package/dist/chunks/base-BpECeKwU.mjs.map +1 -0
  18. package/dist/chunks/base-BvHqpP_s.cjs +2 -0
  19. package/dist/chunks/base-BvHqpP_s.cjs.map +1 -0
  20. package/dist/chunks/base-K-RHLZ-S.mjs +46 -0
  21. package/dist/chunks/base-K-RHLZ-S.mjs.map +1 -0
  22. package/dist/chunks/base-r6kn0B0D.cjs +2 -0
  23. package/dist/chunks/base-r6kn0B0D.cjs.map +1 -0
  24. package/dist/chunks/combine-async-DcG-3p8i.cjs +2 -0
  25. package/dist/chunks/combine-async-DcG-3p8i.cjs.map +1 -0
  26. package/dist/chunks/combine-async-Dcg4ya1R.mjs +236 -0
  27. package/dist/chunks/combine-async-Dcg4ya1R.mjs.map +1 -0
  28. package/dist/chunks/delay-CG3cD7bk.cjs +2 -0
  29. package/dist/chunks/delay-CG3cD7bk.cjs.map +1 -0
  30. package/dist/chunks/delay-CKIXpP71.mjs +32 -0
  31. package/dist/chunks/delay-CKIXpP71.mjs.map +1 -0
  32. package/dist/chunks/helper-BVabbpmX.mjs +165 -0
  33. package/dist/chunks/helper-BVabbpmX.mjs.map +1 -0
  34. package/dist/chunks/helper-tsqZMRHW.cjs +3 -0
  35. package/dist/chunks/helper-tsqZMRHW.cjs.map +1 -0
  36. package/dist/chunks/local-8JVtLN0O.mjs +10 -0
  37. package/dist/chunks/local-8JVtLN0O.mjs.map +1 -0
  38. package/dist/chunks/local-Da4yU-nE.cjs +2 -0
  39. package/dist/chunks/local-Da4yU-nE.cjs.map +1 -0
  40. package/dist/chunks/types-B7X_LBjM.cjs +2 -0
  41. package/dist/chunks/types-B7X_LBjM.cjs.map +1 -0
  42. package/dist/chunks/types-DE2SnSbz.mjs +5 -0
  43. package/dist/chunks/types-DE2SnSbz.mjs.map +1 -0
  44. package/dist/index.cjs +2 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.mjs +759 -0
  47. package/dist/index.mjs.map +1 -0
  48. package/dist/subpath/Arr.cjs +2 -0
  49. package/dist/subpath/Arr.cjs.map +1 -0
  50. package/dist/subpath/Arr.mjs +539 -0
  51. package/dist/subpath/Arr.mjs.map +1 -0
  52. package/dist/subpath/Concurrent.cjs +15 -0
  53. package/dist/subpath/Concurrent.cjs.map +1 -0
  54. package/dist/subpath/Concurrent.mjs +4044 -0
  55. package/dist/subpath/Concurrent.mjs.map +1 -0
  56. package/dist/subpath/FetchQ.cjs +2 -0
  57. package/dist/subpath/FetchQ.cjs.map +1 -0
  58. package/dist/subpath/FetchQ.mjs +519 -0
  59. package/dist/subpath/FetchQ.mjs.map +1 -0
  60. package/dist/subpath/Fit.cjs +2 -0
  61. package/dist/subpath/Fit.cjs.map +1 -0
  62. package/dist/subpath/Fit.mjs +914 -0
  63. package/dist/subpath/Fit.mjs.map +1 -0
  64. package/dist/subpath/Lazy.cjs +2 -0
  65. package/dist/subpath/Lazy.cjs.map +1 -0
  66. package/dist/subpath/Lazy.mjs +72 -0
  67. package/dist/subpath/Lazy.mjs.map +1 -0
  68. package/dist/subpath/Maps.cjs +2 -0
  69. package/dist/subpath/Maps.cjs.map +1 -0
  70. package/dist/subpath/Maps.mjs +123 -0
  71. package/dist/subpath/Maps.mjs.map +1 -0
  72. package/dist/subpath/Maybe.cjs +2 -0
  73. package/dist/subpath/Maybe.cjs.map +1 -0
  74. package/dist/subpath/Maybe.mjs +329 -0
  75. package/dist/subpath/Maybe.mjs.map +1 -0
  76. package/dist/subpath/Reactive.cjs +2 -0
  77. package/dist/subpath/Reactive.cjs.map +1 -0
  78. package/dist/subpath/Reactive.mjs +1204 -0
  79. package/dist/subpath/Reactive.mjs.map +1 -0
  80. package/dist/subpath/Reader.cjs +2 -0
  81. package/dist/subpath/Reader.cjs.map +1 -0
  82. package/dist/subpath/Reader.mjs +75 -0
  83. package/dist/subpath/Reader.mjs.map +1 -0
  84. package/dist/subpath/ReaderT.cjs +2 -0
  85. package/dist/subpath/ReaderT.cjs.map +1 -0
  86. package/dist/subpath/ReaderT.mjs +148 -0
  87. package/dist/subpath/ReaderT.mjs.map +1 -0
  88. package/dist/subpath/Resource.cjs +2 -0
  89. package/dist/subpath/Resource.cjs.map +1 -0
  90. package/dist/subpath/Resource.mjs +150 -0
  91. package/dist/subpath/Resource.mjs.map +1 -0
  92. package/dist/subpath/Result.cjs +2 -0
  93. package/dist/subpath/Result.cjs.map +1 -0
  94. package/dist/subpath/Result.mjs +337 -0
  95. package/dist/subpath/Result.mjs.map +1 -0
  96. package/dist/subpath/Sets.cjs +2 -0
  97. package/dist/subpath/Sets.cjs.map +1 -0
  98. package/dist/subpath/Sets.mjs +92 -0
  99. package/dist/subpath/Sets.mjs.map +1 -0
  100. package/dist/subpath/Str.cjs +2 -0
  101. package/dist/subpath/Str.cjs.map +1 -0
  102. package/dist/subpath/Str.mjs +114 -0
  103. package/dist/subpath/Str.mjs.map +1 -0
  104. package/dist/subpath/TxScope.cjs +2 -0
  105. package/dist/subpath/TxScope.cjs.map +1 -0
  106. package/dist/subpath/TxScope.mjs +138 -0
  107. package/dist/subpath/TxScope.mjs.map +1 -0
  108. package/dist/subpath/TypeTool.cjs +2 -0
  109. package/dist/subpath/TypeTool.cjs.map +1 -0
  110. package/dist/subpath/TypeTool.mjs +9 -0
  111. package/dist/subpath/TypeTool.mjs.map +1 -0
  112. package/dist/subpath/Utils.cjs +2 -0
  113. package/dist/subpath/Utils.cjs.map +1 -0
  114. package/dist/subpath/Utils.mjs +835 -0
  115. package/dist/subpath/Utils.mjs.map +1 -0
  116. package/dist/subpath/VirtualTime.cjs +2 -0
  117. package/dist/subpath/VirtualTime.cjs.map +1 -0
  118. package/dist/subpath/VirtualTime.mjs +1186 -0
  119. package/dist/subpath/VirtualTime.mjs.map +1 -0
  120. package/dist/types/Arr.d.ts +2 -0
  121. package/dist/types/Concurrent/Lock/condition_variable.d.ts +138 -0
  122. package/dist/types/Concurrent/Lock/mutex.d.ts +185 -0
  123. package/dist/types/Concurrent/Lock/rwlock.d.ts +253 -0
  124. package/dist/types/Concurrent/Lock/semaphore.d.ts +208 -0
  125. package/dist/types/Concurrent/Valve/__export__.d.ts +5 -0
  126. package/dist/types/Concurrent/Valve/circuit-breaker.d.ts +146 -0
  127. package/dist/types/Concurrent/Valve/leaky-bucket.d.ts +115 -0
  128. package/dist/types/Concurrent/Valve/sliding-window.d.ts +91 -0
  129. package/dist/types/Concurrent/Valve/token-bucket.d.ts +68 -0
  130. package/dist/types/Concurrent/__export__.d.ts +15 -0
  131. package/dist/types/Concurrent/barrier.d.ts +255 -0
  132. package/dist/types/Concurrent/channel.d.ts +239 -0
  133. package/dist/types/Concurrent/delay.d.ts +42 -0
  134. package/dist/types/Concurrent/ext/map.d.ts +82 -0
  135. package/dist/types/Concurrent/ext/other.d.ts +113 -0
  136. package/dist/types/Concurrent/ext/race.d.ts +31 -0
  137. package/dist/types/Concurrent/ext/some.d.ts +64 -0
  138. package/dist/types/Concurrent/limiter.d.ts +131 -0
  139. package/dist/types/Concurrent/scheduler.d.ts +171 -0
  140. package/dist/types/Concurrent/task-scope.d.ts +282 -0
  141. package/dist/types/Concurrent.d.ts +2 -0
  142. package/dist/types/Errors.d.ts +66 -0
  143. package/dist/types/FetchQ.d.ts +2 -0
  144. package/dist/types/Fit/__export__.d.ts +5 -0
  145. package/dist/types/Fit/base.d.ts +325 -0
  146. package/dist/types/Fit/parser.d.ts +110 -0
  147. package/dist/types/Fit/standard-schema.d.ts +127 -0
  148. package/dist/types/Fit/sugar.d.ts +274 -0
  149. package/dist/types/Fit/tool.d.ts +585 -0
  150. package/dist/types/Fit.d.ts +2 -0
  151. package/dist/types/Lazy.d.ts +2 -0
  152. package/dist/types/Maps.d.ts +2 -0
  153. package/dist/types/Maybe/__export__.d.ts +6 -0
  154. package/dist/types/Maybe/base.d.ts +62 -0
  155. package/dist/types/Maybe/consumers-async.d.ts +58 -0
  156. package/dist/types/Maybe/consumers.d.ts +63 -0
  157. package/dist/types/Maybe/operators-async.d.ts +145 -0
  158. package/dist/types/Maybe/operators.d.ts +177 -0
  159. package/dist/types/Maybe/types.d.ts +12 -0
  160. package/dist/types/Maybe.d.ts +2 -0
  161. package/dist/types/MockClock/Timeline.d.ts +392 -0
  162. package/dist/types/MockClock/TimerHandle.d.ts +159 -0
  163. package/dist/types/MockClock/TimerHeap.d.ts +21 -0
  164. package/dist/types/MockClock/VirtualTimeManager.d.ts +23 -0
  165. package/dist/types/MockClock/__export__.d.ts +104 -0
  166. package/dist/types/MockClock/hooks/__export__.d.ts +9 -0
  167. package/dist/types/MockClock/hooks/hookAbortSignal.d.ts +3 -0
  168. package/dist/types/MockClock/hooks/hookDate.d.ts +3 -0
  169. package/dist/types/MockClock/hooks/hookIntl.d.ts +3 -0
  170. package/dist/types/MockClock/hooks/hookMessageChannel.d.ts +3 -0
  171. package/dist/types/MockClock/hooks/hookMicrotasks.d.ts +3 -0
  172. package/dist/types/MockClock/hooks/hookOs.d.ts +3 -0
  173. package/dist/types/MockClock/hooks/hookPerformance.d.ts +3 -0
  174. package/dist/types/MockClock/hooks/hookProcess.d.ts +3 -0
  175. package/dist/types/MockClock/hooks/hookTimers.d.ts +3 -0
  176. package/dist/types/MockClock/types.d.ts +103 -0
  177. package/dist/types/Other/FetchQ.d.ts +320 -0
  178. package/dist/types/Other/deque.d.ts +59 -0
  179. package/dist/types/Other/disjointSet.d.ts +53 -0
  180. package/dist/types/Other/heap.d.ts +41 -0
  181. package/dist/types/Other/lazy.d.ts +127 -0
  182. package/dist/types/Other/queue.d.ts +42 -0
  183. package/dist/types/Other/secret.d.ts +111 -0
  184. package/dist/types/Other/stack.d.ts +40 -0
  185. package/dist/types/Reactive/__export__.d.ts +4 -0
  186. package/dist/types/Reactive/event_emitter.d.ts +195 -0
  187. package/dist/types/Reactive/flow-combination.d.ts +74 -0
  188. package/dist/types/Reactive/flow.d.ts +180 -0
  189. package/dist/types/Reactive/pace.d.ts +80 -0
  190. package/dist/types/Reactive.d.ts +2 -0
  191. package/dist/types/Reader/__export-readerT__.d.ts +4 -0
  192. package/dist/types/Reader/__export-reader__.d.ts +4 -0
  193. package/dist/types/Reader/local.d.ts +39 -0
  194. package/dist/types/Reader/reader-async.d.ts +84 -0
  195. package/dist/types/Reader/reader.d.ts +96 -0
  196. package/dist/types/Reader/readerT-async.d.ts +186 -0
  197. package/dist/types/Reader/readerT.d.ts +178 -0
  198. package/dist/types/Reader/types.d.ts +37 -0
  199. package/dist/types/Reader.d.ts +2 -0
  200. package/dist/types/ReaderT.d.ts +2 -0
  201. package/dist/types/Resource/TxScope-async.d.ts +86 -0
  202. package/dist/types/Resource/TxScope.d.ts +85 -0
  203. package/dist/types/Resource/__export-TxScope__.d.ts +2 -0
  204. package/dist/types/Resource/__export-resource__.d.ts +2 -0
  205. package/dist/types/Resource/resource-async.d.ts +79 -0
  206. package/dist/types/Resource/resource.d.ts +78 -0
  207. package/dist/types/Resource/types.d.ts +79 -0
  208. package/dist/types/Resource.d.ts +2 -0
  209. package/dist/types/Result/Consumers/branch-async.d.ts +77 -0
  210. package/dist/types/Result/Consumers/branch.d.ts +70 -0
  211. package/dist/types/Result/Consumers/inspect.d.ts +66 -0
  212. package/dist/types/Result/Operators/Async/combine-async.d.ts +69 -0
  213. package/dist/types/Result/Operators/Async/partition-async.d.ts +29 -0
  214. package/dist/types/Result/Operators/Async/reduce-async.d.ts +15 -0
  215. package/dist/types/Result/Operators/Async/transform-async.d.ts +90 -0
  216. package/dist/types/Result/Operators/combine.d.ts +60 -0
  217. package/dist/types/Result/Operators/flatten.d.ts +26 -0
  218. package/dist/types/Result/Operators/partition.d.ts +25 -0
  219. package/dist/types/Result/Operators/reduce.d.ts +12 -0
  220. package/dist/types/Result/Operators/transform.d.ts +70 -0
  221. package/dist/types/Result/__export__.d.ts +14 -0
  222. package/dist/types/Result/base.d.ts +115 -0
  223. package/dist/types/Result/types.d.ts +34 -0
  224. package/dist/types/Result.d.ts +2 -0
  225. package/dist/types/Sets.d.ts +2 -0
  226. package/dist/types/Str.d.ts +2 -0
  227. package/dist/types/TxScope.d.ts +2 -0
  228. package/dist/types/TypeTool.d.ts +2 -0
  229. package/dist/types/Utils/Array/__export__.d.ts +10 -0
  230. package/dist/types/Utils/Array/filtering.d.ts +89 -0
  231. package/dist/types/Utils/Array/flatten.d.ts +45 -0
  232. package/dist/types/Utils/Array/grouping.d.ts +44 -0
  233. package/dist/types/Utils/Array/iteration.d.ts +86 -0
  234. package/dist/types/Utils/Array/operators.d.ts +62 -0
  235. package/dist/types/Utils/Array/randomization.d.ts +76 -0
  236. package/dist/types/Utils/Array/set.d.ts +108 -0
  237. package/dist/types/Utils/Array/slice.d.ts +189 -0
  238. package/dist/types/Utils/Array/sorting.d.ts +55 -0
  239. package/dist/types/Utils/Array/zip.d.ts +93 -0
  240. package/dist/types/Utils/Functions/__export__.d.ts +5 -0
  241. package/dist/types/Utils/Functions/base.d.ts +157 -0
  242. package/dist/types/Utils/Functions/curry.d.ts +73 -0
  243. package/dist/types/Utils/Functions/debounce.d.ts +240 -0
  244. package/dist/types/Utils/Functions/defer.d.ts +43 -0
  245. package/dist/types/Utils/Functions/pipe.d.ts +205 -0
  246. package/dist/types/Utils/Map.d.ts +284 -0
  247. package/dist/types/Utils/Math.d.ts +225 -0
  248. package/dist/types/Utils/Object/__export__.d.ts +2 -0
  249. package/dist/types/Utils/Object/base.d.ts +131 -0
  250. package/dist/types/Utils/Object/clone.d.ts +81 -0
  251. package/dist/types/Utils/Predicates.d.ts +361 -0
  252. package/dist/types/Utils/Set.d.ts +105 -0
  253. package/dist/types/Utils/String.d.ts +217 -0
  254. package/dist/types/Utils/__export__.d.ts +9 -0
  255. package/dist/types/Utils/type-tool.d.ts +168 -0
  256. package/dist/types/Utils.d.ts +2 -0
  257. package/dist/types/VirtualTime.d.ts +2 -0
  258. package/dist/types/helper.d.ts +71 -0
  259. package/dist/types/index.d.ts +21 -0
  260. package/dist/types/unknown-error.d.ts +98 -0
  261. package/package.json +179 -0
@@ -0,0 +1,180 @@
1
+ import { MaybePromise } from '../Utils/type-tool';
2
+ /**
3
+ * Symbol indicating the flow should continue processing.
4
+ * When a controller returns this symbol, the flow keeps waiting for the next value.
5
+ */
6
+ export declare const FlowContinue: unique symbol;
7
+ /**
8
+ * Stops the flow with the given return value.
9
+ * When a controller returns this, the flow completes and resolves with the value.
10
+ * @template T - The type of the return value.
11
+ * @param value - The value to return.
12
+ * @returns The same value passed in.
13
+ */
14
+ export declare const FlowStop: <T>(value: T) => T;
15
+ type FlowController<T, R> = (value: T, iteration: number, signal: AbortSignal | undefined) => MaybePromise<R | typeof FlowContinue>;
16
+ type SwitchFlowController<T, R> = (value: T, iteration: number, signal: AbortSignal) => MaybePromise<R | typeof FlowContinue>;
17
+ /**
18
+ * Options for consuming a Flow.
19
+ * @template R - The return type of the consume operation.
20
+ */
21
+ interface ConsumeOptions<R> {
22
+ /** Callback invoked when the flow completes normally. */
23
+ on_complete?: () => MaybePromise<R>;
24
+ /** Callback invoked when the flow errors. */
25
+ on_error?: (err: unknown) => MaybePromise<R>;
26
+ /** Optional AbortSignal to cancel the consume operation. */
27
+ signal?: AbortSignal;
28
+ }
29
+ interface PendingItem<R = unknown> {
30
+ resolve: (value: R) => void;
31
+ reject: (err: unknown) => void;
32
+ on_complete?: () => MaybePromise<R>;
33
+ on_error?: (err: unknown) => MaybePromise<R>;
34
+ queue_index: number;
35
+ }
36
+ export interface Observer<T> {
37
+ next?: (value: T) => void;
38
+ error?: (err: unknown) => void;
39
+ complete?: () => void;
40
+ }
41
+ export type Unsubscribable = Readonly<{
42
+ unsubscribe: () => void;
43
+ [Symbol.dispose](): void;
44
+ }>;
45
+ /**
46
+ * A reactive stream that emits values to subscribers.
47
+ * Supports both push-based (observer pattern) and pull-based (async iterator) consumption.
48
+ * @template T - The type of values emitted by this flow.
49
+ */
50
+ export declare class Flow<T> {
51
+ protected observers: Set<Observer<T>>;
52
+ protected teardowns: (() => void)[];
53
+ protected has_error: boolean;
54
+ protected is_completed: boolean;
55
+ protected thrown_error: unknown;
56
+ protected pending_items: (PendingItem<unknown> | null)[];
57
+ protected queue_head: number;
58
+ protected broadcast(value: T): void;
59
+ protected broadcastError(err: unknown): void;
60
+ protected broadcastComplete(): void;
61
+ protected disposeInternal(): void;
62
+ protected shouldCompact(): boolean;
63
+ protected compactQueue(): void;
64
+ protected removePendingItem(item: PendingItem): void;
65
+ /** Returns true if the flow has errored or completed. */
66
+ get closed(): boolean;
67
+ /**
68
+ * Registers a teardown function to be called when the flow completes or errors.
69
+ * If the flow is already closed, the teardown is called immediately.
70
+ */
71
+ addTeardown(teardown: () => void): void;
72
+ /**
73
+ * Subscribes to the flow with an observer or callback.
74
+ * @param observerOrNext - An Observer object or a callback function for next values.
75
+ * @returns An Unsubscribable that can be used to unsubscribe.
76
+ */
77
+ subscribe(observerOrNext: Observer<T> | ((v: T) => void)): Unsubscribable;
78
+ /** Emits a value to all subscribers. */
79
+ next(value: T): void;
80
+ /** Signals an error to all subscribers and completes the flow. */
81
+ error(err: unknown): void;
82
+ /** Signals completion to all subscribers. */
83
+ complete(): void;
84
+ protected createPendingItem<R>(): PendingItem<R>;
85
+ /**
86
+ * Consumes values from the flow until the controller returns a value.
87
+ * Each emitted value is passed to the controller, which can return:
88
+ * - FlowContinue: keep waiting for more values
89
+ * - Any other value: resolve the promise with that value
90
+ * @template R - The return type of the consume operation.
91
+ * @param controller - Function called for each emitted value.
92
+ * @param options - Optional callbacks for completion/error and abort signal.
93
+ * @returns Promise that resolves when the controller returns a value.
94
+ */
95
+ consume<R>(controller: FlowController<T, R>, options?: ConsumeOptions<R>): Promise<R>;
96
+ /**
97
+ * Similar to consume, but cancels the previous controller call when a new value arrives.
98
+ * Useful for scenarios like search-as-you-type where only the latest input matters.
99
+ * @template R - The return type of the consume operation.
100
+ * @param controller - Function called for each emitted value with an AbortSignal.
101
+ * @param options - Optional callbacks for completion/error and abort signal.
102
+ * @returns Promise that resolves when the controller returns a value.
103
+ */
104
+ switchConsume<R>(controller: SwitchFlowController<T, R>, options?: ConsumeOptions<R>): Promise<R>;
105
+ /** Returns an async iterator for the flow, enabling for-await-of syntax. */
106
+ [Symbol.asyncIterator](): AsyncIterator<T>;
107
+ }
108
+ /**
109
+ * A Flow variant that processes values sequentially.
110
+ * Unlike the base Flow, SerialFlow ensures each value is fully processed
111
+ * before the next one is handled, preventing concurrent controller executions.
112
+ * @template T - The type of values emitted by this flow.
113
+ */
114
+ export declare class SerialFlow<T> extends Flow<T> {
115
+ protected pending_queue: T[];
116
+ protected queue_read_index: number;
117
+ protected is_consuming: boolean;
118
+ switchConsume(): never;
119
+ /**
120
+ * Consumes values sequentially, ensuring each value is fully processed before the next.
121
+ * Values emitted during processing are queued and processed in order.
122
+ */
123
+ consume<R>(controller: FlowController<T, R>, options?: ConsumeOptions<R>): Promise<R>;
124
+ }
125
+ /**
126
+ * A Flow that always has a current value and emits it to new subscribers immediately.
127
+ * Similar to RxJS's BehaviorSubject.
128
+ * @template T - The type of the current value.
129
+ */
130
+ export declare class BehaviorFlow<T> extends Flow<T> {
131
+ private _value;
132
+ constructor(initialValue: T);
133
+ /** Returns the current value. */
134
+ get value(): T;
135
+ /**
136
+ * Subscribes to the flow and immediately receives the current value.
137
+ * @param observerOrNext - An Observer object or a callback function.
138
+ * @returns An Unsubscribable that can be used to unsubscribe.
139
+ */
140
+ subscribe(observerOrNext: Observer<T> | ((v: T) => void)): Unsubscribable;
141
+ /** Updates the current value and emits it to all subscribers. */
142
+ next(value: T): void;
143
+ }
144
+ /** Function type that produces values into a Flow. */
145
+ export type FlowProducer<T> = (flow: Flow<T>) => (() => void) | void;
146
+ /**
147
+ * A Flow that starts producing values only when subscribed (cold stream).
148
+ * Each subscription triggers the producer function.
149
+ * @template T - The type of values emitted by this flow.
150
+ */
151
+ export declare class ColdFlow<T> extends Flow<T> {
152
+ private producer;
153
+ constructor(producer: FlowProducer<T>);
154
+ /**
155
+ * Subscribes to the flow and starts the producer.
156
+ * The producer is called once per subscription.
157
+ */
158
+ subscribe(observerOrNext: Observer<T> | ((v: T) => void)): Unsubscribable;
159
+ }
160
+ /** Creates a Flow from a producer function. */
161
+ export declare function fromProducer<T>(producer: FlowProducer<T>): Flow<T>;
162
+ /** Creates a SerialFlow from a producer function. */
163
+ export declare function fromSerialProducer<T>(producer: FlowProducer<T>): SerialFlow<T>;
164
+ /** Creates a Flow that emits the given values and completes. */
165
+ export declare function of<T>(...values: T[]): Flow<T>;
166
+ export declare function from<T>(source: Iterable<T>): Flow<T>;
167
+ export declare function from<T>(source: AsyncIterable<T>): Flow<T>;
168
+ export declare function from<T>(source: Promise<T>): Flow<T>;
169
+ export declare function from<T>(source: ArrayLike<T>): Flow<T>;
170
+ /**
171
+ * A SerialFlow that starts producing values only when subscribed.
172
+ * Combines cold stream behavior with sequential processing.
173
+ * @template T - The type of values emitted by this flow.
174
+ */
175
+ export declare class SerialColdFlow<T> extends SerialFlow<T> {
176
+ private producer;
177
+ constructor(producer: FlowProducer<T>);
178
+ subscribe(observerOrNext: Observer<T> | ((v: T) => void)): Unsubscribable;
179
+ }
180
+ export {};
@@ -0,0 +1,80 @@
1
+ import { Result } from '../Result/types';
2
+ import { MaybePromise } from '../Utils/type-tool';
3
+ type NextAction<R> = {
4
+ readonly value: R;
5
+ } | {
6
+ readonly delay: number;
7
+ };
8
+ /**
9
+ * @template R1 - The input result type from the executed function
10
+ * @template R2 - The output result type after pacing logic
11
+ */
12
+ type PaceFunction<R1, R2> = (output: Result<R1, unknown>, iteration: number, interval: number) => MaybePromise<NextAction<R2>>;
13
+ /**
14
+ * Signals the pacer to stop and return a value.
15
+ * @template T - The type of value to return
16
+ */
17
+ export declare const Stop: <T>(value: T) => {
18
+ value: T;
19
+ };
20
+ /**
21
+ * Signals the pacer to continue waiting with the specified delay.
22
+ */
23
+ export declare const Continue: (delay: number) => {
24
+ delay: number;
25
+ };
26
+ /**
27
+ * Calculates exponential backoff delay.
28
+ * @param attempt - Current attempt number (0-indexed)
29
+ * @param base - Base delay in milliseconds (default: 1000)
30
+ * @param max - Maximum delay cap in milliseconds (default: 30000)
31
+ */
32
+ export declare const expBackoff: (attempt: number, base?: number, max?: number) => number;
33
+ /**
34
+ * Exponential backoff with jitter strategies to prevent thundering herd.
35
+ * @param attempt - Current attempt number (0-indexed)
36
+ * @param base - Base delay in milliseconds (default: 1000)
37
+ * @param max - Maximum delay cap in milliseconds (default: 30000)
38
+ * @param jitter - Jitter strategy: 'full' | 'equal' | 'decorrelated' (default: 'full')
39
+ */
40
+ export declare const expJitter: (attempt: number, base?: number, max?: number, jitter?: "full" | "equal" | "decorrelated") => number;
41
+ /**
42
+ * Executes a function repeatedly with custom pacing logic.
43
+ *
44
+ * The pace function controls when to stop and what to return based on
45
+ * each iteration's result. Useful for implementing retry logic, polling,
46
+ * or any iterative async operation with custom backoff strategies.
47
+ *
48
+ * @template R1 - The return type of the executed function
49
+ * @template R2 - The final output type after pacing logic completes
50
+ * @param fn - The function to execute on each iteration
51
+ * @param pace - Controls iteration flow; return `Stop(value)` to complete or `Continue(ms)` to retry
52
+ * @param signal - Optional AbortSignal for cancellation
53
+ * @returns The value passed to `Stop()` when pacing completes
54
+ */
55
+ export declare function pacer<R1, R2>(fn: () => MaybePromise<R1>, pace: PaceFunction<R1, R2>, signal?: AbortSignal): Promise<R2>;
56
+ /**
57
+ * Options for retry operations with exponential backoff.
58
+ */
59
+ interface PaceRetryOptions {
60
+ /** Maximum number of retry attempts (default: 5) */
61
+ readonly maxRetries?: number;
62
+ /** Base delay in milliseconds for exponential backoff (default: 1000) */
63
+ readonly baseDelayMs?: number;
64
+ /** Maximum delay cap in milliseconds (default: 30000) */
65
+ readonly maxBackoffMs?: number;
66
+ /** Optional AbortSignal for cancellation */
67
+ signal?: AbortSignal;
68
+ }
69
+ /**
70
+ * Retries an async task with exponential backoff and jitter.
71
+ *
72
+ * @template T - The return type of the task
73
+ * @param task - The async function to retry
74
+ * @param options - Retry configuration options
75
+ * @param signal - Optional AbortSignal for cancellation
76
+ * @returns The result of the successful task execution
77
+ * @throws Last error if all retry attempts fail
78
+ */
79
+ export declare function retry<T>(task: () => MaybePromise<T>, options?: PaceRetryOptions): Promise<T>;
80
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './Reactive/__export__'
2
+ export {}
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export * from './readerT';
3
+ export * from './readerT-async';
4
+ export * from './local';
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export * from './reader';
3
+ export * from './reader-async';
4
+ export * from './local';
@@ -0,0 +1,39 @@
1
+ import { Reader, AsyncReader, ReaderT, AsyncReaderT } from './types';
2
+ /**
3
+ * Implements the local function for ReaderT type.
4
+ * @typeParam R - Environment type
5
+ * @typeParam E - Error type
6
+ * @typeParam A - Result type
7
+ * @param reader - Original ReaderT
8
+ * @param f_mod - Environment modification function that takes the current environment and returns a modified one
9
+ * @returns A new ReaderT that executes with the modified environment
10
+ */
11
+ export declare function local<R, E, A>(reader: ReaderT<R, E, A>, f_mod: (env: R) => R): ReaderT<R, E, A>;
12
+ /**
13
+ * Implements the local function for AsyncReaderT type.
14
+ * @typeParam R - Environment type
15
+ * @typeParam E - Error type
16
+ * @typeParam A - Result type
17
+ * @param reader - Original AsyncReaderT
18
+ * @param f_mod - Environment modification function that takes the current environment and returns a modified one
19
+ * @returns A new AsyncReaderT that executes with the modified environment
20
+ */
21
+ export declare function local<R, E, A>(reader: AsyncReaderT<R, E, A>, f_mod: (env: R) => R): AsyncReaderT<R, E, A>;
22
+ /**
23
+ * Implements the local function for Reader type.
24
+ * @typeParam R - Environment type
25
+ * @typeParam A - Result type
26
+ * @param reader - Original Reader
27
+ * @param f_mod - Environment modification function that takes the current environment and returns a modified one
28
+ * @returns A new Reader that executes with the modified environment
29
+ */
30
+ export declare function local<R, A>(reader: Reader<R, A>, f_mod: (env: R) => R): Reader<R, A>;
31
+ /**
32
+ * Implements the local function for AsyncReader type.
33
+ * @typeParam R - Environment type
34
+ * @typeParam A - Result type
35
+ * @param reader - Original AsyncReader
36
+ * @param f_mod - Environment modification function that takes the current environment and returns a modified one
37
+ * @returns A new AsyncReader that executes with the modified environment
38
+ */
39
+ export declare function local<R, A>(reader: AsyncReader<R, A>, f_mod: (env: R) => R): AsyncReader<R, A>;
@@ -0,0 +1,84 @@
1
+ import { AsyncReader } from './types';
2
+ /**
3
+ * Creates an AsyncReader that ignores the environment (R) and resolves immediately
4
+ * with the given value (A). This is the 'return' or 'pure' operation.
5
+ * @typeParam R - The Environment type.
6
+ * @typeParam A - The type of the value to wrap.
7
+ * @param a - The value to be wrapped in AsyncReader.
8
+ * @returns AsyncReader<R, A> that resolves to 'a'.
9
+ */
10
+ export declare const ofAsync: <R, A>(a: A) => AsyncReader<R, A>;
11
+ /**
12
+ * Creates an AsyncReader that retrieves the environment (R) and resolves with it.
13
+ * This is the 'ask' operation in Reader Monad.
14
+ * @typeParam R - The Environment type.
15
+ * @returns AsyncReader<R, R> that resolves to the environment 'R'.
16
+ */
17
+ export declare const askAsync: <R>() => AsyncReader<R, R>;
18
+ /**
19
+ * Applies a function (A) => B to the value inside the AsyncReader, maintaining the
20
+ * environment context. This is the 'map' operation (Functor).
21
+ * @typeParam R - The Environment type.
22
+ * @typeParam A - The type of the input value.
23
+ * @typeParam B - The type of the output value.
24
+ * @param reader - The source AsyncReader<R, A>.
25
+ * @param f - The mapping function (A) => B.
26
+ * @returns AsyncReader<R, B> containing the mapped value.
27
+ */
28
+ export declare const mapAsync: <R, A, B>(reader: AsyncReader<R, A>, f: (a: A) => B) => AsyncReader<R, B>;
29
+ /**
30
+ * Chains two AsyncReader computations. The result of the first reader (A) is used to
31
+ * produce the second reader (AsyncReader<R, B>). This is the 'flatMap' or 'bind' operation (Monad).
32
+ * @typeParam R - The Environment type.
33
+ * @typeParam A - The type of the input value of the first reader.
34
+ * @typeParam B - The type of the final output value.
35
+ * @param reader - The initial AsyncReader<R, A>.
36
+ * @param f - A function that takes the result of 'reader' and returns the next AsyncReader<R, B>.
37
+ * @returns AsyncReader<R, B> containing the final result.
38
+ */
39
+ export declare const anThenAsync: <R, A, B>(reader: AsyncReader<R, A>, f: (a: A) => AsyncReader<R, B>) => AsyncReader<R, B>;
40
+ /**
41
+ * Applies a function contained within an AsyncReader (R, (A) => B) to a value
42
+ * contained within another AsyncReader (R, A), preserving the environment. This is the 'ap' operation (Applicative Functor).
43
+ * @typeParam R - The Environment type.
44
+ * @typeParam A - The type of the input value.
45
+ * @typeParam B - The type of the output value.
46
+ * @param reader_fab - AsyncReader containing the function (A) => B.
47
+ * @param reader_a - AsyncReader containing the input value A.
48
+ * @returns AsyncReader<R, B> containing the result of applying the function.
49
+ */
50
+ export declare const apAsync: <R, A, B>(reader_fab: AsyncReader<R, (a: A) => B>, reader_a: AsyncReader<R, A>) => AsyncReader<R, B>;
51
+ /**
52
+ * Performs a side effect using the result of the first AsyncReader, and then returns
53
+ * the original result, ignoring the side effect's return value.
54
+ * Note: The side effect function must return an AsyncReader.
55
+ * @typeParam R - The Environment type.
56
+ * @typeParam A - The type of the original value to be passed through.
57
+ * @param reader - The source AsyncReader<R, A>.
58
+ * @param f - A function that takes A and returns an AsyncReader<R, unknown> (the side effect).
59
+ * @returns AsyncReader<R, A> containing the original value.
60
+ */
61
+ export declare const tapAsync: <R, A>(reader: AsyncReader<R, A>, f: (a: A) => AsyncReader<R, unknown>) => AsyncReader<R, A>;
62
+ /**
63
+ * Asynchronously lifts a binary function (A, B) => C into the AsyncReader context.
64
+ * It combines two AsyncReaders using the Applicative 'ap' operation.
65
+ * @typeParam R - The Environment type
66
+ * @typeParam A - The type of the first input value
67
+ * @typeParam B - The type of the second input value
68
+ * @typeParam C - The type of the output value
69
+ * @param f_abc - The binary function (A, B) => C
70
+ * @returns A function that takes two AsyncReaders and returns an AsyncReader<R, C>
71
+ */
72
+ export declare const liftA2Async: <R, A, B, C>(f_abc: (a: A, b: B) => C) => (reader_a: AsyncReader<R, A>, reader_b: AsyncReader<R, B>) => AsyncReader<R, C>;
73
+ /**
74
+ * Asynchronously lifts a ternary function (A, B, C) => D into the AsyncReader context.
75
+ * It combines three AsyncReaders using the Applicative 'ap' operation.
76
+ * @typeParam R - The Environment type
77
+ * @typeParam A - The type of the first input value
78
+ * @typeParam B - The type of the second input value
79
+ * @typeParam C - The type of the third input value
80
+ * @typeParam D - The type of the output value
81
+ * @param f_abcd - The ternary function (A, B, C) => D
82
+ * @returns A function that takes three AsyncReaders and returns an AsyncReader<R, D>
83
+ */
84
+ export declare const liftA3Async: <R, A, B, C, D>(f_abcd: (a: A, b: B, c: C) => D) => (reader_a: AsyncReader<R, A>, reader_b: AsyncReader<R, B>, reader_c: AsyncReader<R, C>) => AsyncReader<R, D>;
@@ -0,0 +1,96 @@
1
+ import { Reader } from './types';
2
+ /**
3
+ * Creates a Reader that ignores the environment (R) and returns the given value (A).
4
+ * This is the 'return' or 'pure' operation (Applicative/Monad).
5
+ *
6
+ * @typeParam R - The Environment type.
7
+ * @typeParam A - The type of the value to wrap.
8
+ * @param a - The value to be wrapped in Reader.
9
+ * @returns Reader<R, A> that returns 'a'.
10
+ */
11
+ export declare const of: <R, A>(a: A) => Reader<R, A>;
12
+ /**
13
+ * Applies a function contained within a Reader (R, (A) => B) to a value
14
+ * contained within another Reader (R, A), preserving the environment.
15
+ * This is the 'ap' operation (Applicative Functor).
16
+ *
17
+ * @typeParam R - The Environment type.
18
+ * @typeParam A - The type of the input value.
19
+ * @typeParam B - The type of the output value.
20
+ * @param reader_fab - Reader containing the function (A) => B.
21
+ * @param reader_a - Reader containing the input value A.
22
+ * @returns Reader<R, B> containing the result of applying the function.
23
+ */
24
+ export declare const ap: <R, A, B>(reader_fab: Reader<R, (a: A) => B>, reader_a: Reader<R, A>) => Reader<R, B>;
25
+ /**
26
+ * Creates a Reader that retrieves the environment (R) and returns it.
27
+ * This is the 'ask' operation in Reader Monad.
28
+ *
29
+ * @typeParam R - The Environment type.
30
+ * @returns Reader<R, R> that returns the environment 'R'.
31
+ */
32
+ export declare const ask: <R>() => Reader<R, R>;
33
+ /**
34
+ * Applies a function (A) => B to the value inside the Reader, maintaining the
35
+ * environment context. This is the 'map' operation (Functor).
36
+ *
37
+ * @typeParam R - The Environment type.
38
+ * @typeParam A - The type of the input value.
39
+ * @typeParam B - The type of the output value.
40
+ * @param reader - The source Reader<R, A>.
41
+ * @param f - The mapping function (A) => B.
42
+ * @returns Reader<R, B> containing the mapped value.
43
+ */
44
+ export declare const map: <R, A, B>(reader: Reader<R, A>, f: (a: A) => B) => Reader<R, B>;
45
+ /**
46
+ * Chains two Reader computations. The result of the first reader (A) is used to
47
+ * produce the second reader (Reader<R, B>).
48
+ * This is the 'flatMap' or 'bind' operation (Monad).
49
+ *
50
+ * @typeParam R - The Environment type.
51
+ * @typeParam A - The type of the input value of the first reader.
52
+ * @typeParam B - The type of the final output value.
53
+ * @param reader - The initial Reader<R, A>.
54
+ * @param f - A function that takes the result of 'reader' and returns the next Reader<R, B>.
55
+ * @returns Reader<R, B> containing the final result.
56
+ */
57
+ export declare const anThen: <R, A, B>(reader: Reader<R, A>, f: (a: A) => Reader<R, B>) => Reader<R, B>;
58
+ /**
59
+ * Performs a side effect using the result of the first Reader, and then returns
60
+ * the original result, ignoring the side effect's return value.
61
+ * Note: The side effect function must return a Reader.
62
+ *
63
+ * @typeParam R - The Environment type.
64
+ * @typeParam A - The type of the original value to be passed through.
65
+ * @param reader - The source Reader<R, A>.
66
+ * @param f - A function that takes A and returns a Reader<R, unknown> (the side effect).
67
+ * @returns Reader<R, A> containing the original value.
68
+ */
69
+ export declare const tap: <R, A>(reader: Reader<R, A>, f: (a: A) => Reader<R, unknown>) => Reader<R, A>;
70
+ /**
71
+ * Lifts a binary function (A, B) => C into the Reader context.
72
+ * It takes a standard two-argument function and two Readers, and returns a new Reader
73
+ * that applies the function to the values within the Readers. This is achieved via Currying and 'ap'.
74
+ *
75
+ * @typeParam R - The Environment type
76
+ * @typeParam A - The type of the first input value
77
+ * @typeParam B - The type of the second input value
78
+ * @typeParam C - The type of the output value
79
+ * @param f_abc - The binary function (A, B) => C
80
+ * @returns A function that takes two Readers and returns a Reader<R, C>
81
+ */
82
+ export declare const liftA2: <R, A, B, C>(f_abc: (a: A, b: B) => C) => (reader_a: Reader<R, A>, reader_b: Reader<R, B>) => Reader<R, C>;
83
+ /**
84
+ * Lifts a ternary function (A, B, C) => D into the Reader context.
85
+ * It takes a standard three-argument function and three Readers, and returns a new Reader
86
+ * that applies the function to the values within the Readers. This is built upon liftA2 and 'ap'.
87
+ *
88
+ * @typeParam R - The Environment type
89
+ * @typeParam A - The type of the first input value
90
+ * @typeParam B - The type of the second input value
91
+ * @typeParam C - The type of the third input value
92
+ * @typeParam D - The type of the output value
93
+ * @param f_abcd - The ternary function (A, B, C) => D
94
+ * @returns A function that takes three Readers and returns a Reader<R, D>
95
+ */
96
+ export declare const liftA3: <R, A, B, C, D>(f_abcd: (a: A, b: B, c: C) => D) => (reader_a: Reader<R, A>, reader_b: Reader<R, B>, reader_c: Reader<R, C>) => Reader<R, D>;