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,79 @@
1
+ import { StateOpened, StateClosed, AnyCleaner, NoneType } from './types';
2
+ declare const _data: unique symbol;
3
+ declare const _cleanup: unique symbol;
4
+ /**
5
+ * Asynchronous resource management class.
6
+ * @typeParam T - The type of the resource data
7
+ * @typeParam S - The state type (opened or closed)
8
+ */
9
+ export declare class ResourceAsync<T, S extends StateOpened | StateClosed> {
10
+ private state;
11
+ [_data]: T | NoneType;
12
+ [_cleanup]: AnyCleaner<T> | undefined;
13
+ private constructor();
14
+ /**
15
+ * Creates a new opened asynchronous resource.
16
+ * @typeParam D - The type of the resource data
17
+ * @param data - The resource data
18
+ * @param cleaner - Optional asynchronous cleanup function
19
+ * @returns A new opened asynchronous resource
20
+ */
21
+ static open<D>(data: D, cleaner?: AnyCleaner<D>): ResourceAsync<D, StateOpened>;
22
+ /**
23
+ * Asynchronously disposes the resource (cleanup).
24
+ * @returns Promise that resolves when disposal is complete
25
+ */
26
+ [Symbol.asyncDispose](this: ResourceAsync<T, StateOpened>): Promise<void>;
27
+ }
28
+ /**
29
+ * Union type for asynchronous resource states.
30
+ * @typeParam T - The type of the resource data
31
+ */
32
+ export type ResAsyncType<T> = ResourceAsync<T, StateOpened> | ResourceAsync<T, StateClosed>;
33
+ /**
34
+ * Uses an asynchronous resource with a callback function.
35
+ * @typeParam T - The type of the resource data
36
+ * @typeParam R - The return type of the callback
37
+ * @param resource - The opened asynchronous resource
38
+ * @param callback - Function to process the resource data
39
+ * @returns Promise with the result of the callback
40
+ * @throws Error if resource is already disposed
41
+ */
42
+ export declare function useAsync<T, R>(resource: ResourceAsync<T, StateOpened>, callback: (data: T) => Promise<R> | R): Promise<R>;
43
+ /**
44
+ * Performs a side effect on an asynchronous resource and returns the resource.
45
+ * @typeParam T - The type of the resource data
46
+ * @typeParam R - The return type of the side effect function
47
+ * @param resource - The opened asynchronous resource
48
+ * @param fn - Side effect function to execute
49
+ * @returns The same resource after executing the side effect
50
+ * @throws Error if resource is already disposed
51
+ */
52
+ export declare function execAsync<T, R>(resource: ResourceAsync<T, StateOpened>, fn: (data: T) => Promise<R> | R): Promise<ResourceAsync<T, StateOpened>>;
53
+ /**
54
+ * Closes an asynchronous resource (disposes it).
55
+ * @typeParam T - The type of the resource data
56
+ * @param resource - The opened asynchronous resource to close
57
+ * @returns The closed asynchronous resource
58
+ */
59
+ export declare function closeAsync<T>(resource: ResourceAsync<T, StateOpened>): Promise<ResourceAsync<T, StateClosed>>;
60
+ /**
61
+ * Executes an asynchronous or synchronous function on the resource and then closes it,
62
+ * guaranteeing asynchronous cleanup even if the function throws.
63
+ * @typeParam T - The type of the resource data
64
+ * @typeParam R - The return type of the function
65
+ * @param resource - The opened asynchronous resource
66
+ * @param fn - Asynchronous or synchronous function to execute before closing
67
+ * @returns A promise that resolves to the closed asynchronous resource
68
+ */
69
+ export declare function disposeAsync<T, R>(resource: ResourceAsync<T, StateOpened>, fn: (data: T) => Promise<R> | R): Promise<ResourceAsync<T, StateClosed>>;
70
+ /**
71
+ * Reopens a closed asynchronous resource with new data.
72
+ * @typeParam T - The type of the resource data
73
+ * @param resource - The closed asynchronous resource
74
+ * @param data - New data for the resource
75
+ * @param cleaner - Optional new cleanup function
76
+ * @returns The reopened asynchronous resource
77
+ */
78
+ export declare function reopenAsync<T>(resource: ResourceAsync<T, StateClosed>, data: T, cleaner?: AnyCleaner<T>): ResourceAsync<T, StateOpened>;
79
+ export {};
@@ -0,0 +1,78 @@
1
+ import { StateOpened, StateClosed, NoneType, Cleaner } from './types';
2
+ declare const _data: unique symbol;
3
+ declare const _cleanup: unique symbol;
4
+ /**
5
+ * Synchronous resource management class.
6
+ * @typeParam T - The type of the resource data
7
+ * @typeParam S - The state type (opened or closed)
8
+ */
9
+ export declare class Resource<T, S extends StateOpened | StateClosed> {
10
+ private state;
11
+ [_data]: T | NoneType;
12
+ [_cleanup]: Cleaner<T> | undefined;
13
+ private constructor();
14
+ /**
15
+ * Creates a new opened synchronous resource.
16
+ * @typeParam D - The type of the resource data
17
+ * @param data - The resource data
18
+ * @param cleaner - Optional synchronous cleanup function
19
+ * @returns A new opened synchronous resource
20
+ */
21
+ static open<D>(data: D, cleaner?: Cleaner<D>): Resource<D, StateOpened>;
22
+ /**
23
+ * Synchronously disposes the resource (cleanup).
24
+ */
25
+ [Symbol.dispose](this: Resource<T, StateOpened>): void;
26
+ }
27
+ /**
28
+ * Union type for synchronous resource states.
29
+ * @typeParam T - The type of the resource data
30
+ */
31
+ export type ResType<T> = Resource<T, StateOpened> | Resource<T, StateClosed>;
32
+ /**
33
+ * Uses a synchronous resource with a callback function.
34
+ * @typeParam T - The type of the resource data
35
+ * @typeParam R - The return type of the callback
36
+ * @param resource - The opened synchronous resource
37
+ * @param fn - Function to process the resource data
38
+ * @returns The result of the callback
39
+ * @throws Error if resource is already disposed
40
+ */
41
+ export declare function use<T, R>(resource: Resource<T, StateOpened>, fn: (data: T) => R): R;
42
+ /**
43
+ * Performs a side effect on a synchronous resource and returns the resource.
44
+ * @typeParam T - The type of the resource data
45
+ * @typeParam R - The return type of the side effect function
46
+ * @param resource - The opened synchronous resource
47
+ * @param fn - Side effect function to execute
48
+ * @returns The same resource after executing the side effect
49
+ * @throws Error if resource is already disposed
50
+ */
51
+ export declare function exec<T, R>(resource: Resource<T, StateOpened>, fn: (data: T) => R): Resource<T, StateOpened>;
52
+ /**
53
+ * Closes a synchronous resource (disposes it).
54
+ * @typeParam T - The type of the resource data
55
+ * @param resource - The opened synchronous resource to close
56
+ * @returns The closed synchronous resource
57
+ */
58
+ export declare function close<T>(resource: Resource<T, StateOpened>): Resource<T, StateClosed>;
59
+ /**
60
+ * Executes a function on the resource and then closes it,
61
+ * guaranteeing cleanup even if the function throws.
62
+ * @typeParam T - The type of the resource data
63
+ * @typeParam R - The return type of the function
64
+ * @param resource - The opened synchronous resource
65
+ * @param fn - Function to execute before closing
66
+ * @returns The closed synchronous resource
67
+ */
68
+ export declare function dispose<T, R>(resource: Resource<T, StateOpened>, fn: (data: T) => R): Resource<T, StateClosed>;
69
+ /**
70
+ * Reopens a closed synchronous resource with new data.
71
+ * @typeParam T - The type of the resource data
72
+ * @param resource - The closed synchronous resource
73
+ * @param data - New data for the resource
74
+ * @param cleaner - Optional new cleanup function
75
+ * @returns The reopened synchronous resource
76
+ */
77
+ export declare function reopen<T>(resource: Resource<T, StateClosed>, data: T, cleaner?: Cleaner<T>): Resource<T, StateOpened>;
78
+ export {};
@@ -0,0 +1,79 @@
1
+ import { MaybePromise } from '../Utils/type-tool';
2
+ /**
3
+ * Marker interface for opened state.
4
+ * @public
5
+ */
6
+ export interface StateOpened {
7
+ }
8
+ /**
9
+ * Marker interface for closed state.
10
+ */
11
+ export interface StateClosed {
12
+ }
13
+ /**
14
+ * Marker interface for committed state.
15
+ */
16
+ export interface StateCommit {
17
+ }
18
+ /**
19
+ * Marker interface for rolled back state.
20
+ */
21
+ export interface StateRollback {
22
+ }
23
+ /**
24
+ * Synchronous cleanup function type.
25
+ * @typeParam T - The type of the data to clean up
26
+ */
27
+ export type Cleaner<T> = (data: T) => void;
28
+ /**
29
+ * Asynchronous cleanup function type.
30
+ * @typeParam T - The type of the data to clean up
31
+ */
32
+ export type AsyncCleaner<T> = (data: T) => PromiseLike<void> | void;
33
+ /**
34
+ * Union type for any cleanup function (synchronous or asynchronous).
35
+ * @typeParam T - The type of the data to clean up
36
+ */
37
+ export type AnyCleaner<T> = Cleaner<T> | AsyncCleaner<T>;
38
+ /**
39
+ * Synchronous commit function type.
40
+ * @typeParam T - The type of the transaction data
41
+ */
42
+ export type CommitUp<T> = (data: T) => void;
43
+ /**
44
+ * Synchronous rollback function type.
45
+ * @typeParam T - The type of the transaction data
46
+ */
47
+ export type RollbackUp<T> = (data: T) => void;
48
+ /**
49
+ * Asynchronous commit function type.
50
+ * @typeParam T - The type of the transaction data
51
+ */
52
+ export type AsyncCommitUp<T> = (data: T) => MaybePromise<void>;
53
+ /**
54
+ * Asynchronous rollback function type.
55
+ * @typeParam T - The type of the transaction data
56
+ */
57
+ export type AsyncRollbackUp<T> = (data: T) => MaybePromise<void>;
58
+ /**
59
+ * Union type for any commit function (synchronous or asynchronous).
60
+ * @typeParam T - The type of the transaction data
61
+ */
62
+ export type AnyCommitUp<T> = CommitUp<T> | AsyncCommitUp<T>;
63
+ /**
64
+ * Union type for any rollback function (synchronous or asynchronous).
65
+ * @typeParam T - The type of the transaction data
66
+ */
67
+ export type AnyRollbackUp<T> = RollbackUp<T> | AsyncRollbackUp<T>;
68
+ /**
69
+ * A unique symbolic constant representing the absence of resources.
70
+ * * @remarks
71
+ * This is used as a placeholder within a `Resource` context to indicate
72
+ * that the resource pool is exhausted or no resource is available.
73
+ */
74
+ export declare const NONE: unique symbol;
75
+ /**
76
+ * Represents the type of the {@link NONE} constant.
77
+ * Use this type for type guards or function signatures that might return the `NONE` placeholder.
78
+ */
79
+ export type NoneType = typeof NONE;
@@ -0,0 +1,2 @@
1
+ export * from './Resource/__export-resource__'
2
+ export {}
@@ -0,0 +1,77 @@
1
+ import { AnyResult } from '../types';
2
+ import { UnknownError } from '../../unknown-error';
3
+ import { MaybePromise } from '../../Utils/type-tool';
4
+ /**
5
+ * Asynchronously executes different callback functions based on the Result state and returns Promise<R>.
6
+ * Catches exceptions thrown by the callbacks.
7
+ * @typeParam T - The type of the success value
8
+ * @typeParam E - The type of the error
9
+ * @typeParam R - The type of the return value
10
+ * @param result_promise - The Result or Promise<Result> to match
11
+ * @param onOk - The callback function for a successful state (Ok)
12
+ * @param onErr - The callback function for a failure state (Err)
13
+ * @param signal - Optional AbortSignal for cancellation
14
+ * @returns The Promise resolving to the return value of onOk or onErr, or an UnknownError if a callback throws
15
+ */
16
+ export declare function matchResultAsync<T, E, R>(result_promise: AnyResult<T, E>, onOk: (value: T, signal?: AbortSignal) => MaybePromise<R>, onErr: (error: E, signal?: AbortSignal) => MaybePromise<R>, signal?: AbortSignal): Promise<R | UnknownError>;
17
+ /**
18
+ * Asynchronously executes onOk if the Result is **Ok**; executes the optional onElse if **Err**.
19
+ * All exceptions thrown by the callbacks are caught and wrapped as UnknownError.
20
+ * @typeParam T - The type of the **Success Value** in the **Ok state**.
21
+ * @typeParam E - The type of the **Error** in the **Err state**.
22
+ * @typeParam R1 - The final resolved return type of the **onOk** callback.
23
+ * @param result_promise - The Result object or Promise<Result> to be checked.
24
+ * @param onOk - The callback executed if the Result is Ok. Returns R1 or Promise<R1>.
25
+ * @returns A Promise that resolves to the result of onOk (R1), or UnknownError if a callback throws, or **void** if the Result is Err.
26
+ */
27
+ export declare function ifOkAsync<T, E, R1>(result_promise: AnyResult<T, E>, onOk: (value: T) => MaybePromise<R1>): Promise<R1 | UnknownError | void>;
28
+ /**
29
+ * Asynchronously executes onOk if the Result is **Ok**; executes onElse if **Err**.
30
+ * All exceptions thrown by the callbacks are caught and wrapped as UnknownError.
31
+ * @typeParam T - The type of the **Success Value** in the **Ok state**.
32
+ * @typeParam E - The type of the **Error** in the **Err state**.
33
+ * @typeParam R1 - The final resolved return type of the **onOk** callback.
34
+ * @typeParam R2 - The final resolved return type of the **onElse** callback.
35
+ * @param result_promise - The Result object or Promise<Result> to be checked.
36
+ * @param onOk - The callback executed if the Result is Ok. Returns R1 or Promise<R1>.
37
+ * @param onElse - The callback executed if the Result is Err. Returns R2 or Promise<R2>.
38
+ * @returns A Promise that resolves to the result of onOk or onElse (R1 or R2), or UnknownError if a callback throws.
39
+ */
40
+ export declare function ifOkAsync<T, E, R1, R2>(result_promise: AnyResult<T, E>, onOk: (value: T) => MaybePromise<R1>, onElse: (error: E) => MaybePromise<R2>): Promise<R1 | R2 | UnknownError>;
41
+ /**
42
+ * Asynchronously executes onErr if the Result is **Err**; executes the optional onElse if **Ok**.
43
+ * All exceptions thrown by the callbacks are caught and wrapped as UnknownError.
44
+ * @typeParam T - The type of the **Success Value** in the **Ok state**.
45
+ * @typeParam E - The type of the **Error** in the **Err state**.
46
+ * @typeParam R1 - The final resolved return type of the **onErr** callback.
47
+ * @param result_promise - The Result object or Promise<Result> to be checked.
48
+ * @param onErr - The callback executed if the Result is Err. Returns R1 or Promise<R1>.
49
+ * @returns A Promise that resolves to the result of onErr (R1), or UnknownError if a callback throws, or **void** if the Result is Ok.
50
+ */
51
+ export declare function ifErrAsync<T, E, R1>(result_promise: AnyResult<T, E>, onErr: (error: E) => MaybePromise<R1>): Promise<R1 | UnknownError | void>;
52
+ /**
53
+ * Asynchronously executes onErr if the Result is **Err**; executes onElse if **Ok**.
54
+ * All exceptions thrown by the callbacks are caught and wrapped as UnknownError.
55
+ * @typeParam T - The type of the **Success Value** in the **Ok state**.
56
+ * @typeParam E - The type of the **Error** in the **Err state**.
57
+ * @typeParam R1 - The final resolved return type of the **onErr** callback.
58
+ * @typeParam R2 - The final resolved return type of the **onElse** callback.
59
+ * @param result_promise - The Result object or Promise<Result> to be checked.
60
+ * @param onErr - The callback executed if the Result is Err. Returns R1 or Promise<R1>.
61
+ * @param onElse - The callback executed if the Result is Ok. Returns R2 or Promise<R2>.
62
+ * @returns A Promise that resolves to the result of onErr or onElse (R1 or R2), or UnknownError if a callback throws.
63
+ */
64
+ export declare function ifErrAsync<T, E, R1, R2>(result_promise: AnyResult<T, E>, onErr: (error: E) => MaybePromise<R1>, onElse: (value: T) => MaybePromise<R2>): Promise<R1 | R2 | UnknownError>;
65
+ /**
66
+ * Asynchronously transforms the Result into a single type R.
67
+ * Uses mapFn on Success; uses defaultFn on Failure.
68
+ * Catches exceptions thrown by the callbacks.
69
+ * @typeParam T - The type of the success value
70
+ * @typeParam E - The type of the error
71
+ * @typeParam R - The type of the final return value
72
+ * @param result_promise - The Result or Promise<Result> to process
73
+ * @param defaultFn - The function to compute the default value on failure
74
+ * @param mapFn - The function to map the success value
75
+ * @returns The Promise resolving to the final return value, or an UnknownError if a callback throws
76
+ */
77
+ export declare function mapOrElseAsync<T, E, R>(result_promise: AnyResult<T, E>, defaultFn: (error: E) => MaybePromise<R>, mapFn: (value: T) => MaybePromise<R>): Promise<R | UnknownError>;
@@ -0,0 +1,70 @@
1
+ import { Result } from '../types';
2
+ /**
3
+ * Executes one of two callbacks based on whether the Result is Ok or Err,
4
+ * and returns the result of the executed callback.
5
+ * @typeParam T - The type of the success value in the Ok variant.
6
+ * @typeParam E - The type of the error in the Err variant.
7
+ * @typeParam R1 - The return type of the onOk callback.
8
+ * @typeParam R2 - The return type of the onErr callback.
9
+ * @param result - The Result object to match against.
10
+ * @param onOk - Callback executed if the Result is Ok. Receives the inner value (T).
11
+ * @param onErr - Callback executed if the Result is Err. Receives the inner error (E).
12
+ * @returns The result of either onOk or onErr, with type R1 | R2.
13
+ */
14
+ export declare const match: <T, E, R1, R2>(result: Result<T, E>, onOk: (value: T) => R1, onErr: (error: E) => R2) => R1 | R2;
15
+ /**
16
+ * Executes onOk if the Result is **Ok** (Success).
17
+ * @typeParam T - The type of the **Success Value** contained in the **Ok state**.
18
+ * @typeParam E - The type of the **Error** contained in the **Err state**.
19
+ * @typeParam R1 - The return type of the **onOk** callback.
20
+ * @param result - The Result object to check.
21
+ * @param onOk - The function executed when the Result is **Ok**, receiving the internal value (T).
22
+ * @returns The return value of onOk (R1) or **void** if the Result is Err.
23
+ */
24
+ export declare function ifOk<T, E, R1>(result: Result<T, E>, onOk: (value: T) => R1): R1 | void;
25
+ /**
26
+ * Executes onOk if the Result is **Ok**; executes onElse if **Err**.
27
+ * @typeParam T - The type of the **Success Value** contained in the **Ok state**.
28
+ * @typeParam E - The type of the **Error** contained in the **Err state**.
29
+ * @typeParam R1 - The return type of the **onOk** callback.
30
+ * @typeParam R2 - The return type of the **onElse** callback.
31
+ * @param result - The Result object to check.
32
+ * @param onOk - The function executed when the Result is **Ok**, receiving the internal value (T).
33
+ * @param onElse - The function executed when the Result is **Err**, receiving the internal error (E).
34
+ * @returns The return value of onOk (R1) or onElse (R2).
35
+ */
36
+ export declare function ifOk<T, E, R1, R2>(result: Result<T, E>, onOk: (value: T) => R1, onElse: (error: E) => R2): R1 | R2;
37
+ /**
38
+ * Executes onErr if the Result is **Err** (Failure).
39
+ * @typeParam T - The type of the **Success Value** contained in the **Ok state**.
40
+ * @typeParam E - The type of the **Error** contained in the **Err state**.
41
+ * @typeParam R1 - The return type of the **onErr** callback.
42
+ * @param result - The Result object to check.
43
+ * @param onErr - The function executed when the Result is **Err**, receiving the internal error (E).
44
+ * @returns The return value of onErr (R1) or **void** if the Result is Ok.
45
+ */
46
+ export declare function ifErr<T, E, R1>(result: Result<T, E>, onErr: (error: E) => R1): R1 | void;
47
+ /**
48
+ * Executes onErr if the Result is **Err**; executes onElse if **Ok**.
49
+ * @typeParam T - The type of the **Success Value** contained in the **Ok state**.
50
+ * @typeParam E - The type of the **Error** contained in the **Err state**.
51
+ * @typeParam R1 - The return type of the **onErr** callback.
52
+ * @typeParam R2 - The return type of the **onElse** callback.
53
+ * @param result - The Result object to check.
54
+ * @param onErr - The function executed when the Result is **Err**, receiving the internal error (E).
55
+ * @param onElse - The function executed when the Result is **Ok**, receiving the internal value (T).
56
+ * @returns The return value of onErr (R1) or onElse (R2).
57
+ */
58
+ export declare function ifErr<T, E, R1, R2>(result: Result<T, E>, onErr: (error: E) => R1, onElse: (value: T) => R2): R1 | R2;
59
+ /**
60
+ * Transforms the Result into a single type R. Uses mapFn to transform the value on Success;
61
+ * uses defaultFn to transform the error into a default value on Failure.
62
+ * @typeParam T - The type of the success value
63
+ * @typeParam E - The type of the error
64
+ * @typeParam R - The type of the final return value
65
+ * @param result - The Result to process
66
+ * @param defaultFn - The function to compute the default value on failure
67
+ * @param mapFn - The function to map the success value
68
+ * @returns The final return value R
69
+ */
70
+ export declare const mapOrElse: <T, E, R1, R2>(result: Result<T, E>, defaultFn: (error: E) => R1, mapFn: (value: T) => R2) => R1 | R2;
@@ -0,0 +1,66 @@
1
+ import { AnyResult, Result } from '../types';
2
+ import { UnknownError } from '../../unknown-error';
3
+ import { MaybePromise } from '../../Utils/type-tool';
4
+ /**
5
+ * Returns the Result as is, regardless of its state. Used for side effects (e.g., logging) on both Success/Failure paths.
6
+ * @typeParam T - The type of the success value
7
+ * @typeParam E - The type of the error
8
+ * @param result - The Result to peek
9
+ * @param options - Options object containing optional side-effect functions
10
+ * @returns The unchanged Result
11
+ */
12
+ export declare function peekBoth<T, E>(result: Result<T, E>, { fnOk, fnErr, }: {
13
+ fnOk?: (value: T) => void;
14
+ fnErr?: (error: E) => void;
15
+ }): Result<T, E>;
16
+ /**
17
+ * Executes the fnErr function as a side effect if the Result is Failure; then returns the Result as is.
18
+ * @typeParam T - The type of the success value
19
+ * @typeParam E - The type of the error
20
+ * @param result - The Result to peek
21
+ * @param fnErr - The side-effect function to execute on Failure
22
+ * @returns The unchanged Result
23
+ */
24
+ export declare function peekErr<T, E>(result: Result<T, E>, fnErr: (error: E) => void): Result<T, E>;
25
+ /**
26
+ * Executes the fnOk function as a side effect if the Result is Success; then returns the Result as is.
27
+ * @typeParam T - The type of the success value
28
+ * @typeParam E - The type of the error
29
+ * @param result - The Result to peek
30
+ * @param fnOk - The side-effect function to execute on Success
31
+ * @returns The unchanged Result
32
+ */
33
+ export declare function peekOk<T, E>(result: Result<T, E>, fnOk: (value: T) => void): Result<T, E>;
34
+ /**
35
+ * Asynchronously executes side effects for both Success/Failure paths, and returns the AsyncResult unchanged.
36
+ * @typeParam T - The type of the success value
37
+ * @typeParam E - The type of the error
38
+ * @param result_promise - The Result or Promise<Result> to peek
39
+ * @param options - Options object containing optional side-effect functions
40
+ * @param signal - Optional AbortSignal for cancellation
41
+ * @returns A Promise containing the original Result, or an UnknownError if a side effect throws
42
+ */
43
+ export declare function peekBothAsync<T, E>(result_promise: AnyResult<T, E>, { fnOk, fnErr, }: {
44
+ fnOk?: (value: T, signal?: AbortSignal) => MaybePromise<void>;
45
+ fnErr?: (error: E, signal?: AbortSignal) => MaybePromise<void>;
46
+ }, signal?: AbortSignal): Promise<Result<T, E | DOMException | UnknownError>>;
47
+ /**
48
+ * Asynchronously executes fnErr as a side effect if the Result is Failure; then returns the Result unchanged.
49
+ * @typeParam T - The type of the success value
50
+ * @typeParam E - The type of the error
51
+ * @param result_promise - The Result or Promise<Result> to peek
52
+ * @param fnErr - The side-effect function to execute on Failure
53
+ * @param signal - Optional AbortSignal for cancellation
54
+ * @returns A Promise containing the original Result, or an UnknownError if fnErr throws
55
+ */
56
+ export declare function peekErrAsync<T, E>(result_promise: AnyResult<T, E>, fnErr: (error: E, signal?: AbortSignal) => MaybePromise<void>, signal?: AbortSignal): Promise<Result<T, E | DOMException | UnknownError>>;
57
+ /**
58
+ * Asynchronously executes fnOk as a side effect if the Result is Success; then returns the Result unchanged.
59
+ * @typeParam T - The type of the success value
60
+ * @typeParam E - The type of the error
61
+ * @param result_promise - The Result or Promise<Result> to peek
62
+ * @param fnOk - The side-effect function to execute on Success
63
+ * @param signal - Optional AbortSignal for cancellation
64
+ * @returns A Promise containing the original Result, or an UnknownError if fnOk throws
65
+ */
66
+ export declare function peekOkAsync<T, E>(result_promise: AnyResult<T, E>, fnOk: (value: T, signal?: AbortSignal) => MaybePromise<void>, signal?: AbortSignal): Promise<Result<T, E | DOMException | UnknownError>>;
@@ -0,0 +1,69 @@
1
+ import { AnyResult, AsyncResult } from '../../types';
2
+ import { UnknownError } from '../../../unknown-error';
3
+ /**
4
+ * Asynchronous Applicative Apply.
5
+ * Applies the function inside result_fab to the value inside result_a, executing concurrently.
6
+ * Short-circuits on the first error encountered in either input.
7
+ *
8
+ * @typeParam T - The type of the input value A
9
+ * @typeParam E - The type of the error
10
+ * @typeParam U - The type of the output value B
11
+ * @typeParam F - The error type of the function Result
12
+ * @param result_fab - The AnyResult containing the mapping function (A) => B
13
+ * @param result_a - The AnyResult containing the value A
14
+ * @param signal - Optional AbortSignal for cancellation
15
+ * @returns An AsyncResult containing the output value B or the first error
16
+ */
17
+ export declare function apAsync<T, E, U, F>(result_fab: AnyResult<(value: T, signal?: AbortSignal) => U, F>, result_a: AnyResult<T, E>, signal?: AbortSignal): AsyncResult<U, E | F | UnknownError | DOMException>;
18
+ /**
19
+ * Asynchronously combines two Results into a tuple (executed concurrently).
20
+ * @typeParam T - The success value type of the first Result
21
+ * @typeParam E - The error type of the first Result
22
+ * @typeParam U - The success value type of the second Result
23
+ * @typeParam F - The error type of the second Result
24
+ * @param result_a - The first AnyResult
25
+ * @param result_b - The second AnyResult
26
+ * @param signal - Optional AbortSignal for cancellation
27
+ * @returns An AsyncResult containing the tuple or the first error
28
+ */
29
+ export declare function zipAsync<T, E, U, F>(result_a: AnyResult<T, E>, result_b: AnyResult<U, F>, signal?: AbortSignal): AsyncResult<[T, U], E | F | UnknownError | DOMException>;
30
+ /**
31
+ * Executes multiple AsyncResults concurrently. Returns an array if all succeed, or short-circuits by returning the first error.
32
+ * @typeParam T - The type of the success value
33
+ * @typeParam E - The type of the error
34
+ * @param results - The array of AnyResults
35
+ * @param signal - Optional AbortSignal for cancellation
36
+ * @returns An AsyncResult containing the array of values or the first error
37
+ */
38
+ export declare function allAsync<T, E>(results: readonly AnyResult<T, E>[], signal?: AbortSignal): AsyncResult<T[], E | UnknownError | DOMException>;
39
+ /**
40
+ * Executes multiple AsyncResults sequentially. Returns an array if all succeed, or short-circuits by returning the first error.
41
+ * @typeParam T - The type of the success value
42
+ * @typeParam E - The type of the error
43
+ * @param results - The array of AnyResults
44
+ * @param signal - Optional AbortSignal for cancellation
45
+ * @returns An AsyncResult containing the array of values or the first error
46
+ */
47
+ export declare function sequenceAsync<T, E>(results: readonly AnyResult<T, E>[], signal?: AbortSignal): AsyncResult<T[], E | UnknownError | DOMException>;
48
+ /**
49
+ * Asynchronous logical AND operation. If result is Ok, awaits and returns other; if result is Err, returns result's error.
50
+ * @typeParam T - The success value type of the first Result
51
+ * @typeParam E - The type of the error
52
+ * @typeParam U - The success value type of the second Result
53
+ * @param result_promise - The first AnyResult
54
+ * @param other_promise - The second AnyResult
55
+ * @param signal - Optional AbortSignal for cancellation
56
+ * @returns The result of the logical AND
57
+ */
58
+ export declare function andAsync<T, E, U>(result_promise: AnyResult<T, E>, other_promise: AnyResult<U, E>, signal?: AbortSignal): AsyncResult<U, E | UnknownError | DOMException>;
59
+ /**
60
+ * Asynchronous logical OR operation. If result is Ok, returns result; if result is Err, awaits and returns other.
61
+ * @typeParam T - The type of the success value
62
+ * @typeParam E - The type of the original error
63
+ * @typeParam F - The type of the alternative error
64
+ * @param result_promise - The first AnyResult
65
+ * @param other_promise - The second AnyResult
66
+ * @param signal - Optional AbortSignal for cancellation
67
+ * @returns The result of the logical OR
68
+ */
69
+ export declare function orAsync<T, E, F>(result_promise: AnyResult<T, E>, other_promise: AnyResult<T, F>, signal?: AbortSignal): AsyncResult<T, F | UnknownError | DOMException>;
@@ -0,0 +1,29 @@
1
+ import { AnyResult } from '../../types';
2
+ import { UnknownError } from '../../../unknown-error';
3
+ /**
4
+ * Asynchronously collects all success values from an array of AsyncResults.
5
+ * @typeParam T - The type of the success value
6
+ * @typeParam E - The type of the error
7
+ * @param results - The array of AsyncResults
8
+ * @param signal - Optional AbortSignal for cancellation
9
+ * @returns A Promise of the array of collected success values
10
+ */
11
+ export declare function collectOkAsync<T, E>(results: readonly AnyResult<T, E>[], signal?: AbortSignal): Promise<T[]>;
12
+ /**
13
+ * Asynchronously collects all failure errors from an array of AsyncResults.
14
+ * @typeParam T - The type of the success value
15
+ * @typeParam E - The type of the error
16
+ * @param results - The array of AsyncResults
17
+ * @param signal - Optional AbortSignal for cancellation
18
+ * @returns A Promise of the array of collected error values
19
+ */
20
+ export declare function collectErrAsync<T, E>(results: readonly AnyResult<T, E>[], signal?: AbortSignal): Promise<E[]>;
21
+ /**
22
+ * Asynchronously executes the Result array concurrently and partitions it into a tuple of success values and error values (non-short-circuiting).
23
+ * @typeParam T - The type of the success value
24
+ * @typeParam E - The type of the error
25
+ * @param results - The array of AsyncResults
26
+ * @param signal - Optional AbortSignal for cancellation
27
+ * @returns A Promise of a tuple containing the success value array and the error value array
28
+ */
29
+ export declare function partitionAsync<T, E>(results: readonly AnyResult<T, E>[], signal?: AbortSignal): Promise<[T[], Array<E | DOMException | UnknownError>]>;
@@ -0,0 +1,15 @@
1
+ import { AnyResult, AsyncResult } from '../../types';
2
+ import { UnknownError } from '../../../unknown-error';
3
+ import { MaybePromise } from '../../../Utils/type-tool';
4
+ /**
5
+ * Asynchronously and sequentially reduces multiple AsyncResults into a single Result (short-circuit).
6
+ * @typeParam T - The type of the success value
7
+ * @typeParam E - The type of the error
8
+ * @typeParam R - The type of the reduced result
9
+ * @param resultPromises - The array of AsyncResults to reduce
10
+ * @param initial - The initial value
11
+ * @param reducer - The reduction function (can be async)
12
+ * @param signal - Optional AbortSignal for cancellation
13
+ * @returns An AsyncResult containing the reduced result
14
+ */
15
+ export declare function reduceAsync<T, E, R>(resultPromises: readonly AnyResult<T, E>[], initial: R, reducer: (accumulator: R, value: T, signal?: AbortSignal) => MaybePromise<R>, signal?: AbortSignal): AsyncResult<R, E | UnknownError | DOMException>;