effect 2.0.0-next.44 → 2.0.0-next.46

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 (779) hide show
  1. package/Bigint/dist/effect-Bigint.cjs.dev.js +125 -1
  2. package/Bigint/dist/effect-Bigint.cjs.mjs +6 -1
  3. package/Bigint/dist/effect-Bigint.cjs.prod.js +125 -1
  4. package/Bigint/dist/effect-Bigint.esm.js +111 -2
  5. package/Boolean/dist/effect-Boolean.cjs.dev.js +1 -1
  6. package/Boolean/dist/effect-Boolean.cjs.prod.js +1 -1
  7. package/Boolean/dist/effect-Boolean.esm.js +1 -1
  8. package/Brand/dist/effect-Brand.cjs.dev.js +3 -3
  9. package/Brand/dist/effect-Brand.cjs.prod.js +3 -3
  10. package/Cache/dist/effect-Cache.cjs.dev.js +32 -32
  11. package/Cache/dist/effect-Cache.cjs.prod.js +32 -32
  12. package/Cause/dist/effect-Cause.cjs.dev.js +17 -17
  13. package/Cause/dist/effect-Cause.cjs.mjs +1 -1
  14. package/Cause/dist/effect-Cause.cjs.prod.js +17 -17
  15. package/Cause/dist/effect-Cause.esm.js +4 -4
  16. package/Channel/dist/effect-Channel.cjs.dev.js +50 -50
  17. package/Channel/dist/effect-Channel.cjs.mjs +3 -3
  18. package/Channel/dist/effect-Channel.cjs.prod.js +50 -50
  19. package/Channel/dist/effect-Channel.esm.js +8 -8
  20. package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.dev.js +36 -36
  21. package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.prod.js +36 -36
  22. package/Chunk/dist/effect-Chunk.cjs.dev.js +3 -3
  23. package/Chunk/dist/effect-Chunk.cjs.prod.js +3 -3
  24. package/Clock/dist/effect-Clock.cjs.dev.js +16 -16
  25. package/Clock/dist/effect-Clock.cjs.prod.js +16 -16
  26. package/Config/dist/effect-Config.cjs.dev.js +11 -11
  27. package/Config/dist/effect-Config.cjs.prod.js +11 -11
  28. package/ConfigError/dist/effect-ConfigError.cjs.dev.js +4 -4
  29. package/ConfigError/dist/effect-ConfigError.cjs.prod.js +4 -4
  30. package/ConfigProvider/dist/effect-ConfigProvider.cjs.dev.js +17 -17
  31. package/ConfigProvider/dist/effect-ConfigProvider.cjs.prod.js +17 -17
  32. package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.dev.js +5 -5
  33. package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.prod.js +5 -5
  34. package/ConfigSecret/dist/effect-ConfigSecret.cjs.dev.js +4 -4
  35. package/ConfigSecret/dist/effect-ConfigSecret.cjs.prod.js +4 -4
  36. package/Console/dist/effect-Console.cjs.dev.js +35 -35
  37. package/Console/dist/effect-Console.cjs.prod.js +35 -35
  38. package/Context/dist/effect-Context.cjs.dev.js +3 -8
  39. package/Context/dist/effect-Context.cjs.prod.js +3 -8
  40. package/Data/dist/effect-Data.cjs.dev.js +141 -54
  41. package/Data/dist/effect-Data.cjs.mjs +2 -0
  42. package/Data/dist/effect-Data.cjs.prod.js +141 -54
  43. package/Data/dist/effect-Data.esm.js +51 -3
  44. package/DefaultServices/dist/effect-DefaultServices.cjs.dev.js +16 -16
  45. package/DefaultServices/dist/effect-DefaultServices.cjs.prod.js +16 -16
  46. package/Deferred/dist/effect-Deferred.cjs.dev.js +8 -8
  47. package/Deferred/dist/effect-Deferred.cjs.prod.js +8 -8
  48. package/Differ/dist/effect-Differ.cjs.dev.js +11 -11
  49. package/Differ/dist/effect-Differ.cjs.prod.js +11 -11
  50. package/Duration/dist/effect-Duration.cjs.dev.js +3 -3
  51. package/Duration/dist/effect-Duration.cjs.prod.js +3 -3
  52. package/Effect/dist/effect-Effect.cjs.dev.js +44 -44
  53. package/Effect/dist/effect-Effect.cjs.prod.js +44 -44
  54. package/Effectable/dist/effect-Effectable.cjs.dev.js +24 -14
  55. package/Effectable/dist/effect-Effectable.cjs.mjs +5 -4
  56. package/Effectable/dist/effect-Effectable.cjs.prod.js +24 -14
  57. package/Effectable/dist/effect-Effectable.esm.js +15 -5
  58. package/Either/dist/effect-Either.cjs.dev.js +3 -3
  59. package/Either/dist/effect-Either.cjs.prod.js +3 -3
  60. package/Encoding/dist/effect-Encoding.cjs.dev.js +3 -3
  61. package/Encoding/dist/effect-Encoding.cjs.prod.js +3 -3
  62. package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.dev.js +2 -2
  63. package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.prod.js +2 -2
  64. package/Exit/dist/effect-Exit.cjs.dev.js +8 -8
  65. package/Exit/dist/effect-Exit.cjs.prod.js +8 -8
  66. package/Fiber/dist/effect-Fiber.cjs.dev.js +29 -29
  67. package/Fiber/dist/effect-Fiber.cjs.prod.js +29 -29
  68. package/FiberId/dist/effect-FiberId.cjs.dev.js +5 -5
  69. package/FiberId/dist/effect-FiberId.cjs.prod.js +5 -5
  70. package/FiberRef/dist/effect-FiberRef.cjs.dev.js +29 -29
  71. package/FiberRef/dist/effect-FiberRef.cjs.prod.js +29 -29
  72. package/FiberRefs/dist/effect-FiberRefs.cjs.dev.js +9 -9
  73. package/FiberRefs/dist/effect-FiberRefs.cjs.prod.js +9 -9
  74. package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.dev.js +10 -10
  75. package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.prod.js +10 -10
  76. package/GroupBy/dist/effect-GroupBy.cjs.dev.js +42 -42
  77. package/GroupBy/dist/effect-GroupBy.cjs.prod.js +42 -42
  78. package/HashMap/dist/effect-HashMap.cjs.dev.js +20 -20
  79. package/HashMap/dist/effect-HashMap.cjs.prod.js +20 -20
  80. package/HashSet/dist/effect-HashSet.cjs.dev.js +20 -20
  81. package/HashSet/dist/effect-HashSet.cjs.prod.js +20 -20
  82. package/KeyedPool/dist/effect-KeyedPool.cjs.dev.js +33 -33
  83. package/KeyedPool/dist/effect-KeyedPool.cjs.prod.js +33 -33
  84. package/Layer/dist/effect-Layer.cjs.dev.js +32 -32
  85. package/Layer/dist/effect-Layer.cjs.prod.js +32 -32
  86. package/List/dist/effect-List.cjs.dev.js +3 -3
  87. package/List/dist/effect-List.cjs.prod.js +3 -3
  88. package/LogLevel/dist/effect-LogLevel.cjs.dev.js +8 -8
  89. package/LogLevel/dist/effect-LogLevel.cjs.prod.js +8 -8
  90. package/Logger/dist/effect-Logger.cjs.dev.js +33 -33
  91. package/Logger/dist/effect-Logger.cjs.prod.js +33 -33
  92. package/Metric/dist/effect-Metric.cjs.dev.js +27 -27
  93. package/Metric/dist/effect-Metric.cjs.prod.js +27 -27
  94. package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.dev.js +4 -4
  95. package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.prod.js +4 -4
  96. package/MetricHook/dist/effect-MetricHook.cjs.dev.js +6 -6
  97. package/MetricHook/dist/effect-MetricHook.cjs.prod.js +6 -6
  98. package/MetricKey/dist/effect-MetricKey.cjs.dev.js +6 -6
  99. package/MetricKey/dist/effect-MetricKey.cjs.prod.js +6 -6
  100. package/MetricKeyType/dist/effect-MetricKeyType.cjs.dev.js +4 -4
  101. package/MetricKeyType/dist/effect-MetricKeyType.cjs.prod.js +4 -4
  102. package/MetricPolling/dist/effect-MetricPolling.cjs.dev.js +30 -30
  103. package/MetricPolling/dist/effect-MetricPolling.cjs.prod.js +30 -30
  104. package/MetricRegistry/dist/effect-MetricRegistry.cjs.dev.js +8 -8
  105. package/MetricRegistry/dist/effect-MetricRegistry.cjs.prod.js +8 -8
  106. package/MetricState/dist/effect-MetricState.cjs.dev.js +1 -1
  107. package/MetricState/dist/effect-MetricState.cjs.prod.js +1 -1
  108. package/MutableHashMap/dist/effect-MutableHashMap.cjs.dev.js +4 -4
  109. package/MutableHashMap/dist/effect-MutableHashMap.cjs.prod.js +4 -4
  110. package/MutableHashSet/dist/effect-MutableHashSet.cjs.dev.js +4 -4
  111. package/MutableHashSet/dist/effect-MutableHashSet.cjs.prod.js +4 -4
  112. package/MutableQueue/dist/effect-MutableQueue.cjs.dev.js +3 -3
  113. package/MutableQueue/dist/effect-MutableQueue.cjs.prod.js +3 -3
  114. package/Number/dist/effect-Number.cjs.dev.js +1 -1
  115. package/Number/dist/effect-Number.cjs.prod.js +1 -1
  116. package/Number/dist/effect-Number.esm.js +1 -1
  117. package/Option/dist/effect-Option.cjs.dev.js +9 -9
  118. package/Option/dist/effect-Option.cjs.prod.js +9 -9
  119. package/Pool/dist/effect-Pool.cjs.dev.js +31 -31
  120. package/Pool/dist/effect-Pool.cjs.prod.js +31 -31
  121. package/PubSub/dist/effect-PubSub.cjs.d.mts +2 -0
  122. package/PubSub/dist/effect-PubSub.cjs.d.mts.map +1 -0
  123. package/PubSub/dist/effect-PubSub.cjs.d.ts +2 -0
  124. package/PubSub/dist/effect-PubSub.cjs.d.ts.map +1 -0
  125. package/{Hub/dist/effect-Hub.cjs.dev.js → PubSub/dist/effect-PubSub.cjs.dev.js} +163 -163
  126. package/PubSub/dist/effect-PubSub.cjs.js +7 -0
  127. package/{Hub/dist/effect-Hub.cjs.mjs → PubSub/dist/effect-PubSub.cjs.mjs} +1 -1
  128. package/{Hub/dist/effect-Hub.cjs.prod.js → PubSub/dist/effect-PubSub.cjs.prod.js} +163 -163
  129. package/{Hub/dist/effect-Hub.esm.js → PubSub/dist/effect-PubSub.esm.js} +15 -15
  130. package/PubSub/package.json +4 -0
  131. package/Queue/dist/effect-Queue.cjs.dev.js +28 -28
  132. package/Queue/dist/effect-Queue.cjs.prod.js +28 -28
  133. package/README.md +5 -5
  134. package/Random/dist/effect-Random.cjs.dev.js +16 -16
  135. package/Random/dist/effect-Random.cjs.prod.js +16 -16
  136. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.dev.js +3 -3
  137. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.prod.js +3 -3
  138. package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.dev.js +3 -3
  139. package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.prod.js +3 -3
  140. package/RedBlackTree/dist/effect-RedBlackTree.cjs.dev.js +4 -4
  141. package/RedBlackTree/dist/effect-RedBlackTree.cjs.prod.js +4 -4
  142. package/Ref/dist/effect-Ref.cjs.dev.js +9 -9
  143. package/Ref/dist/effect-Ref.cjs.prod.js +9 -9
  144. package/Reloadable/dist/effect-Reloadable.cjs.dev.js +44 -44
  145. package/Reloadable/dist/effect-Reloadable.cjs.prod.js +44 -44
  146. package/Request/dist/effect-Request.cjs.dev.js +29 -29
  147. package/Request/dist/effect-Request.cjs.prod.js +29 -29
  148. package/RequestBlock/dist/effect-RequestBlock.cjs.dev.js +36 -36
  149. package/RequestBlock/dist/effect-RequestBlock.cjs.prod.js +36 -36
  150. package/RequestResolver/dist/effect-RequestResolver.cjs.dev.js +38 -38
  151. package/RequestResolver/dist/effect-RequestResolver.cjs.prod.js +38 -38
  152. package/Resource/dist/effect-Resource.cjs.dev.js +34 -34
  153. package/Resource/dist/effect-Resource.cjs.prod.js +34 -34
  154. package/Runtime/dist/effect-Runtime.cjs.dev.js +34 -34
  155. package/Runtime/dist/effect-Runtime.cjs.prod.js +34 -34
  156. package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.dev.js +33 -33
  157. package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.prod.js +33 -33
  158. package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.dev.js +6 -6
  159. package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.prod.js +6 -6
  160. package/STM/dist/effect-STM.cjs.dev.js +48 -48
  161. package/STM/dist/effect-STM.cjs.prod.js +48 -48
  162. package/Schedule/dist/effect-Schedule.cjs.dev.js +19 -19
  163. package/Schedule/dist/effect-Schedule.cjs.prod.js +19 -19
  164. package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.dev.js +3 -3
  165. package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.prod.js +3 -3
  166. package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.dev.js +3 -3
  167. package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.prod.js +3 -3
  168. package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.dev.js +3 -3
  169. package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.prod.js +3 -3
  170. package/Scheduler/dist/effect-Scheduler.cjs.dev.js +8 -8
  171. package/Scheduler/dist/effect-Scheduler.cjs.prod.js +8 -8
  172. package/Scope/dist/effect-Scope.cjs.dev.js +27 -27
  173. package/Scope/dist/effect-Scope.cjs.prod.js +27 -27
  174. package/ScopedCache/dist/effect-ScopedCache.cjs.dev.js +78 -61
  175. package/ScopedCache/dist/effect-ScopedCache.cjs.prod.js +78 -61
  176. package/ScopedRef/dist/effect-ScopedRef.cjs.dev.js +34 -34
  177. package/ScopedRef/dist/effect-ScopedRef.cjs.prod.js +34 -34
  178. package/Sink/dist/effect-Sink.cjs.dev.js +43 -43
  179. package/Sink/dist/effect-Sink.cjs.mjs +1 -1
  180. package/Sink/dist/effect-Sink.cjs.prod.js +43 -43
  181. package/Sink/dist/effect-Sink.esm.js +5 -5
  182. package/SortedMap/dist/effect-SortedMap.cjs.dev.js +3 -3
  183. package/SortedMap/dist/effect-SortedMap.cjs.prod.js +3 -3
  184. package/SortedSet/dist/effect-SortedSet.cjs.dev.js +3 -3
  185. package/SortedSet/dist/effect-SortedSet.cjs.prod.js +3 -3
  186. package/Stream/dist/effect-Stream.cjs.dev.js +60 -60
  187. package/Stream/dist/effect-Stream.cjs.mjs +5 -5
  188. package/Stream/dist/effect-Stream.cjs.prod.js +60 -60
  189. package/Stream/dist/effect-Stream.esm.js +15 -15
  190. package/Streamable/dist/effect-Streamable.cjs.d.mts +2 -0
  191. package/Streamable/dist/effect-Streamable.cjs.d.mts.map +1 -0
  192. package/Streamable/dist/effect-Streamable.cjs.d.ts +2 -0
  193. package/Streamable/dist/effect-Streamable.cjs.d.ts.map +1 -0
  194. package/Streamable/dist/effect-Streamable.cjs.dev.js +152 -0
  195. package/Streamable/dist/effect-Streamable.cjs.js +7 -0
  196. package/Streamable/dist/effect-Streamable.cjs.mjs +3 -0
  197. package/Streamable/dist/effect-Streamable.cjs.prod.js +152 -0
  198. package/Streamable/dist/effect-Streamable.esm.js +42 -0
  199. package/Streamable/package.json +4 -0
  200. package/String/dist/effect-String.cjs.dev.js +4 -4
  201. package/String/dist/effect-String.cjs.prod.js +4 -4
  202. package/String/dist/effect-String.esm.js +1 -1
  203. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.dev.js +48 -48
  204. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.prod.js +48 -48
  205. package/Supervisor/dist/effect-Supervisor.cjs.dev.js +34 -34
  206. package/Supervisor/dist/effect-Supervisor.cjs.prod.js +34 -34
  207. package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.dev.js +30 -30
  208. package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.prod.js +30 -30
  209. package/TArray/dist/effect-TArray.cjs.dev.js +46 -46
  210. package/TArray/dist/effect-TArray.cjs.prod.js +46 -46
  211. package/TDeferred/dist/effect-TDeferred.cjs.dev.js +45 -45
  212. package/TDeferred/dist/effect-TDeferred.cjs.prod.js +45 -45
  213. package/TMap/dist/effect-TMap.cjs.dev.js +47 -47
  214. package/TMap/dist/effect-TMap.cjs.prod.js +47 -47
  215. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.dev.js +44 -44
  216. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.prod.js +44 -44
  217. package/TPubSub/dist/effect-TPubSub.cjs.d.mts +2 -0
  218. package/TPubSub/dist/effect-TPubSub.cjs.d.mts.map +1 -0
  219. package/TPubSub/dist/effect-TPubSub.cjs.d.ts +2 -0
  220. package/TPubSub/dist/effect-TPubSub.cjs.d.ts.map +1 -0
  221. package/{THub/dist/effect-THub.cjs.dev.js → TPubSub/dist/effect-TPubSub.cjs.dev.js} +101 -101
  222. package/TPubSub/dist/effect-TPubSub.cjs.js +7 -0
  223. package/{THub/dist/effect-THub.cjs.mjs → TPubSub/dist/effect-TPubSub.cjs.mjs} +2 -2
  224. package/{THub/dist/effect-THub.cjs.prod.js → TPubSub/dist/effect-TPubSub.cjs.prod.js} +101 -101
  225. package/TPubSub/dist/effect-TPubSub.esm.js +157 -0
  226. package/TPubSub/package.json +4 -0
  227. package/TQueue/dist/effect-TQueue.cjs.dev.js +46 -46
  228. package/TQueue/dist/effect-TQueue.cjs.prod.js +46 -46
  229. package/TRandom/dist/effect-TRandom.cjs.dev.js +50 -50
  230. package/TRandom/dist/effect-TRandom.cjs.prod.js +50 -50
  231. package/TReentrantLock/dist/effect-TReentrantLock.cjs.dev.js +46 -46
  232. package/TReentrantLock/dist/effect-TReentrantLock.cjs.prod.js +46 -46
  233. package/TRef/dist/effect-TRef.cjs.dev.js +44 -44
  234. package/TRef/dist/effect-TRef.cjs.prod.js +44 -44
  235. package/TSemaphore/dist/effect-TSemaphore.cjs.dev.js +45 -45
  236. package/TSemaphore/dist/effect-TSemaphore.cjs.prod.js +45 -45
  237. package/TSet/dist/effect-TSet.cjs.dev.js +47 -47
  238. package/TSet/dist/effect-TSet.cjs.prod.js +47 -47
  239. package/Take/dist/effect-Take.cjs.dev.js +36 -36
  240. package/Take/dist/effect-Take.cjs.prod.js +36 -36
  241. package/TestAnnotation/dist/effect-TestAnnotation.cjs.dev.js +8 -8
  242. package/TestAnnotation/dist/effect-TestAnnotation.cjs.prod.js +8 -8
  243. package/TestAnnotations/dist/effect-TestAnnotations.cjs.dev.js +25 -25
  244. package/TestAnnotations/dist/effect-TestAnnotations.cjs.prod.js +25 -25
  245. package/TestClock/dist/effect-TestClock.cjs.dev.js +46 -46
  246. package/TestClock/dist/effect-TestClock.cjs.prod.js +46 -46
  247. package/TestConfig/dist/effect-TestConfig.cjs.dev.js +3 -8
  248. package/TestConfig/dist/effect-TestConfig.cjs.prod.js +3 -8
  249. package/TestContext/dist/effect-TestContext.cjs.dev.js +37 -37
  250. package/TestContext/dist/effect-TestContext.cjs.prod.js +37 -37
  251. package/TestLive/dist/effect-TestLive.cjs.dev.js +17 -17
  252. package/TestLive/dist/effect-TestLive.cjs.prod.js +17 -17
  253. package/TestServices/dist/effect-TestServices.cjs.dev.js +42 -42
  254. package/TestServices/dist/effect-TestServices.cjs.prod.js +42 -42
  255. package/TestSized/dist/effect-TestSized.cjs.dev.js +11 -11
  256. package/TestSized/dist/effect-TestSized.cjs.prod.js +11 -11
  257. package/Tracer/dist/effect-Tracer.cjs.dev.js +16 -16
  258. package/Tracer/dist/effect-Tracer.cjs.prod.js +16 -16
  259. package/dist/{Context-01a123ac.cjs.prod.js → Context-9fe5eb16.cjs.prod.js} +5 -5
  260. package/dist/{Context-593661f6.cjs.dev.js → Context-da73ddfa.cjs.dev.js} +5 -5
  261. package/dist/{Effectable-2f022879.cjs.dev.js → Effectable-7314aed8.cjs.dev.js} +63 -10
  262. package/dist/{Effectable-cd8f3a96.cjs.prod.js → Effectable-c4c14a2b.cjs.prod.js} +63 -10
  263. package/dist/{Either-7a881c7a.cjs.prod.js → Either-d43f082c.cjs.prod.js} +6 -79
  264. package/dist/{Either-12bbe00c.cjs.dev.js → Either-fa0ef1d9.cjs.dev.js} +6 -79
  265. package/dist/{ExecutionStrategy-14d3053a.cjs.prod.js → ExecutionStrategy-4808fe5d.cjs.prod.js} +2 -2
  266. package/dist/{ExecutionStrategy-70f1a920.cjs.dev.js → ExecutionStrategy-7d9d457b.cjs.dev.js} +2 -2
  267. package/dist/{HashSet-0b4ff1e4.cjs.dev.js → HashSet-5963ad6b.cjs.dev.js} +32 -32
  268. package/dist/{HashSet-6257b66d.cjs.prod.js → HashSet-ac02a3e1.cjs.prod.js} +32 -32
  269. package/dist/Option-463b42e6.cjs.dev.js +81 -0
  270. package/dist/Option-935e5d7c.cjs.prod.js +81 -0
  271. package/dist/{Ref-a3a4e50d.cjs.prod.js → Ref-4014b526.cjs.prod.js} +1 -1
  272. package/dist/{Ref-74b592a4.cjs.dev.js → Ref-acdee7ef.cjs.dev.js} +1 -1
  273. package/dist/{cache-75fbef45.cjs.prod.js → cache-5c7d77e4.cjs.prod.js} +17 -17
  274. package/dist/{cache-e1ea3923.cjs.dev.js → cache-7eed9d33.cjs.dev.js} +17 -17
  275. package/dist/{circular-6f16b226.cjs.prod.js → circular-1f481ffb.cjs.prod.js} +33 -33
  276. package/dist/{circular-f406f9a4.cjs.prod.js → circular-9e10a5a7.cjs.prod.js} +6 -6
  277. package/dist/{circular-58ff5e9c.cjs.dev.js → circular-c2dbce1a.cjs.dev.js} +33 -33
  278. package/dist/{circular-30564534.cjs.dev.js → circular-c8b65bdb.cjs.dev.js} +6 -6
  279. package/dist/{config-80900693.cjs.dev.js → config-3b7935a3.cjs.dev.js} +3 -3
  280. package/dist/{config-d0ddc159.cjs.prod.js → config-5ba54da1.cjs.prod.js} +3 -3
  281. package/dist/{configProvider-93617d6d.cjs.prod.js → configProvider-b6b20998.cjs.prod.js} +29 -29
  282. package/dist/{configProvider-ce43fdbf.cjs.dev.js → configProvider-f34a82f1.cjs.dev.js} +29 -29
  283. package/dist/{core-0b0539de.cjs.prod.js → core-07202cc0.cjs.prod.js} +711 -726
  284. package/dist/{core-60ca562a.cjs.prod.js → core-7411d1e1.cjs.prod.js} +3 -3
  285. package/dist/{core-b4d7b4f5.cjs.dev.js → core-b7401357.cjs.dev.js} +711 -726
  286. package/dist/{core-13f8a866.cjs.dev.js → core-c5747f88.cjs.dev.js} +3 -3
  287. package/dist/{core-effect-892f3686.cjs.dev.js → core-effect-1c564d42.cjs.dev.js} +77 -75
  288. package/dist/{core-effect-c65770cd.cjs.prod.js → core-effect-9201ea63.cjs.prod.js} +77 -75
  289. package/dist/{dataSource-3ba9e4d3.cjs.dev.js → dataSource-b5eda714.cjs.dev.js} +2 -2
  290. package/dist/{dataSource-7df3a5f6.cjs.prod.js → dataSource-b83bc277.cjs.prod.js} +2 -2
  291. package/dist/declarations/src/Bigint.d.ts +92 -1
  292. package/dist/declarations/src/Bigint.d.ts.map +1 -1
  293. package/dist/declarations/src/Boolean.d.ts +1 -1
  294. package/dist/declarations/src/Cause.d.ts +6 -6
  295. package/dist/declarations/src/Cause.d.ts.map +1 -1
  296. package/dist/declarations/src/Channel.d.ts +7 -7
  297. package/dist/declarations/src/Channel.d.ts.map +1 -1
  298. package/dist/declarations/src/Data.d.ts +30 -0
  299. package/dist/declarations/src/Data.d.ts.map +1 -1
  300. package/dist/declarations/src/Effect.d.ts +4 -2
  301. package/dist/declarations/src/Effect.d.ts.map +1 -1
  302. package/dist/declarations/src/Effectable.d.ts +14 -4
  303. package/dist/declarations/src/Effectable.d.ts.map +1 -1
  304. package/dist/declarations/src/Metric.d.ts +31 -7
  305. package/dist/declarations/src/Metric.d.ts.map +1 -1
  306. package/dist/declarations/src/MetricHook.d.ts +7 -4
  307. package/dist/declarations/src/MetricHook.d.ts.map +1 -1
  308. package/dist/declarations/src/MetricKey.d.ts +24 -4
  309. package/dist/declarations/src/MetricKey.d.ts.map +1 -1
  310. package/dist/declarations/src/MetricKeyType.d.ts +9 -6
  311. package/dist/declarations/src/MetricKeyType.d.ts.map +1 -1
  312. package/dist/declarations/src/MetricRegistry.d.ts +2 -2
  313. package/dist/declarations/src/MetricRegistry.d.ts.map +1 -1
  314. package/dist/declarations/src/MetricState.d.ts +15 -9
  315. package/dist/declarations/src/MetricState.d.ts.map +1 -1
  316. package/dist/declarations/src/Number.d.ts +1 -1
  317. package/dist/declarations/src/{Hub.d.ts → PubSub.d.ts} +38 -38
  318. package/dist/declarations/src/PubSub.d.ts.map +1 -0
  319. package/dist/declarations/src/Sink.d.ts +4 -4
  320. package/dist/declarations/src/Sink.d.ts.map +1 -1
  321. package/dist/declarations/src/Stream.d.ts +24 -24
  322. package/dist/declarations/src/Stream.d.ts.map +1 -1
  323. package/dist/declarations/src/Streamable.d.ts +27 -0
  324. package/dist/declarations/src/Streamable.d.ts.map +1 -0
  325. package/dist/declarations/src/String.d.ts +1 -1
  326. package/dist/declarations/src/SubscriptionRef.d.ts.map +1 -1
  327. package/dist/declarations/src/TPubSub.d.ts +146 -0
  328. package/dist/declarations/src/TPubSub.d.ts.map +1 -0
  329. package/dist/declarations/src/index.d.ts +15 -15
  330. package/dist/declarations/src/index.d.ts.map +1 -1
  331. package/dist/{defaultServices-5530ff0e.cjs.dev.js → defaultServices-755d5b46.cjs.dev.js} +6 -6
  332. package/dist/{defaultServices-086b8ac9.cjs.prod.js → defaultServices-9d7ce86f.cjs.prod.js} +6 -6
  333. package/dist/effect.cjs.dev.js +9 -9
  334. package/dist/effect.cjs.mjs +3 -3
  335. package/dist/effect.cjs.prod.js +9 -9
  336. package/dist/effect.esm.js +6 -6
  337. package/dist/{fiber-1bfb4c1d.cjs.dev.js → fiber-5156eff2.cjs.dev.js} +12 -12
  338. package/dist/{fiber-2eb0a4c1.cjs.prod.js → fiber-9519d109.cjs.prod.js} +12 -12
  339. package/dist/{fiberRefs-be6b6a70.cjs.prod.js → fiberRefs-558c17e6.cjs.prod.js} +1 -1
  340. package/dist/{fiberRefs-be4fae6a.cjs.dev.js → fiberRefs-98b71233.cjs.dev.js} +1 -1
  341. package/dist/{fiberRuntime-2d31e120.cjs.prod.js → fiberRuntime-31ae011f.cjs.prod.js} +99 -100
  342. package/dist/{fiberRuntime-c7280769.cjs.dev.js → fiberRuntime-d3872282.cjs.dev.js} +99 -100
  343. package/dist/{groupBy-0702739b.cjs.prod.js → groupBy-724f64ef.cjs.prod.js} +4 -4
  344. package/dist/{groupBy-7f852bf3.cjs.dev.js → groupBy-862cc2da.cjs.dev.js} +4 -4
  345. package/dist/{hook-e72b20fd.cjs.dev.js → hook-8cefc909.cjs.dev.js} +8 -4
  346. package/dist/{hook-470b717e.cjs.prod.js → hook-98ce30e4.cjs.prod.js} +8 -4
  347. package/dist/{key-f0a1408a.cjs.dev.js → key-198b6670.cjs.dev.js} +3 -3
  348. package/dist/{key-378a6a2c.cjs.prod.js → key-eb8a12b2.cjs.prod.js} +3 -3
  349. package/dist/{keyType-cf67c69c.cjs.prod.js → keyType-0c5e6178.cjs.prod.js} +9 -2
  350. package/dist/{keyType-55f27f07.cjs.dev.js → keyType-7c164b82.cjs.dev.js} +9 -2
  351. package/dist/{layer-b42e8022.cjs.dev.js → layer-29574350.cjs.dev.js} +33 -33
  352. package/dist/{layer-d103b49b.cjs.prod.js → layer-51ff4846.cjs.prod.js} +33 -33
  353. package/dist/{patch-a1b2802f.cjs.dev.js → patch-0220a642.cjs.dev.js} +1 -1
  354. package/dist/{patch-c4d6c61e.cjs.prod.js → patch-7c559bb2.cjs.prod.js} +1 -1
  355. package/dist/{pathPatch-15c8d723.cjs.prod.js → pathPatch-b56a4da2.cjs.prod.js} +1 -1
  356. package/dist/{pathPatch-d9d41297.cjs.dev.js → pathPatch-fab016f1.cjs.dev.js} +1 -1
  357. package/dist/{pool-ef44ba82.cjs.dev.js → pool-3211287f.cjs.dev.js} +31 -31
  358. package/dist/{pool-e414eb88.cjs.prod.js → pool-f77d7705.cjs.prod.js} +31 -31
  359. package/dist/{query-1d0157db.cjs.prod.js → query-a52b25f0.cjs.prod.js} +11 -11
  360. package/dist/{query-54337864.cjs.dev.js → query-c36decd5.cjs.dev.js} +11 -11
  361. package/dist/{queue-27ac9d98.cjs.prod.js → queue-315ea45d.cjs.prod.js} +22 -22
  362. package/dist/{queue-533d70d4.cjs.dev.js → queue-7a223c44.cjs.dev.js} +22 -22
  363. package/dist/{registry-1099de3f.cjs.dev.js → registry-62ff192e.cjs.dev.js} +4 -4
  364. package/dist/{registry-013ecdde.cjs.prod.js → registry-d5258dff.cjs.prod.js} +4 -4
  365. package/dist/{runtime-ea174155.cjs.prod.js → runtime-005f8a9b.cjs.prod.js} +7 -7
  366. package/dist/{runtime-afad6a9b.cjs.dev.js → runtime-57c8ddf8.cjs.dev.js} +7 -7
  367. package/dist/{schedule-1d92198c.cjs.prod.js → schedule-8cdf6bf1.cjs.prod.js} +40 -40
  368. package/dist/{schedule-e0f55cab.cjs.dev.js → schedule-e7a9f93f.cjs.dev.js} +40 -40
  369. package/dist/scopedRef-789d7fef.cjs.prod.js +55 -0
  370. package/dist/scopedRef-eb19c7a6.cjs.dev.js +55 -0
  371. package/dist/{singleProducerAsyncInput-4105a342.cjs.dev.js → singleProducerAsyncInput-9ff8389b.cjs.dev.js} +1 -1
  372. package/dist/{singleProducerAsyncInput-21463e16.cjs.prod.js → singleProducerAsyncInput-f9b258b1.cjs.prod.js} +1 -1
  373. package/dist/{sink-9129504b.cjs.prod.js → sink-572d8981.cjs.prod.js} +17 -17
  374. package/dist/{sink-ee393b63.cjs.dev.js → sink-8d3427e7.cjs.dev.js} +17 -17
  375. package/dist/{state-dd1bd066.cjs.prod.js → state-0bdf02b7.cjs.prod.js} +2 -6
  376. package/dist/{state-8fbec044.cjs.dev.js → state-931050c4.cjs.dev.js} +2 -6
  377. package/dist/{stm-537da66b.cjs.dev.js → stm-8aca0022.cjs.dev.js} +3 -3
  378. package/dist/{stm-5043c3cb.cjs.prod.js → stm-f250b596.cjs.prod.js} +3 -3
  379. package/dist/{stream-c7eda5bc.cjs.dev.js → stream-34d80d2c.cjs.dev.js} +31 -28
  380. package/dist/{stream-13637643.cjs.prod.js → stream-ea4f4d44.cjs.prod.js} +31 -28
  381. package/dist/{synchronizedRef-37e32854.cjs.dev.js → synchronizedRef-a12fd967.cjs.dev.js} +6 -6
  382. package/dist/{synchronizedRef-b4cde4de.cjs.prod.js → synchronizedRef-ed8aa6ac.cjs.prod.js} +6 -6
  383. package/dist/{tArray-df1bae1c.cjs.dev.js → tArray-17f078f2.cjs.dev.js} +3 -3
  384. package/dist/{tArray-d5476a2d.cjs.prod.js → tArray-d184e22f.cjs.prod.js} +3 -3
  385. package/dist/{tMap-a3e14c05.cjs.dev.js → tMap-1a5aa78b.cjs.dev.js} +4 -4
  386. package/dist/{tMap-20ef43ea.cjs.prod.js → tMap-e219f30e.cjs.prod.js} +4 -4
  387. package/dist/{tQueue-bd3cf539.cjs.dev.js → tQueue-0a4fc773.cjs.dev.js} +3 -3
  388. package/dist/{tQueue-c02c22bd.cjs.prod.js → tQueue-47129ad0.cjs.prod.js} +3 -3
  389. package/dist/{tRef-49e44dde.cjs.prod.js → tRef-ab4c5713.cjs.prod.js} +1 -1
  390. package/dist/{tRef-75dd04b3.cjs.dev.js → tRef-b860ef05.cjs.dev.js} +1 -1
  391. package/internal/Context.esm.js +4 -4
  392. package/internal/Data.esm.js +4 -1
  393. package/internal/Differ/ChunkPatch.esm.js +1 -1
  394. package/internal/Differ/ContextPatch.esm.js +1 -1
  395. package/internal/Differ/HashMapPatch.esm.js +1 -1
  396. package/internal/Differ/HashSetPatch.esm.js +1 -1
  397. package/internal/Differ/OrPatch.esm.js +1 -1
  398. package/internal/Effectable.esm.js +9 -9
  399. package/internal/Either.esm.js +3 -3
  400. package/internal/Option.esm.js +3 -3
  401. package/internal/cache.esm.js +1 -1
  402. package/internal/cause.esm.js +6 -21
  403. package/internal/channel.esm.js +5 -5
  404. package/internal/core-effect.esm.js +6 -4
  405. package/internal/fiberRuntime.esm.js +3 -3
  406. package/internal/layer.esm.js +1 -1
  407. package/internal/metric/hook.esm.js +7 -3
  408. package/internal/metric/key.esm.js +2 -2
  409. package/internal/metric/keyType.esm.js +9 -2
  410. package/internal/metric/registry.esm.js +2 -2
  411. package/internal/metric/state.esm.js +2 -6
  412. package/internal/metric.esm.js +3 -3
  413. package/internal/{hub.esm.js → pubsub.esm.js} +108 -108
  414. package/internal/request.esm.js +1 -1
  415. package/internal/sink.esm.js +8 -8
  416. package/internal/stm/{tHub.esm.js → tPubSub.esm.js} +30 -30
  417. package/internal/stream.esm.js +23 -20
  418. package/internal/subscriptionRef.esm.js +8 -8
  419. package/package.json +66 -211
  420. package/src/.index.ts +30 -0
  421. package/src/Bigint.ts +497 -0
  422. package/src/Boolean.ts +261 -0
  423. package/src/Brand.ts +336 -0
  424. package/src/Cache.ts +250 -0
  425. package/src/Cause.ts +813 -0
  426. package/src/Channel.ts +2244 -0
  427. package/src/ChannelChildExecutorDecision.ts +138 -0
  428. package/src/ChannelMergeDecision.ts +94 -0
  429. package/src/ChannelMergeState.ts +166 -0
  430. package/src/ChannelMergeStrategy.ts +107 -0
  431. package/src/ChannelSingleProducerAsyncInput.ts +68 -0
  432. package/src/ChannelUpstreamPullRequest.ts +110 -0
  433. package/src/ChannelUpstreamPullStrategy.ts +120 -0
  434. package/src/Chunk.ts +1314 -0
  435. package/src/Clock.ts +111 -0
  436. package/src/Config.ts +447 -0
  437. package/src/ConfigError.ts +267 -0
  438. package/src/ConfigProvider.ts +296 -0
  439. package/src/ConfigProviderPathPatch.ts +100 -0
  440. package/src/ConfigSecret.ts +76 -0
  441. package/src/Console.ts +222 -0
  442. package/src/Context.ts +365 -0
  443. package/src/Data.ts +367 -0
  444. package/src/DefaultServices.ts +34 -0
  445. package/src/Deferred.ts +283 -0
  446. package/src/Differ.ts +406 -0
  447. package/src/Duration.ts +558 -0
  448. package/src/Effect.ts +5177 -0
  449. package/src/Effectable.ts +107 -0
  450. package/src/Either.ts +593 -0
  451. package/src/Encoding.ts +130 -0
  452. package/src/Equal.ts +64 -0
  453. package/src/Equivalence.ts +235 -0
  454. package/src/ExecutionStrategy.ts +111 -0
  455. package/src/Exit.ts +464 -0
  456. package/src/Fiber.ts +650 -0
  457. package/src/FiberId.ts +187 -0
  458. package/src/FiberRef.ts +399 -0
  459. package/src/FiberRefs.ts +160 -0
  460. package/src/FiberRefsPatch.ts +105 -0
  461. package/src/FiberStatus.ts +108 -0
  462. package/src/Function.ts +834 -0
  463. package/src/GlobalValue.ts +20 -0
  464. package/src/GroupBy.ts +102 -0
  465. package/src/HKT.ts +44 -0
  466. package/src/Hash.ts +162 -0
  467. package/src/HashMap.ts +373 -0
  468. package/src/HashSet.ts +300 -0
  469. package/src/Inspectable.ts +45 -0
  470. package/src/KeyedPool.ts +160 -0
  471. package/src/Layer.ts +866 -0
  472. package/src/List.ts +942 -0
  473. package/src/LogLevel.ts +266 -0
  474. package/src/LogSpan.ts +25 -0
  475. package/src/Logger.ts +321 -0
  476. package/src/Metric.ts +657 -0
  477. package/src/MetricBoundaries.ts +70 -0
  478. package/src/MetricHook.ts +139 -0
  479. package/src/MetricKey.ts +227 -0
  480. package/src/MetricKeyType.ts +257 -0
  481. package/src/MetricLabel.ts +47 -0
  482. package/src/MetricPair.ts +70 -0
  483. package/src/MetricPolling.ts +136 -0
  484. package/src/MetricRegistry.ts +47 -0
  485. package/src/MetricState.ts +256 -0
  486. package/src/MutableHashMap.ts +187 -0
  487. package/src/MutableHashSet.ts +118 -0
  488. package/src/MutableList.ts +289 -0
  489. package/src/MutableQueue.ts +227 -0
  490. package/src/MutableRef.ts +204 -0
  491. package/src/NonEmptyIterable.ts +30 -0
  492. package/src/Number.ts +406 -0
  493. package/src/Option.ts +1307 -0
  494. package/src/Order.ts +328 -0
  495. package/src/Ordering.ts +112 -0
  496. package/src/Pipeable.ts +318 -0
  497. package/src/Pool.ts +148 -0
  498. package/src/Predicate.ts +704 -0
  499. package/src/PubSub.ts +175 -0
  500. package/src/Queue.ts +575 -0
  501. package/src/Random.ts +115 -0
  502. package/src/ReadonlyArray.ts +2017 -0
  503. package/src/ReadonlyRecord.ts +641 -0
  504. package/src/RedBlackTree.ts +415 -0
  505. package/src/Ref.ts +159 -0
  506. package/src/Reloadable.ts +136 -0
  507. package/src/Request.ts +285 -0
  508. package/src/RequestBlock.ts +157 -0
  509. package/src/RequestResolver.ts +305 -0
  510. package/src/Resource.ts +97 -0
  511. package/src/Runtime.ts +216 -0
  512. package/src/RuntimeFlags.ts +336 -0
  513. package/src/RuntimeFlagsPatch.ts +183 -0
  514. package/src/STM.ts +2076 -0
  515. package/src/Schedule.ts +1396 -0
  516. package/src/ScheduleDecision.ts +62 -0
  517. package/src/ScheduleInterval.ts +151 -0
  518. package/src/ScheduleIntervals.ts +122 -0
  519. package/src/Scheduler.ts +359 -0
  520. package/src/Scope.ts +171 -0
  521. package/src/ScopedCache.ts +148 -0
  522. package/src/ScopedRef.ts +95 -0
  523. package/src/Sink.ts +1431 -0
  524. package/src/SortedMap.ts +229 -0
  525. package/src/SortedSet.ts +385 -0
  526. package/src/Stream.ts +4540 -0
  527. package/src/StreamEmit.ts +83 -0
  528. package/src/StreamHaltStrategy.ts +111 -0
  529. package/src/Streamable.ts +42 -0
  530. package/src/String.ts +682 -0
  531. package/src/Struct.ts +151 -0
  532. package/src/SubscriptionRef.ts +273 -0
  533. package/src/Supervisor.ts +239 -0
  534. package/src/Symbol.ts +28 -0
  535. package/src/SynchronizedRef.ts +249 -0
  536. package/src/TArray.ts +494 -0
  537. package/src/TDeferred.ts +99 -0
  538. package/src/TMap.ts +510 -0
  539. package/src/TPriorityQueue.ts +223 -0
  540. package/src/TPubSub.ts +187 -0
  541. package/src/TQueue.ts +431 -0
  542. package/src/TRandom.ts +129 -0
  543. package/src/TReentrantLock.ts +224 -0
  544. package/src/TRef.ts +176 -0
  545. package/src/TSemaphore.ts +129 -0
  546. package/src/TSet.ts +349 -0
  547. package/src/Take.ts +257 -0
  548. package/src/TestAnnotation.ts +166 -0
  549. package/src/TestAnnotationMap.ts +124 -0
  550. package/src/TestAnnotations.ts +113 -0
  551. package/src/TestClock.ts +552 -0
  552. package/src/TestConfig.ts +49 -0
  553. package/src/TestContext.ts +35 -0
  554. package/src/TestLive.ts +55 -0
  555. package/src/TestServices.ts +392 -0
  556. package/src/TestSized.ts +55 -0
  557. package/src/Tracer.ts +119 -0
  558. package/src/Tuple.ts +204 -0
  559. package/src/Types.ts +123 -0
  560. package/src/Unify.ts +118 -0
  561. package/src/Utils.ts +699 -0
  562. package/src/index.ts +840 -0
  563. package/src/internal/Common.ts +56 -0
  564. package/src/internal/Context.ts +252 -0
  565. package/src/internal/Data.ts +55 -0
  566. package/src/internal/Differ/ChunkPatch.ts +209 -0
  567. package/src/internal/Differ/ContextPatch.ts +229 -0
  568. package/src/internal/Differ/HashMapPatch.ts +217 -0
  569. package/src/internal/Differ/HashSetPatch.ts +174 -0
  570. package/src/internal/Differ/OrPatch.ts +296 -0
  571. package/src/internal/Differ.ts +184 -0
  572. package/src/internal/Effectable.ts +92 -0
  573. package/src/internal/Either.ts +107 -0
  574. package/src/internal/Encoding/Base64.ts +282 -0
  575. package/src/internal/Encoding/Base64Url.ts +28 -0
  576. package/src/internal/Encoding/Common.ts +24 -0
  577. package/src/internal/Encoding/Hex.ts +315 -0
  578. package/src/internal/HashMap/array.ts +49 -0
  579. package/src/internal/HashMap/bitwise.ts +32 -0
  580. package/src/internal/HashMap/config.ts +14 -0
  581. package/src/internal/HashMap/keySet.ts +8 -0
  582. package/src/internal/HashMap/node.ts +390 -0
  583. package/src/internal/HashMap.ts +533 -0
  584. package/src/internal/HashSet.ts +319 -0
  585. package/src/internal/Iterable.ts +54 -0
  586. package/src/internal/Option.ts +79 -0
  587. package/src/internal/ReadonlyArray.ts +8 -0
  588. package/src/internal/RedBlackTree/iterator.ts +207 -0
  589. package/src/internal/RedBlackTree/node.ts +48 -0
  590. package/src/internal/RedBlackTree.ts +1195 -0
  591. package/src/internal/Stack.ts +4 -0
  592. package/src/internal/blockedRequests.ts +512 -0
  593. package/src/internal/cache.ts +714 -0
  594. package/src/internal/cause.ts +1205 -0
  595. package/src/internal/channel/channelExecutor.ts +1193 -0
  596. package/src/internal/channel/channelState.ts +132 -0
  597. package/src/internal/channel/childExecutorDecision.ts +95 -0
  598. package/src/internal/channel/continuation.ts +171 -0
  599. package/src/internal/channel/mergeDecision.ts +115 -0
  600. package/src/internal/channel/mergeState.ts +120 -0
  601. package/src/internal/channel/mergeStrategy.ts +72 -0
  602. package/src/internal/channel/singleProducerAsyncInput.ts +261 -0
  603. package/src/internal/channel/subexecutor.ts +229 -0
  604. package/src/internal/channel/upstreamPullRequest.ts +83 -0
  605. package/src/internal/channel/upstreamPullStrategy.ts +86 -0
  606. package/src/internal/channel.ts +2516 -0
  607. package/src/internal/clock.ts +97 -0
  608. package/src/internal/completedRequestMap.ts +9 -0
  609. package/src/internal/concurrency.ts +83 -0
  610. package/src/internal/config.ts +598 -0
  611. package/src/internal/configError.ts +291 -0
  612. package/src/internal/configProvider/pathPatch.ts +97 -0
  613. package/src/internal/configProvider.ts +692 -0
  614. package/src/internal/configSecret.ts +71 -0
  615. package/src/internal/console.ts +136 -0
  616. package/src/internal/core-effect.ts +2146 -0
  617. package/src/internal/core-stream.ts +999 -0
  618. package/src/internal/core.ts +2765 -0
  619. package/src/internal/dataSource.ts +258 -0
  620. package/src/internal/defaultServices/console.ts +97 -0
  621. package/src/internal/defaultServices.ts +140 -0
  622. package/src/internal/deferred.ts +44 -0
  623. package/src/internal/effect/circular.ts +664 -0
  624. package/src/internal/executionStrategy.ts +72 -0
  625. package/src/internal/fiber.ts +350 -0
  626. package/src/internal/fiberId.ts +270 -0
  627. package/src/internal/fiberMessage.ts +85 -0
  628. package/src/internal/fiberRefs/patch.ts +144 -0
  629. package/src/internal/fiberRefs.ts +239 -0
  630. package/src/internal/fiberRuntime.ts +3477 -0
  631. package/src/internal/fiberScope.ts +72 -0
  632. package/src/internal/fiberStatus.ts +118 -0
  633. package/src/internal/groupBy.ts +516 -0
  634. package/src/internal/keyedPool.ts +240 -0
  635. package/src/internal/layer/circular.ts +203 -0
  636. package/src/internal/layer.ts +1230 -0
  637. package/src/internal/logSpan.ts +15 -0
  638. package/src/internal/logger-circular.ts +24 -0
  639. package/src/internal/logger.ts +307 -0
  640. package/src/internal/metric/boundaries.ts +72 -0
  641. package/src/internal/metric/hook.ts +459 -0
  642. package/src/internal/metric/key.ts +173 -0
  643. package/src/internal/metric/keyType.ts +263 -0
  644. package/src/internal/metric/label.ts +44 -0
  645. package/src/internal/metric/pair.ts +48 -0
  646. package/src/internal/metric/polling.ts +143 -0
  647. package/src/internal/metric/registry.ts +188 -0
  648. package/src/internal/metric/state.ts +286 -0
  649. package/src/internal/metric.ts +522 -0
  650. package/src/internal/opCodes/cause.ts +35 -0
  651. package/src/internal/opCodes/channel.ts +83 -0
  652. package/src/internal/opCodes/channelChildExecutorDecision.ts +17 -0
  653. package/src/internal/opCodes/channelMergeDecision.ts +11 -0
  654. package/src/internal/opCodes/channelMergeState.ts +17 -0
  655. package/src/internal/opCodes/channelMergeStrategy.ts +11 -0
  656. package/src/internal/opCodes/channelState.ts +23 -0
  657. package/src/internal/opCodes/channelUpstreamPullRequest.ts +11 -0
  658. package/src/internal/opCodes/channelUpstreamPullStrategy.ts +11 -0
  659. package/src/internal/opCodes/config.ts +65 -0
  660. package/src/internal/opCodes/configError.ts +35 -0
  661. package/src/internal/opCodes/continuation.ts +11 -0
  662. package/src/internal/opCodes/deferred.ts +11 -0
  663. package/src/internal/opCodes/effect.ts +83 -0
  664. package/src/internal/opCodes/layer.ts +53 -0
  665. package/src/internal/opCodes/streamHaltStrategy.ts +23 -0
  666. package/src/internal/pool.ts +499 -0
  667. package/src/internal/pubsub.ts +1557 -0
  668. package/src/internal/query.ts +199 -0
  669. package/src/internal/queue.ts +729 -0
  670. package/src/internal/random.ts +88 -0
  671. package/src/internal/ref.ts +164 -0
  672. package/src/internal/reloadable.ts +164 -0
  673. package/src/internal/request.ts +137 -0
  674. package/src/internal/resource.ts +64 -0
  675. package/src/internal/ringBuffer.ts +68 -0
  676. package/src/internal/runtime.ts +348 -0
  677. package/src/internal/runtimeFlags.ts +176 -0
  678. package/src/internal/runtimeFlagsPatch.ts +103 -0
  679. package/src/internal/schedule/decision.ts +47 -0
  680. package/src/internal/schedule/interval.ts +101 -0
  681. package/src/internal/schedule/intervals.ts +179 -0
  682. package/src/internal/schedule.ts +2096 -0
  683. package/src/internal/scopedCache.ts +634 -0
  684. package/src/internal/scopedRef.ts +133 -0
  685. package/src/internal/singleShotGen.ts +35 -0
  686. package/src/internal/sink.ts +2118 -0
  687. package/src/internal/stm/core.ts +804 -0
  688. package/src/internal/stm/opCodes/stm.ts +71 -0
  689. package/src/internal/stm/opCodes/stmState.ts +17 -0
  690. package/src/internal/stm/opCodes/strategy.ts +17 -0
  691. package/src/internal/stm/opCodes/tExit.ts +29 -0
  692. package/src/internal/stm/opCodes/tryCommit.ts +11 -0
  693. package/src/internal/stm/stm/entry.ts +59 -0
  694. package/src/internal/stm/stm/journal.ts +123 -0
  695. package/src/internal/stm/stm/opCodes/stm.ts +71 -0
  696. package/src/internal/stm/stm/opCodes/stmState.ts +17 -0
  697. package/src/internal/stm/stm/opCodes/strategy.ts +17 -0
  698. package/src/internal/stm/stm/opCodes/tExit.ts +29 -0
  699. package/src/internal/stm/stm/opCodes/tryCommit.ts +11 -0
  700. package/src/internal/stm/stm/stmState.ts +130 -0
  701. package/src/internal/stm/stm/tExit.ts +180 -0
  702. package/src/internal/stm/stm/tryCommit.ts +34 -0
  703. package/src/internal/stm/stm/txnId.ts +14 -0
  704. package/src/internal/stm/stm/versioned.ts +4 -0
  705. package/src/internal/stm/stm.ts +1491 -0
  706. package/src/internal/stm/tArray.ts +550 -0
  707. package/src/internal/stm/tDeferred.ts +79 -0
  708. package/src/internal/stm/tMap.ts +824 -0
  709. package/src/internal/stm/tPriorityQueue.ts +259 -0
  710. package/src/internal/stm/tPubSub.ts +542 -0
  711. package/src/internal/stm/tQueue.ts +400 -0
  712. package/src/internal/stm/tRandom.ts +140 -0
  713. package/src/internal/stm/tReentrantLock.ts +352 -0
  714. package/src/internal/stm/tRef.ts +190 -0
  715. package/src/internal/stm/tSemaphore.ts +113 -0
  716. package/src/internal/stm/tSet.ts +237 -0
  717. package/src/internal/stream/debounceState.ts +57 -0
  718. package/src/internal/stream/emit.ts +46 -0
  719. package/src/internal/stream/haltStrategy.ts +85 -0
  720. package/src/internal/stream/handoff.ts +185 -0
  721. package/src/internal/stream/handoffSignal.ts +59 -0
  722. package/src/internal/stream/pull.ts +35 -0
  723. package/src/internal/stream/sinkEndReason.ts +30 -0
  724. package/src/internal/stream/zipAllState.ts +88 -0
  725. package/src/internal/stream/zipChunksState.ts +56 -0
  726. package/src/internal/stream.ts +8089 -0
  727. package/src/internal/string-utils.ts +107 -0
  728. package/src/internal/subscriptionRef.ts +133 -0
  729. package/src/internal/supervisor/patch.ts +190 -0
  730. package/src/internal/supervisor.ts +301 -0
  731. package/src/internal/synchronizedRef.ts +115 -0
  732. package/src/internal/take.ts +198 -0
  733. package/src/internal/testing/sleep.ts +27 -0
  734. package/src/internal/testing/suspendedWarningData.ts +85 -0
  735. package/src/internal/testing/warningData.ts +94 -0
  736. package/src/internal/timeout.ts +23 -0
  737. package/src/internal/tracer.ts +74 -0
  738. package/Error/dist/effect-Error.cjs.d.mts +0 -2
  739. package/Error/dist/effect-Error.cjs.d.mts.map +0 -1
  740. package/Error/dist/effect-Error.cjs.d.ts +0 -2
  741. package/Error/dist/effect-Error.cjs.d.ts.map +0 -1
  742. package/Error/dist/effect-Error.cjs.dev.js +0 -140
  743. package/Error/dist/effect-Error.cjs.js +0 -7
  744. package/Error/dist/effect-Error.cjs.mjs +0 -4
  745. package/Error/dist/effect-Error.cjs.prod.js +0 -140
  746. package/Error/dist/effect-Error.esm.js +0 -47
  747. package/Error/package.json +0 -4
  748. package/Hub/dist/effect-Hub.cjs.d.mts +0 -2
  749. package/Hub/dist/effect-Hub.cjs.d.mts.map +0 -1
  750. package/Hub/dist/effect-Hub.cjs.d.ts +0 -2
  751. package/Hub/dist/effect-Hub.cjs.d.ts.map +0 -1
  752. package/Hub/dist/effect-Hub.cjs.js +0 -7
  753. package/Hub/package.json +0 -4
  754. package/THub/dist/effect-THub.cjs.d.mts +0 -2
  755. package/THub/dist/effect-THub.cjs.d.mts.map +0 -1
  756. package/THub/dist/effect-THub.cjs.d.ts +0 -2
  757. package/THub/dist/effect-THub.cjs.d.ts.map +0 -1
  758. package/THub/dist/effect-THub.cjs.js +0 -7
  759. package/THub/dist/effect-THub.esm.js +0 -157
  760. package/THub/package.json +0 -4
  761. package/dist/declarations/src/Error.d.ts +0 -37
  762. package/dist/declarations/src/Error.d.ts.map +0 -1
  763. package/dist/declarations/src/Hub.d.ts.map +0 -1
  764. package/dist/declarations/src/THub.d.ts +0 -146
  765. package/dist/declarations/src/THub.d.ts.map +0 -1
  766. package/dist/scopedRef-1c2c9acf.cjs.prod.js +0 -55
  767. package/dist/scopedRef-ab4c58b0.cjs.dev.js +0 -55
  768. /package/dist/{FiberId-e594f6e8.cjs.prod.js → FiberId-1d7ac632.cjs.prod.js} +0 -0
  769. /package/dist/{FiberId-557db880.cjs.dev.js → FiberId-d88ddce6.cjs.dev.js} +0 -0
  770. /package/dist/{RuntimeFlagsPatch-ea268c50.cjs.dev.js → RuntimeFlagsPatch-69102b03.cjs.dev.js} +0 -0
  771. /package/dist/{RuntimeFlagsPatch-e2769b87.cjs.prod.js → RuntimeFlagsPatch-866fa259.cjs.prod.js} +0 -0
  772. /package/dist/{boundaries-20cfad9d.cjs.prod.js → boundaries-9af538e3.cjs.prod.js} +0 -0
  773. /package/dist/{boundaries-3810d885.cjs.dev.js → boundaries-f212e414.cjs.dev.js} +0 -0
  774. /package/dist/{configError-33e55472.cjs.prod.js → configError-b43723af.cjs.prod.js} +0 -0
  775. /package/dist/{configError-240e9b61.cjs.dev.js → configError-d5efe9c0.cjs.dev.js} +0 -0
  776. /package/dist/{configSecret-e34c1b14.cjs.dev.js → configSecret-3e8ae336.cjs.dev.js} +0 -0
  777. /package/dist/{configSecret-d1caca55.cjs.prod.js → configSecret-e2faa181.cjs.prod.js} +0 -0
  778. /package/dist/{take-2af6e92a.cjs.prod.js → take-85daaf79.cjs.prod.js} +0 -0
  779. /package/dist/{take-df9480a8.cjs.dev.js → take-f9ef9e2e.cjs.dev.js} +0 -0
@@ -0,0 +1,1491 @@
1
+ import * as Cause from "../../Cause"
2
+ import * as Chunk from "../../Chunk"
3
+ import * as Context from "../../Context"
4
+ import * as Effect from "../../Effect"
5
+ import * as Either from "../../Either"
6
+ import * as Exit from "../../Exit"
7
+ import type * as FiberId from "../../FiberId"
8
+ import type { LazyArg } from "../../Function"
9
+ import { constFalse, constTrue, constVoid, dual, identity, pipe } from "../../Function"
10
+ import * as effectCore from "../../internal/core"
11
+ import * as SingleShotGen from "../../internal/singleShotGen"
12
+ import * as core from "../../internal/stm/core"
13
+ import * as Journal from "../../internal/stm/stm/journal"
14
+ import * as STMState from "../../internal/stm/stm/stmState"
15
+ import * as Option from "../../Option"
16
+ import * as predicate from "../../Predicate"
17
+ import type { Predicate, Refinement } from "../../Predicate"
18
+ import * as RA from "../../ReadonlyArray"
19
+ import type * as STM from "../../STM"
20
+
21
+ /** @internal */
22
+ export const acquireUseRelease = dual<
23
+ <A, R2, E2, A2, R3, E3, A3>(
24
+ use: (resource: A) => STM.STM<R2, E2, A2>,
25
+ release: (resource: A) => STM.STM<R3, E3, A3>
26
+ ) => <R, E>(
27
+ acquire: STM.STM<R, E, A>
28
+ ) => Effect.Effect<R | R2 | R3, E | E2 | E3, A2>,
29
+ <R, E, A, R2, E2, A2, R3, E3, A3>(
30
+ acquire: STM.STM<R, E, A>,
31
+ use: (resource: A) => STM.STM<R2, E2, A2>,
32
+ release: (resource: A) => STM.STM<R3, E3, A3>
33
+ ) => Effect.Effect<R | R2 | R3, E | E2 | E3, A2>
34
+ >(3, <R, E, A, R2, E2, A2, R3, E3, A3>(
35
+ acquire: STM.STM<R, E, A>,
36
+ use: (resource: A) => STM.STM<R2, E2, A2>,
37
+ release: (resource: A) => STM.STM<R3, E3, A3>
38
+ ): Effect.Effect<R | R2 | R3, E | E2 | E3, A2> =>
39
+ Effect.uninterruptibleMask((restore) => {
40
+ let state: STMState.STMState<E, A> = STMState.running
41
+ return pipe(
42
+ restore(
43
+ core.unsafeAtomically(
44
+ acquire,
45
+ (exit) => {
46
+ state = STMState.done(exit)
47
+ },
48
+ () => {
49
+ state = STMState.interrupted
50
+ }
51
+ )
52
+ ),
53
+ Effect.matchCauseEffect({
54
+ onFailure: (cause) => {
55
+ if (STMState.isDone(state) && Exit.isSuccess(state.exit)) {
56
+ return pipe(
57
+ release(state.exit.value),
58
+ Effect.matchCauseEffect({
59
+ onFailure: (cause2) => Effect.failCause(Cause.parallel(cause, cause2)),
60
+ onSuccess: () => Effect.failCause(cause)
61
+ })
62
+ )
63
+ }
64
+ return Effect.failCause(cause)
65
+ },
66
+ onSuccess: (a) =>
67
+ pipe(
68
+ restore(use(a)),
69
+ Effect.matchCauseEffect({
70
+ onFailure: (cause) =>
71
+ pipe(
72
+ release(a),
73
+ Effect.matchCauseEffect({
74
+ onFailure: (cause2) => Effect.failCause(Cause.parallel(cause, cause2)),
75
+ onSuccess: () => Effect.failCause(cause)
76
+ })
77
+ ),
78
+ onSuccess: (a2) => pipe(release(a), Effect.as(a2))
79
+ })
80
+ )
81
+ })
82
+ )
83
+ }))
84
+
85
+ /** @internal */
86
+ export const as = dual<
87
+ <A2>(value: A2) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<R, E, A2>,
88
+ <R, E, A, A2>(self: STM.STM<R, E, A>, value: A2) => STM.STM<R, E, A2>
89
+ >(2, (self, value) => pipe(self, core.map(() => value)))
90
+
91
+ /** @internal */
92
+ export const asSome = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, E, Option.Option<A>> =>
93
+ pipe(self, core.map(Option.some))
94
+
95
+ /** @internal */
96
+ export const asSomeError = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, Option.Option<E>, A> =>
97
+ pipe(self, mapError(Option.some))
98
+
99
+ /** @internal */
100
+ export const asUnit = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, E, void> => pipe(self, core.map(constVoid))
101
+
102
+ /** @internal */
103
+ export const attempt = <A>(evaluate: LazyArg<A>): STM.STM<never, unknown, A> =>
104
+ suspend(() => {
105
+ try {
106
+ return core.succeed(evaluate())
107
+ } catch (defect) {
108
+ return core.fail(defect)
109
+ }
110
+ })
111
+
112
+ export const bind = dual<
113
+ <N extends string, K, R2, E2, A>(
114
+ tag: Exclude<N, keyof K>,
115
+ f: (_: K) => STM.STM<R2, E2, A>
116
+ ) => <R, E>(self: STM.STM<R, E, K>) => STM.STM<
117
+ R | R2,
118
+ E | E2,
119
+ Effect.MergeRecord<K, { [k in N]: A }>
120
+ >,
121
+ <R, E, N extends string, K, R2, E2, A>(
122
+ self: STM.STM<R, E, K>,
123
+ tag: Exclude<N, keyof K>,
124
+ f: (_: K) => STM.STM<R2, E2, A>
125
+ ) => STM.STM<
126
+ R | R2,
127
+ E | E2,
128
+ Effect.MergeRecord<K, { [k in N]: A }>
129
+ >
130
+ >(3, <R, E, N extends string, K, R2, E2, A>(
131
+ self: STM.STM<R, E, K>,
132
+ tag: Exclude<N, keyof K>,
133
+ f: (_: K) => STM.STM<R2, E2, A>
134
+ ) =>
135
+ core.flatMap(self, (k) =>
136
+ core.map(
137
+ f(k),
138
+ (a): Effect.MergeRecord<K, { [k in N]: A }> => ({ ...k, [tag]: a } as any)
139
+ )))
140
+
141
+ /* @internal */
142
+ export const bindTo = dual<
143
+ <N extends string>(tag: N) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<
144
+ R,
145
+ E,
146
+ Record<N, A>
147
+ >,
148
+ <R, E, A, N extends string>(
149
+ self: STM.STM<R, E, A>,
150
+ tag: N
151
+ ) => STM.STM<
152
+ R,
153
+ E,
154
+ Record<N, A>
155
+ >
156
+ >(
157
+ 2,
158
+ <R, E, A, N extends string>(self: STM.STM<R, E, A>, tag: N): STM.STM<R, E, Record<N, A>> =>
159
+ core.map(self, (a) => ({ [tag]: a } as Record<N, A>))
160
+ )
161
+
162
+ /* @internal */
163
+ export const let_ = dual<
164
+ <N extends string, K, A>(
165
+ tag: Exclude<N, keyof K>,
166
+ f: (_: K) => A
167
+ ) => <R, E>(self: STM.STM<R, E, K>) => STM.STM<
168
+ R,
169
+ E,
170
+ Effect.MergeRecord<K, { [k in N]: A }>
171
+ >,
172
+ <R, E, K, N extends string, A>(
173
+ self: STM.STM<R, E, K>,
174
+ tag: Exclude<N, keyof K>,
175
+ f: (_: K) => A
176
+ ) => STM.STM<
177
+ R,
178
+ E,
179
+ Effect.MergeRecord<K, { [k in N]: A }>
180
+ >
181
+ >(3, <R, E, K, N extends string, A>(self: STM.STM<R, E, K>, tag: Exclude<N, keyof K>, f: (_: K) => A) =>
182
+ core.map(
183
+ self,
184
+ (k): Effect.MergeRecord<K, { [k in N]: A }> => ({ ...k, [tag]: f(k) } as any)
185
+ ))
186
+
187
+ /** @internal */
188
+ export const catchSome = dual<
189
+ <E, R2, E2, A2>(
190
+ pf: (error: E) => Option.Option<STM.STM<R2, E2, A2>>
191
+ ) => <R, A>(
192
+ self: STM.STM<R, E, A>
193
+ ) => STM.STM<R2 | R, E | E2, A2 | A>,
194
+ <R, A, E, R2, E2, A2>(
195
+ self: STM.STM<R, E, A>,
196
+ pf: (error: E) => Option.Option<STM.STM<R2, E2, A2>>
197
+ ) => STM.STM<R2 | R, E | E2, A2 | A>
198
+ >(2, <R, A, E, R2, E2, A2>(
199
+ self: STM.STM<R, E, A>,
200
+ pf: (error: E) => Option.Option<STM.STM<R2, E2, A2>>
201
+ ): STM.STM<R2 | R, E | E2, A2 | A> =>
202
+ core.catchAll(
203
+ self,
204
+ (e): STM.STM<R | R2, E | E2, A | A2> => Option.getOrElse(pf(e), () => core.fail(e))
205
+ ))
206
+
207
+ export const catchTag = dual<
208
+ <K extends E["_tag"] & string, E extends { _tag: string }, R1, E1, A1>(
209
+ k: K,
210
+ f: (e: Extract<E, { _tag: K }>) => STM.STM<R1, E1, A1>
211
+ ) => <R, A>(self: STM.STM<R, E, A>) => STM.STM<R | R1, Exclude<E, { _tag: K }> | E1, A | A1>,
212
+ <R, E extends { _tag: string }, A, K extends E["_tag"] & string, R1, E1, A1>(
213
+ self: STM.STM<R, E, A>,
214
+ k: K,
215
+ f: (e: Extract<E, { _tag: K }>) => STM.STM<R1, E1, A1>
216
+ ) => STM.STM<R | R1, Exclude<E, { _tag: K }> | E1, A | A1>
217
+ >(3, (self, k, f) =>
218
+ core.catchAll(self, (e) => {
219
+ if ("_tag" in e && e["_tag"] === k) {
220
+ return f(e as any)
221
+ }
222
+ return core.fail(e as any)
223
+ }))
224
+
225
+ /** @internal */
226
+ export const catchTags: {
227
+ <
228
+ E extends { _tag: string },
229
+ Cases extends {
230
+ [K in E["_tag"]]+?: (error: Extract<E, { _tag: K }>) => STM.STM<any, any, any>
231
+ }
232
+ >(
233
+ cases: Cases
234
+ ): <R, A>(self: STM.STM<R, E, A>) => STM.STM<
235
+ | R
236
+ | {
237
+ [K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<infer R, any, any>) ? R : never
238
+ }[keyof Cases],
239
+ | Exclude<E, { _tag: keyof Cases }>
240
+ | {
241
+ [K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<any, infer E, any>) ? E : never
242
+ }[keyof Cases],
243
+ | A
244
+ | {
245
+ [K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<any, any, infer A>) ? A : never
246
+ }[keyof Cases]
247
+ >
248
+ <
249
+ R,
250
+ E extends { _tag: string },
251
+ A,
252
+ Cases extends {
253
+ [K in E["_tag"]]+?: (error: Extract<E, { _tag: K }>) => STM.STM<any, any, any>
254
+ }
255
+ >(
256
+ self: STM.STM<R, E, A>,
257
+ cases: Cases
258
+ ): STM.STM<
259
+ | R
260
+ | {
261
+ [K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<infer R, any, any>) ? R : never
262
+ }[keyof Cases],
263
+ | Exclude<E, { _tag: keyof Cases }>
264
+ | {
265
+ [K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<any, infer E, any>) ? E : never
266
+ }[keyof Cases],
267
+ | A
268
+ | {
269
+ [K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<any, any, infer A>) ? A : never
270
+ }[keyof Cases]
271
+ >
272
+ } = dual(2, (self, cases) =>
273
+ core.catchAll(self, (e: any) => {
274
+ const keys = Object.keys(cases)
275
+ if ("_tag" in e && keys.includes(e["_tag"])) {
276
+ return cases[e["_tag"]](e as any)
277
+ }
278
+ return core.fail(e as any)
279
+ }))
280
+
281
+ /** @internal */
282
+ export const check = (predicate: LazyArg<boolean>): STM.STM<never, never, void> =>
283
+ suspend(() => predicate() ? unit : core.retry)
284
+
285
+ /** @internal */
286
+ export const collect = dual<
287
+ <A, A2>(pf: (a: A) => Option.Option<A2>) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, A2>,
288
+ <R, E, A, A2>(self: STM.STM<R, E, A>, pf: (a: A) => Option.Option<A2>) => STM.STM<R, E, A2>
289
+ >(2, (self, pf) =>
290
+ collectSTM(
291
+ self,
292
+ (a) => Option.map(pf(a), core.succeed)
293
+ ))
294
+
295
+ /** @internal */
296
+ export const collectSTM = dual<
297
+ <A, R2, E2, A2>(
298
+ pf: (a: A) => Option.Option<STM.STM<R2, E2, A2>>
299
+ ) => <R, E>(
300
+ self: STM.STM<R, E, A>
301
+ ) => STM.STM<R2 | R, E2 | E, A2>,
302
+ <R, E, A, R2, E2, A2>(
303
+ self: STM.STM<R, E, A>,
304
+ pf: (a: A) => Option.Option<STM.STM<R2, E2, A2>>
305
+ ) => STM.STM<R2 | R, E2 | E, A2>
306
+ >(2, (self, pf) =>
307
+ core.matchSTM(self, {
308
+ onFailure: core.fail,
309
+ onSuccess: (a) => {
310
+ const option = pf(a)
311
+ return Option.isSome(option) ? option.value : core.retry
312
+ }
313
+ }))
314
+
315
+ /** @internal */
316
+ export const commitEither = <R, E, A>(self: STM.STM<R, E, A>): Effect.Effect<R, E, A> =>
317
+ Effect.flatten(core.commit(either(self)))
318
+
319
+ /** @internal */
320
+ export const cond = <E, A>(
321
+ predicate: LazyArg<boolean>,
322
+ error: LazyArg<E>,
323
+ result: LazyArg<A>
324
+ ): STM.STM<never, E, A> => {
325
+ return suspend(
326
+ () => predicate() ? core.sync(result) : core.failSync(error)
327
+ )
328
+ }
329
+
330
+ /** @internal */
331
+ export const either = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, Either.Either<E, A>> =>
332
+ match(self, { onFailure: Either.left, onSuccess: Either.right })
333
+
334
+ /** @internal */
335
+ export const eventually = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, E, A> =>
336
+ core.matchSTM(self, { onFailure: () => eventually(self), onSuccess: core.succeed })
337
+
338
+ /** @internal */
339
+ export const every = dual<
340
+ <A, R, E>(predicate: (a: A) => STM.STM<R, E, boolean>) => (iterable: Iterable<A>) => STM.STM<R, E, boolean>,
341
+ <A, R, E>(iterable: Iterable<A>, predicate: (a: A) => STM.STM<R, E, boolean>) => STM.STM<R, E, boolean>
342
+ >(
343
+ 2,
344
+ <A, R, E>(
345
+ iterable: Iterable<A>,
346
+ predicate: (a: A) => STM.STM<R, E, boolean>
347
+ ): STM.STM<R, E, boolean> =>
348
+ pipe(
349
+ core.flatMap(core.sync(() => iterable[Symbol.iterator]()), (iterator) => {
350
+ const loop: STM.STM<R, E, boolean> = suspend(() => {
351
+ const next = iterator.next()
352
+ if (next.done) {
353
+ return core.succeed(true)
354
+ }
355
+ return pipe(
356
+ predicate(next.value),
357
+ core.flatMap((bool) => bool ? loop : core.succeed(bool))
358
+ )
359
+ })
360
+ return loop
361
+ })
362
+ )
363
+ )
364
+
365
+ /** @internal */
366
+ export const exists = dual<
367
+ <A, R, E>(predicate: (a: A) => STM.STM<R, E, boolean>) => (iterable: Iterable<A>) => STM.STM<R, E, boolean>,
368
+ <A, R, E>(iterable: Iterable<A>, predicate: (a: A) => STM.STM<R, E, boolean>) => STM.STM<R, E, boolean>
369
+ >(
370
+ 2,
371
+ <A, R, E>(iterable: Iterable<A>, predicate: (a: A) => STM.STM<R, E, boolean>): STM.STM<R, E, boolean> =>
372
+ core.flatMap(core.sync(() => iterable[Symbol.iterator]()), (iterator) => {
373
+ const loop: STM.STM<R, E, boolean> = suspend(() => {
374
+ const next = iterator.next()
375
+ if (next.done) {
376
+ return core.succeed(false)
377
+ }
378
+ return core.flatMap(
379
+ predicate(next.value),
380
+ (bool) => bool ? core.succeed(bool) : loop
381
+ )
382
+ })
383
+ return loop
384
+ })
385
+ )
386
+
387
+ /** @internal */
388
+ export const fiberId: STM.STM<never, never, FiberId.FiberId> = core.effect<never, FiberId.FiberId>((_, fiberId) =>
389
+ fiberId
390
+ )
391
+
392
+ /** @internal */
393
+ export const filter = dual<
394
+ <A, R, E>(predicate: (a: A) => STM.STM<R, E, boolean>) => (iterable: Iterable<A>) => STM.STM<R, E, Array<A>>,
395
+ <A, R, E>(iterable: Iterable<A>, predicate: (a: A) => STM.STM<R, E, boolean>) => STM.STM<R, E, Array<A>>
396
+ >(
397
+ 2,
398
+ <A, R, E>(iterable: Iterable<A>, predicate: (a: A) => STM.STM<R, E, boolean>): STM.STM<R, E, Array<A>> =>
399
+ Array.from(iterable).reduce(
400
+ (acc, curr) =>
401
+ pipe(
402
+ acc,
403
+ core.zipWith(predicate(curr), (as, p) => {
404
+ if (p) {
405
+ as.push(curr)
406
+ return as
407
+ }
408
+ return as
409
+ })
410
+ ),
411
+ core.succeed([]) as STM.STM<R, E, Array<A>>
412
+ )
413
+ )
414
+
415
+ /** @internal */
416
+ export const filterNot = dual<
417
+ <A, R, E>(predicate: (a: A) => STM.STM<R, E, boolean>) => (iterable: Iterable<A>) => STM.STM<R, E, Array<A>>,
418
+ <A, R, E>(iterable: Iterable<A>, predicate: (a: A) => STM.STM<R, E, boolean>) => STM.STM<R, E, Array<A>>
419
+ >(
420
+ 2,
421
+ <A, R, E>(iterable: Iterable<A>, predicate: (a: A) => STM.STM<R, E, boolean>): STM.STM<R, E, Array<A>> =>
422
+ filter(iterable, (a) => negate(predicate(a)))
423
+ )
424
+
425
+ /** @internal */
426
+ export const filterOrDie = dual<
427
+ {
428
+ <A, B extends A>(
429
+ refinement: Refinement<A, B>,
430
+ defect: LazyArg<unknown>
431
+ ): <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, B>
432
+ <A, X extends A>(
433
+ predicate: Predicate<X>,
434
+ defect: LazyArg<unknown>
435
+ ): <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, A>
436
+ },
437
+ {
438
+ <R, E, A, B extends A>(
439
+ self: STM.STM<R, E, A>,
440
+ refinement: Refinement<A, B>,
441
+ defect: LazyArg<unknown>
442
+ ): STM.STM<R, E, B>
443
+ <R, E, A, X extends A>(self: STM.STM<R, E, A>, predicate: Predicate<X>, defect: LazyArg<unknown>): STM.STM<R, E, A>
444
+ }
445
+ >(
446
+ 3,
447
+ <R, E, A, X extends A>(self: STM.STM<R, E, A>, predicate: Predicate<X>, defect: LazyArg<unknown>): STM.STM<R, E, A> =>
448
+ filterOrElse(self, predicate, () => core.dieSync(defect))
449
+ )
450
+
451
+ /** @internal */
452
+ export const filterOrDieMessage = dual<
453
+ {
454
+ <A, B extends A>(refinement: Refinement<A, B>, message: string): <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, B>
455
+ <A, X extends A>(predicate: Predicate<X>, message: string): <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, A>
456
+ },
457
+ {
458
+ <R, E, A, B extends A>(self: STM.STM<R, E, A>, refinement: Refinement<A, B>, message: string): STM.STM<R, E, B>
459
+ <R, E, A, X extends A>(self: STM.STM<R, E, A>, predicate: Predicate<X>, message: string): STM.STM<R, E, A>
460
+ }
461
+ >(
462
+ 3,
463
+ (self, predicate, message) => filterOrElse(self, predicate, () => core.dieMessage(message))
464
+ )
465
+
466
+ /** @internal */
467
+ export const filterOrElse = dual<
468
+ {
469
+ <A, B extends A, X extends A, R2, E2, A2>(
470
+ refinement: Refinement<A, B>,
471
+ orElse: (a: X) => STM.STM<R2, E2, A2>
472
+ ): <R, E>(
473
+ self: STM.STM<R, E, A>
474
+ ) => STM.STM<R2 | R, E2 | E, B | A2>
475
+ <A, X extends A, Y extends A, R2, E2, A2>(
476
+ predicate: Predicate<X>,
477
+ orElse: (a: Y) => STM.STM<R2, E2, A2>
478
+ ): <R, E>(
479
+ self: STM.STM<R, E, A>
480
+ ) => STM.STM<R2 | R, E2 | E, A | A2>
481
+ },
482
+ {
483
+ <R, E, A, B extends A, X extends A, R2, E2, A2>(
484
+ self: STM.STM<R, E, A>,
485
+ refinement: Refinement<A, B>,
486
+ orElse: (a: X) => STM.STM<R2, E2, A2>
487
+ ): STM.STM<R2 | R, E2 | E, B | A2>
488
+ <R, E, A, X extends A, Y extends A, R2, E2, A2>(
489
+ self: STM.STM<R, E, A>,
490
+ predicate: Predicate<X>,
491
+ orElse: (a: Y) => STM.STM<R2, E2, A2>
492
+ ): STM.STM<R2 | R, E2 | E, A | A2>
493
+ }
494
+ >(
495
+ 3,
496
+ <R, E, A, X extends A, Y extends A, R2, E2, A2>(
497
+ self: STM.STM<R, E, A>,
498
+ predicate: Predicate<X>,
499
+ orElse: (a: Y) => STM.STM<R2, E2, A2>
500
+ ): STM.STM<R2 | R, E2 | E, A | A2> =>
501
+ core.flatMap(self, (a): STM.STM<R | R2, E | E2, A | A2> =>
502
+ predicate(a as X) ?
503
+ core.succeed(a) :
504
+ orElse(a as Y))
505
+ )
506
+
507
+ /** @internal */
508
+ export const filterOrFail = dual<
509
+ {
510
+ <A, B extends A, X extends A, E2>(
511
+ refinement: Refinement<A, B>,
512
+ orFailWith: (a: X) => E2
513
+ ): <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E2 | E, B>
514
+ <A, X extends A, Y extends A, E2>(
515
+ predicate: Predicate<X>,
516
+ orFailWith: (a: Y) => E2
517
+ ): <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E2 | E, A>
518
+ },
519
+ {
520
+ <R, E, A, B extends A, X extends A, E2>(
521
+ self: STM.STM<R, E, A>,
522
+ refinement: Refinement<A, B>,
523
+ orFailWith: (a: X) => E2
524
+ ): STM.STM<R, E2 | E, B>
525
+ <R, E, A, X extends A, Y extends A, E2>(
526
+ self: STM.STM<R, E, A>,
527
+ predicate: Predicate<X>,
528
+ orFailWith: (a: Y) => E2
529
+ ): STM.STM<R, E2 | E, A>
530
+ }
531
+ >(3, (self, predicate, orFailWith) =>
532
+ filterOrElse(
533
+ self,
534
+ predicate,
535
+ (a) => core.failSync(() => orFailWith(a as any))
536
+ ))
537
+
538
+ /** @internal */
539
+ export const flatten = <R, E, R2, E2, A>(self: STM.STM<R, E, STM.STM<R2, E2, A>>): STM.STM<R | R2, E | E2, A> =>
540
+ core.flatMap(self, identity)
541
+
542
+ /** @internal */
543
+ export const flip = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, A, E> =>
544
+ core.matchSTM(self, { onFailure: core.succeed, onSuccess: core.fail })
545
+
546
+ /** @internal */
547
+ export const flipWith = dual<
548
+ <R, A, E, R2, A2, E2>(
549
+ f: (stm: STM.STM<R, A, E>) => STM.STM<R2, A2, E2>
550
+ ) => (
551
+ self: STM.STM<R, E, A>
552
+ ) => STM.STM<R | R2, E | E2, A | A2>,
553
+ <R, A, E, R2, A2, E2>(
554
+ self: STM.STM<R, E, A>,
555
+ f: (stm: STM.STM<R, A, E>) => STM.STM<R2, A2, E2>
556
+ ) => STM.STM<R | R2, E | E2, A | A2>
557
+ >(2, (self, f) => flip(f(flip(self))))
558
+
559
+ /** @internal */
560
+ export const match = dual<
561
+ <E, A2, A, A3>(options: {
562
+ readonly onFailure: (error: E) => A2
563
+ readonly onSuccess: (value: A) => A3
564
+ }) => <R>(self: STM.STM<R, E, A>) => STM.STM<R, never, A2 | A3>,
565
+ <R, E, A2, A, A3>(self: STM.STM<R, E, A>, options: {
566
+ readonly onFailure: (error: E) => A2
567
+ readonly onSuccess: (value: A) => A3
568
+ }) => STM.STM<R, never, A2 | A3>
569
+ >(2, (self, { onFailure, onSuccess }) =>
570
+ core.matchSTM(self, {
571
+ onFailure: (e) => core.succeed(onFailure(e)),
572
+ onSuccess: (a) => core.succeed(onSuccess(a))
573
+ }))
574
+
575
+ /** @internal */
576
+ export const forEach = dual<
577
+ {
578
+ <A, R, E, A2>(f: (a: A) => STM.STM<R, E, A2>, options?: {
579
+ readonly discard?: false
580
+ }): (elements: Iterable<A>) => STM.STM<R, E, Array<A2>>
581
+ <A, R, E, A2>(f: (a: A) => STM.STM<R, E, A2>, options: {
582
+ readonly discard: true
583
+ }): (elements: Iterable<A>) => STM.STM<R, E, void>
584
+ },
585
+ {
586
+ <A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM.STM<R, E, A2>, options?: {
587
+ readonly discard?: false
588
+ }): STM.STM<R, E, Array<A2>>
589
+ <A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM.STM<R, E, A2>, options: {
590
+ readonly discard: true
591
+ }): STM.STM<R, E, void>
592
+ }
593
+ >(
594
+ (args) => predicate.isIterable(args[0]),
595
+ <A, R, E, A2>(iterable: Iterable<A>, f: (a: A) => STM.STM<R, E, A2>, options?: {
596
+ readonly discard?: boolean
597
+ }): STM.STM<R, E, any> => {
598
+ if (options?.discard) {
599
+ return pipe(
600
+ core.sync(() => iterable[Symbol.iterator]()),
601
+ core.flatMap((iterator) => {
602
+ const loop: STM.STM<R, E, void> = suspend(() => {
603
+ const next = iterator.next()
604
+ if (next.done) {
605
+ return unit
606
+ }
607
+ return pipe(f(next.value), core.flatMap(() => loop))
608
+ })
609
+ return loop
610
+ })
611
+ )
612
+ }
613
+
614
+ return suspend(() =>
615
+ RA.fromIterable(iterable).reduce(
616
+ (acc, curr) =>
617
+ core.zipWith(acc, f(curr), (array, elem) => {
618
+ array.push(elem)
619
+ return array
620
+ }),
621
+ core.succeed([]) as STM.STM<R, E, Array<A2>>
622
+ )
623
+ )
624
+ }
625
+ )
626
+
627
+ /** @internal */
628
+ export const fromEither = <E, A>(either: Either.Either<E, A>): STM.STM<never, E, A> => {
629
+ switch (either._tag) {
630
+ case "Left": {
631
+ return core.fail(either.left)
632
+ }
633
+ case "Right": {
634
+ return core.succeed(either.right)
635
+ }
636
+ }
637
+ }
638
+
639
+ /** @internal */
640
+ export const fromOption = <A>(option: Option.Option<A>): STM.STM<never, Option.Option<never>, A> =>
641
+ Option.match(option, {
642
+ onNone: () => core.fail(Option.none()),
643
+ onSome: core.succeed
644
+ })
645
+
646
+ /** @internal */
647
+ class STMGen {
648
+ constructor(readonly value: STM.STM<any, any, any>) {}
649
+ [Symbol.iterator]() {
650
+ return new SingleShotGen.SingleShotGen(this)
651
+ }
652
+ }
653
+
654
+ const adapter = function() {
655
+ let x = arguments[0]
656
+ for (let i = 1; i < arguments.length; i++) {
657
+ x = arguments[i](x)
658
+ }
659
+ return new STMGen(x) as any
660
+ }
661
+
662
+ /**
663
+ * Inspired by https://github.com/tusharmath/qio/pull/22 (revised)
664
+ * @internal
665
+ */
666
+ export const gen: typeof STM.gen = (f) =>
667
+ suspend(() => {
668
+ const iterator = f(adapter)
669
+ const state = iterator.next()
670
+ const run = (
671
+ state: IteratorYieldResult<any> | IteratorReturnResult<any>
672
+ ): STM.STM<any, any, any> =>
673
+ state.done ?
674
+ core.succeed(state.value) :
675
+ core.flatMap(
676
+ state.value.value as unknown as STM.STM<any, any, any>,
677
+ (val: any) => run(iterator.next(val))
678
+ )
679
+ return run(state)
680
+ })
681
+
682
+ /** @internal */
683
+ export const head = <R, E, A>(self: STM.STM<R, E, Iterable<A>>): STM.STM<R, Option.Option<E>, A> =>
684
+ pipe(
685
+ self,
686
+ core.matchSTM({
687
+ onFailure: (e) => core.fail(Option.some(e)),
688
+ onSuccess: (a) => {
689
+ const i = a[Symbol.iterator]()
690
+ const res = i.next()
691
+ if (res.done) {
692
+ return core.fail(Option.none())
693
+ } else {
694
+ return core.succeed(res.value)
695
+ }
696
+ }
697
+ })
698
+ )
699
+
700
+ /** @internal */
701
+ export const if_ = dual<
702
+ <R1, R2, E1, E2, A, A1>(
703
+ options: {
704
+ readonly onTrue: STM.STM<R1, E1, A>
705
+ readonly onFalse: STM.STM<R2, E2, A1>
706
+ }
707
+ ) => <R = never, E = never>(
708
+ self: STM.STM<R, E, boolean> | boolean
709
+ ) => STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1>,
710
+ {
711
+ <R, E, R1, R2, E1, E2, A, A1>(
712
+ self: boolean,
713
+ options: {
714
+ readonly onTrue: STM.STM<R1, E1, A>
715
+ readonly onFalse: STM.STM<R2, E2, A1>
716
+ }
717
+ ): STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1>
718
+ <R, E, R1, R2, E1, E2, A, A1>(
719
+ self: STM.STM<R, E, boolean>,
720
+ options: {
721
+ readonly onTrue: STM.STM<R1, E1, A>
722
+ readonly onFalse: STM.STM<R2, E2, A1>
723
+ }
724
+ ): STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1>
725
+ }
726
+ >(
727
+ (args) => typeof args[0] === "boolean" || core.isSTM(args[0]),
728
+ <R, E, R1, R2, E1, E2, A, A1>(
729
+ self: STM.STM<R, E, boolean> | boolean,
730
+ { onFalse, onTrue }: {
731
+ readonly onTrue: STM.STM<R1, E1, A>
732
+ readonly onFalse: STM.STM<R2, E2, A1>
733
+ }
734
+ ) => {
735
+ if (typeof self === "boolean") {
736
+ return self ? onTrue : onFalse
737
+ }
738
+
739
+ return core.flatMap(self, (bool): STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1> => bool ? onTrue : onFalse)
740
+ }
741
+ )
742
+
743
+ /** @internal */
744
+ export const ignore = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, void> =>
745
+ match(self, { onFailure: () => unit, onSuccess: () => unit })
746
+
747
+ /** @internal */
748
+ export const isFailure = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, boolean> =>
749
+ match(self, { onFailure: constTrue, onSuccess: constFalse })
750
+
751
+ /** @internal */
752
+ export const isSuccess = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, boolean> =>
753
+ match(self, { onFailure: constFalse, onSuccess: constTrue })
754
+
755
+ /** @internal */
756
+ export const iterate = <R, E, Z>(
757
+ initial: Z,
758
+ options: {
759
+ readonly while: (z: Z) => boolean
760
+ readonly body: (z: Z) => STM.STM<R, E, Z>
761
+ }
762
+ ): STM.STM<R, E, Z> => iterateLoop(initial, options.while, options.body)
763
+
764
+ const iterateLoop = <R, E, Z>(
765
+ initial: Z,
766
+ cont: (z: Z) => boolean,
767
+ body: (z: Z) => STM.STM<R, E, Z>
768
+ ): STM.STM<R, E, Z> => {
769
+ if (cont(initial)) {
770
+ return pipe(
771
+ body(initial),
772
+ core.flatMap((z) => iterateLoop(z, cont, body))
773
+ )
774
+ }
775
+ return core.succeed(initial)
776
+ }
777
+
778
+ /** @internal */
779
+ export const loop: {
780
+ <Z, R, E, A>(
781
+ initial: Z,
782
+ options: {
783
+ readonly while: (z: Z) => boolean
784
+ readonly step: (z: Z) => Z
785
+ readonly body: (z: Z) => STM.STM<R, E, A>
786
+ readonly discard?: false
787
+ }
788
+ ): STM.STM<R, E, Array<A>>
789
+ <Z, R, E, A>(
790
+ initial: Z,
791
+ options: {
792
+ readonly while: (z: Z) => boolean
793
+ readonly step: (z: Z) => Z
794
+ readonly body: (z: Z) => STM.STM<R, E, A>
795
+ readonly discard: true
796
+ }
797
+ ): STM.STM<R, E, void>
798
+ } = <Z, R, E, A>(
799
+ initial: Z,
800
+ options: {
801
+ readonly while: (z: Z) => boolean
802
+ readonly step: (z: Z) => Z
803
+ readonly body: (z: Z) => STM.STM<R, E, A>
804
+ readonly discard?: boolean
805
+ }
806
+ ): STM.STM<R, E, any> =>
807
+ options.discard ?
808
+ loopDiscardLoop(initial, options.while, options.step, options.body) :
809
+ core.map(loopLoop(initial, options.while, options.step, options.body), (a) => Array.from(a))
810
+
811
+ const loopLoop = <Z, R, E, A>(
812
+ initial: Z,
813
+ cont: (z: Z) => boolean,
814
+ inc: (z: Z) => Z,
815
+ body: (z: Z) => STM.STM<R, E, A>
816
+ ): STM.STM<R, E, Chunk.Chunk<A>> => {
817
+ if (cont(initial)) {
818
+ return pipe(
819
+ body(initial),
820
+ core.flatMap((a) => pipe(loopLoop(inc(initial), cont, inc, body), core.map(Chunk.append(a))))
821
+ )
822
+ }
823
+ return core.succeed(Chunk.empty<A>())
824
+ }
825
+
826
+ const loopDiscardLoop = <Z, R, E, X>(
827
+ initial: Z,
828
+ cont: (z: Z) => boolean,
829
+ inc: (z: Z) => Z,
830
+ body: (z: Z) => STM.STM<R, E, X>
831
+ ): STM.STM<R, E, void> => {
832
+ if (cont(initial)) {
833
+ return pipe(
834
+ body(initial),
835
+ core.flatMap(() => loopDiscardLoop(inc(initial), cont, inc, body))
836
+ )
837
+ }
838
+ return unit
839
+ }
840
+
841
+ /** @internal */
842
+ export const mapAttempt = dual<
843
+ <A, B>(f: (a: A) => B) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, unknown, B>,
844
+ <R, E, A, B>(self: STM.STM<R, E, A>, f: (a: A) => B) => STM.STM<R, unknown, B>
845
+ >(2, <R, E, A, B>(self: STM.STM<R, E, A>, f: (a: A) => B): STM.STM<R, unknown, B> =>
846
+ core.matchSTM(self, {
847
+ onFailure: (e) => core.fail(e),
848
+ onSuccess: (a) => attempt(() => f(a))
849
+ }))
850
+
851
+ /** @internal */
852
+ export const mapBoth = dual<
853
+ <E, E2, A, A2>(options: {
854
+ readonly onFailure: (error: E) => E2
855
+ readonly onSuccess: (value: A) => A2
856
+ }) => <R>(self: STM.STM<R, E, A>) => STM.STM<R, E2, A2>,
857
+ <R, E, E2, A, A2>(self: STM.STM<R, E, A>, options: {
858
+ readonly onFailure: (error: E) => E2
859
+ readonly onSuccess: (value: A) => A2
860
+ }) => STM.STM<R, E2, A2>
861
+ >(2, (self, { onFailure, onSuccess }) =>
862
+ core.matchSTM(self, {
863
+ onFailure: (e) => core.fail(onFailure(e)),
864
+ onSuccess: (a) => core.succeed(onSuccess(a))
865
+ }))
866
+
867
+ /** @internal */
868
+ export const mapError = dual<
869
+ <E, E2>(f: (error: E) => E2) => <R, A>(self: STM.STM<R, E, A>) => STM.STM<R, E2, A>,
870
+ <R, A, E, E2>(self: STM.STM<R, E, A>, f: (error: E) => E2) => STM.STM<R, E2, A>
871
+ >(2, (self, f) =>
872
+ core.matchSTM(self, {
873
+ onFailure: (e) => core.fail(f(e)),
874
+ onSuccess: core.succeed
875
+ }))
876
+
877
+ /** @internal */
878
+ export const merge = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, E | A> =>
879
+ core.matchSTM(self, { onFailure: (e) => core.succeed(e), onSuccess: core.succeed })
880
+
881
+ /** @internal */
882
+ export const mergeAll = dual<
883
+ <A2, A>(zero: A2, f: (a2: A2, a: A) => A2) => <R, E>(iterable: Iterable<STM.STM<R, E, A>>) => STM.STM<R, E, A2>,
884
+ <R, E, A2, A>(iterable: Iterable<STM.STM<R, E, A>>, zero: A2, f: (a2: A2, a: A) => A2) => STM.STM<R, E, A2>
885
+ >(
886
+ 3,
887
+ <R, E, A2, A>(iterable: Iterable<STM.STM<R, E, A>>, zero: A2, f: (a2: A2, a: A) => A2): STM.STM<R, E, A2> =>
888
+ suspend(() =>
889
+ Array.from(iterable).reduce(
890
+ (acc, curr) => pipe(acc, core.zipWith(curr, f)),
891
+ core.succeed(zero) as STM.STM<R, E, A2>
892
+ )
893
+ )
894
+ )
895
+
896
+ /** @internal */
897
+ export const negate = <R, E>(self: STM.STM<R, E, boolean>): STM.STM<R, E, boolean> => pipe(self, core.map((b) => !b))
898
+
899
+ /** @internal */
900
+ export const none = <R, E, A>(self: STM.STM<R, E, Option.Option<A>>): STM.STM<R, Option.Option<E>, void> =>
901
+ core.matchSTM(self, {
902
+ onFailure: (e) => core.fail(Option.some(e)),
903
+ onSuccess: Option.match({
904
+ onNone: () => unit,
905
+ onSome: () => core.fail(Option.none())
906
+ })
907
+ })
908
+
909
+ /** @internal */
910
+ export const option = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, Option.Option<A>> =>
911
+ match(self, { onFailure: () => Option.none(), onSuccess: Option.some })
912
+
913
+ /** @internal */
914
+ export const orDie = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, A> => pipe(self, orDieWith(identity))
915
+
916
+ /** @internal */
917
+ export const orDieWith = dual<
918
+ <E>(f: (error: E) => unknown) => <R, A>(self: STM.STM<R, E, A>) => STM.STM<R, never, A>,
919
+ <R, A, E>(self: STM.STM<R, E, A>, f: (error: E) => unknown) => STM.STM<R, never, A>
920
+ >(2, (self, f) => pipe(self, mapError(f), core.catchAll(core.die)))
921
+
922
+ /** @internal */
923
+ export const orElse = dual<
924
+ <R2, E2, A2>(that: LazyArg<STM.STM<R2, E2, A2>>) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<R2 | R, E2, A2 | A>,
925
+ <R, E, A, R2, E2, A2>(self: STM.STM<R, E, A>, that: LazyArg<STM.STM<R2, E2, A2>>) => STM.STM<R2 | R, E2, A2 | A>
926
+ >(
927
+ 2,
928
+ <R, E, A, R2, E2, A2>(self: STM.STM<R, E, A>, that: LazyArg<STM.STM<R2, E2, A2>>): STM.STM<R2 | R, E2, A2 | A> =>
929
+ core.flatMap(core.effect<R, LazyArg<void>>((journal) => Journal.prepareResetJournal(journal)), (reset) =>
930
+ pipe(
931
+ core.orTry(self, () => core.flatMap(core.sync(reset), that)),
932
+ core.catchAll(() => core.flatMap(core.sync(reset), that))
933
+ ))
934
+ )
935
+
936
+ /** @internal */
937
+ export const orElseEither = dual<
938
+ <R2, E2, A2>(
939
+ that: LazyArg<STM.STM<R2, E2, A2>>
940
+ ) => <R, E, A>(
941
+ self: STM.STM<R, E, A>
942
+ ) => STM.STM<R2 | R, E2, Either.Either<A, A2>>,
943
+ <R, E, A, R2, E2, A2>(
944
+ self: STM.STM<R, E, A>,
945
+ that: LazyArg<STM.STM<R2, E2, A2>>
946
+ ) => STM.STM<R2 | R, E2, Either.Either<A, A2>>
947
+ >(
948
+ 2,
949
+ <R, E, A, R2, E2, A2>(
950
+ self: STM.STM<R, E, A>,
951
+ that: LazyArg<STM.STM<R2, E2, A2>>
952
+ ): STM.STM<R2 | R, E2, Either.Either<A, A2>> =>
953
+ orElse(core.map(self, Either.left), () => core.map(that(), Either.right))
954
+ )
955
+
956
+ /** @internal */
957
+ export const orElseFail = dual<
958
+ <E2>(error: LazyArg<E2>) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<R, E2, A>,
959
+ <R, E, A, E2>(self: STM.STM<R, E, A>, error: LazyArg<E2>) => STM.STM<R, E2, A>
960
+ >(
961
+ 2,
962
+ <R, E, A, E2>(self: STM.STM<R, E, A>, error: LazyArg<E2>): STM.STM<R, E2, A> =>
963
+ orElse(self, () => core.failSync(error))
964
+ )
965
+
966
+ /** @internal */
967
+ export const orElseOptional = dual<
968
+ <R2, E2, A2>(
969
+ that: LazyArg<STM.STM<R2, Option.Option<E2>, A2>>
970
+ ) => <R, E, A>(
971
+ self: STM.STM<R, Option.Option<E>, A>
972
+ ) => STM.STM<R2 | R, Option.Option<E2 | E>, A2 | A>,
973
+ <R, E, A, R2, E2, A2>(
974
+ self: STM.STM<R, Option.Option<E>, A>,
975
+ that: LazyArg<STM.STM<R2, Option.Option<E2>, A2>>
976
+ ) => STM.STM<R2 | R, Option.Option<E2 | E>, A2 | A>
977
+ >(
978
+ 2,
979
+ <R, E, A, R2, E2, A2>(
980
+ self: STM.STM<R, Option.Option<E>, A>,
981
+ that: LazyArg<STM.STM<R2, Option.Option<E2>, A2>>
982
+ ): STM.STM<R2 | R, Option.Option<E2 | E>, A2 | A> =>
983
+ core.catchAll(
984
+ self,
985
+ Option.match({
986
+ onNone: that,
987
+ onSome: (e) => core.fail(Option.some<E | E2>(e))
988
+ })
989
+ )
990
+ )
991
+
992
+ /** @internal */
993
+ export const orElseSucceed = dual<
994
+ <A2>(value: LazyArg<A2>) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<R, never, A2 | A>,
995
+ <R, E, A, A2>(self: STM.STM<R, E, A>, value: LazyArg<A2>) => STM.STM<R, never, A2 | A>
996
+ >(
997
+ 2,
998
+ <R, E, A, A2>(self: STM.STM<R, E, A>, value: LazyArg<A2>): STM.STM<R, never, A2 | A> =>
999
+ orElse(self, () => core.sync(value))
1000
+ )
1001
+
1002
+ /** @internal */
1003
+ export const provideContext = dual<
1004
+ <R>(env: Context.Context<R>) => <E, A>(self: STM.STM<R, E, A>) => STM.STM<never, E, A>,
1005
+ <E, A, R>(self: STM.STM<R, E, A>, env: Context.Context<R>) => STM.STM<never, E, A>
1006
+ >(2, (self, env) => core.mapInputContext(self, (_: Context.Context<never>) => env))
1007
+
1008
+ /** @internal */
1009
+ export const provideSomeContext = dual<
1010
+ <R>(context: Context.Context<R>) => <R1, E, A>(self: STM.STM<R1, E, A>) => STM.STM<Exclude<R1, R>, E, A>,
1011
+ <R, R1, E, A>(self: STM.STM<R1, E, A>, context: Context.Context<R>) => STM.STM<Exclude<R1, R>, E, A>
1012
+ >(2, <R, R1, E, A>(
1013
+ self: STM.STM<R1, E, A>,
1014
+ context: Context.Context<R>
1015
+ ): STM.STM<Exclude<R1, R>, E, A> =>
1016
+ core.mapInputContext(
1017
+ self,
1018
+ (parent: Context.Context<Exclude<R1, R>>): Context.Context<R1> => Context.merge(parent, context) as any
1019
+ ))
1020
+
1021
+ /** @internal */
1022
+ export const provideService = dual<
1023
+ <T extends Context.Tag<any, any>>(
1024
+ tag: T,
1025
+ resource: Context.Tag.Service<T>
1026
+ ) => <R, E, A>(
1027
+ self: STM.STM<R, E, A>
1028
+ ) => STM.STM<Exclude<R, Context.Tag.Identifier<T>>, E, A>,
1029
+ <R, E, A, T extends Context.Tag<any, any>>(
1030
+ self: STM.STM<R, E, A>,
1031
+ tag: T,
1032
+ resource: Context.Tag.Service<T>
1033
+ ) => STM.STM<Exclude<R, Context.Tag.Identifier<T>>, E, A>
1034
+ >(3, (self, tag, resource) => provideServiceSTM(self, tag, core.succeed(resource)))
1035
+
1036
+ /** @internal */
1037
+ export const provideServiceSTM = dual<
1038
+ <T extends Context.Tag<any, any>, R1, E1>(
1039
+ tag: T,
1040
+ stm: STM.STM<R1, E1, Context.Tag.Service<T>>
1041
+ ) => <R, E, A>(
1042
+ self: STM.STM<R, E, A>
1043
+ ) => STM.STM<R1 | Exclude<R, Context.Tag.Identifier<T>>, E1 | E, A>,
1044
+ <R, E, A, T extends Context.Tag<any, any>, R1, E1>(
1045
+ self: STM.STM<R, E, A>,
1046
+ tag: T,
1047
+ stm: STM.STM<R1, E1, Context.Tag.Service<T>>
1048
+ ) => STM.STM<R1 | Exclude<R, Context.Tag.Identifier<T>>, E1 | E, A>
1049
+ >(3, <R, E, A, T extends Context.Tag<any, any>, R1, E1>(
1050
+ self: STM.STM<R, E, A>,
1051
+ tag: T,
1052
+ stm: STM.STM<R1, E1, Context.Tag.Service<T>>
1053
+ ): STM.STM<R1 | Exclude<R, Context.Tag.Identifier<T>>, E1 | E, A> =>
1054
+ core.contextWithSTM((env: Context.Context<R1 | Exclude<R, Context.Tag.Identifier<T>>>) =>
1055
+ core.flatMap(
1056
+ stm,
1057
+ (service) =>
1058
+ provideContext(
1059
+ self,
1060
+ Context.add(env, tag, service) as Context.Context<R | R1>
1061
+ )
1062
+ )
1063
+ ))
1064
+
1065
+ /** @internal */
1066
+ export const reduce = dual<
1067
+ <S, A, R, E>(zero: S, f: (s: S, a: A) => STM.STM<R, E, S>) => (iterable: Iterable<A>) => STM.STM<R, E, S>,
1068
+ <S, A, R, E>(iterable: Iterable<A>, zero: S, f: (s: S, a: A) => STM.STM<R, E, S>) => STM.STM<R, E, S>
1069
+ >(
1070
+ 3,
1071
+ <S, A, R, E>(iterable: Iterable<A>, zero: S, f: (s: S, a: A) => STM.STM<R, E, S>): STM.STM<R, E, S> =>
1072
+ suspend(() =>
1073
+ Array.from(iterable).reduce(
1074
+ (acc, curr) => pipe(acc, core.flatMap((s) => f(s, curr))),
1075
+ core.succeed(zero) as STM.STM<R, E, S>
1076
+ )
1077
+ )
1078
+ )
1079
+
1080
+ /** @internal */
1081
+ export const reduceAll = dual<
1082
+ <R2, E2, A>(
1083
+ initial: STM.STM<R2, E2, A>,
1084
+ f: (x: A, y: A) => A
1085
+ ) => <R, E>(
1086
+ iterable: Iterable<STM.STM<R, E, A>>
1087
+ ) => STM.STM<R2 | R, E2 | E, A>,
1088
+ <R, E, R2, E2, A>(
1089
+ iterable: Iterable<STM.STM<R, E, A>>,
1090
+ initial: STM.STM<R2, E2, A>,
1091
+ f: (x: A, y: A) => A
1092
+ ) => STM.STM<R2 | R, E2 | E, A>
1093
+ >(3, <R, E, R2, E2, A>(
1094
+ iterable: Iterable<STM.STM<R, E, A>>,
1095
+ initial: STM.STM<R2, E2, A>,
1096
+ f: (x: A, y: A) => A
1097
+ ): STM.STM<R2 | R, E2 | E, A> =>
1098
+ suspend(() =>
1099
+ Array.from(iterable).reduce(
1100
+ (acc, curr) => pipe(acc, core.zipWith(curr, f)),
1101
+ initial as STM.STM<R | R2, E | E2, A>
1102
+ )
1103
+ ))
1104
+
1105
+ /** @internal */
1106
+ export const reduceRight = dual<
1107
+ <S, A, R, E>(zero: S, f: (s: S, a: A) => STM.STM<R, E, S>) => (iterable: Iterable<A>) => STM.STM<R, E, S>,
1108
+ <S, A, R, E>(iterable: Iterable<A>, zero: S, f: (s: S, a: A) => STM.STM<R, E, S>) => STM.STM<R, E, S>
1109
+ >(
1110
+ 3,
1111
+ <S, A, R, E>(iterable: Iterable<A>, zero: S, f: (s: S, a: A) => STM.STM<R, E, S>): STM.STM<R, E, S> =>
1112
+ suspend(() =>
1113
+ Array.from(iterable).reduceRight(
1114
+ (acc, curr) => pipe(acc, core.flatMap((s) => f(s, curr))),
1115
+ core.succeed(zero) as STM.STM<R, E, S>
1116
+ )
1117
+ )
1118
+ )
1119
+
1120
+ /** @internal */
1121
+ export const refineOrDie = dual<
1122
+ <E, E2>(pf: (error: E) => Option.Option<E2>) => <R, A>(self: STM.STM<R, E, A>) => STM.STM<R, E2, A>,
1123
+ <R, A, E, E2>(self: STM.STM<R, E, A>, pf: (error: E) => Option.Option<E2>) => STM.STM<R, E2, A>
1124
+ >(2, (self, pf) => refineOrDieWith(self, pf, identity))
1125
+
1126
+ /** @internal */
1127
+ export const refineOrDieWith = dual<
1128
+ <E, E2>(
1129
+ pf: (error: E) => Option.Option<E2>,
1130
+ f: (error: E) => unknown
1131
+ ) => <R, A>(
1132
+ self: STM.STM<R, E, A>
1133
+ ) => STM.STM<R, E2, A>,
1134
+ <R, A, E, E2>(
1135
+ self: STM.STM<R, E, A>,
1136
+ pf: (error: E) => Option.Option<E2>,
1137
+ f: (error: E) => unknown
1138
+ ) => STM.STM<R, E2, A>
1139
+ >(3, (self, pf, f) =>
1140
+ core.catchAll(
1141
+ self,
1142
+ (e) =>
1143
+ Option.match(pf(e), {
1144
+ onNone: () => core.die(f(e)),
1145
+ onSome: core.fail
1146
+ })
1147
+ ))
1148
+
1149
+ /** @internal */
1150
+ export const reject = dual<
1151
+ <A, E2>(pf: (a: A) => Option.Option<E2>) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E2 | E, A>,
1152
+ <R, E, A, E2>(self: STM.STM<R, E, A>, pf: (a: A) => Option.Option<E2>) => STM.STM<R, E2 | E, A>
1153
+ >(2, (self, pf) =>
1154
+ rejectSTM(
1155
+ self,
1156
+ (a) => Option.map(pf(a), core.fail)
1157
+ ))
1158
+
1159
+ /** @internal */
1160
+ export const rejectSTM = dual<
1161
+ <A, R2, E2>(
1162
+ pf: (a: A) => Option.Option<STM.STM<R2, E2, E2>>
1163
+ ) => <R, E>(
1164
+ self: STM.STM<R, E, A>
1165
+ ) => STM.STM<R2 | R, E2 | E, A>,
1166
+ <R, E, A, R2, E2>(
1167
+ self: STM.STM<R, E, A>,
1168
+ pf: (a: A) => Option.Option<STM.STM<R2, E2, E2>>
1169
+ ) => STM.STM<R2 | R, E2 | E, A>
1170
+ >(2, (self, pf) =>
1171
+ core.flatMap(self, (a) =>
1172
+ Option.match(pf(a), {
1173
+ onNone: () => core.succeed(a),
1174
+ onSome: core.flatMap(core.fail)
1175
+ })))
1176
+
1177
+ /** @internal */
1178
+ export const repeatUntil = dual<
1179
+ <A>(predicate: Predicate<A>) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, A>,
1180
+ <R, E, A>(self: STM.STM<R, E, A>, predicate: Predicate<A>) => STM.STM<R, E, A>
1181
+ >(2, (self, predicate) => repeatUntilLoop(self, predicate))
1182
+
1183
+ const repeatUntilLoop = <R, E, A>(self: STM.STM<R, E, A>, predicate: Predicate<A>): STM.STM<R, E, A> =>
1184
+ core.flatMap(self, (a) =>
1185
+ predicate(a) ?
1186
+ core.succeed(a) :
1187
+ repeatUntilLoop(self, predicate))
1188
+
1189
+ /** @internal */
1190
+ export const repeatWhile = dual<
1191
+ <A>(predicate: Predicate<A>) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, A>,
1192
+ <R, E, A>(self: STM.STM<R, E, A>, predicate: Predicate<A>) => STM.STM<R, E, A>
1193
+ >(2, (self, predicate) => repeatWhileLoop(self, predicate))
1194
+
1195
+ const repeatWhileLoop = <R, E, A>(self: STM.STM<R, E, A>, predicate: Predicate<A>): STM.STM<R, E, A> =>
1196
+ pipe(
1197
+ core.flatMap(self, (a) =>
1198
+ predicate(a) ?
1199
+ repeatWhileLoop(self, predicate) :
1200
+ core.succeed(a))
1201
+ )
1202
+
1203
+ /** @internal */
1204
+ export const replicate = dual<
1205
+ (n: number) => <R, E, A>(self: STM.STM<R, E, A>) => Array<STM.STM<R, E, A>>,
1206
+ <R, E, A>(self: STM.STM<R, E, A>, n: number) => Array<STM.STM<R, E, A>>
1207
+ >(2, (self, n) => Array.from({ length: n }, () => self))
1208
+
1209
+ /** @internal */
1210
+ export const replicateSTM = dual<
1211
+ (n: number) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<R, E, Array<A>>,
1212
+ <R, E, A>(self: STM.STM<R, E, A>, n: number) => STM.STM<R, E, Array<A>>
1213
+ >(2, (self, n) => all(replicate(self, n)))
1214
+
1215
+ /** @internal */
1216
+ export const replicateSTMDiscard = dual<
1217
+ (n: number) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<R, E, void>,
1218
+ <R, E, A>(self: STM.STM<R, E, A>, n: number) => STM.STM<R, E, void>
1219
+ >(2, (self, n) => all(replicate(self, n), { discard: true }))
1220
+
1221
+ /** @internal */
1222
+ export const retryUntil = dual<
1223
+ {
1224
+ <A, B extends A>(refinement: Refinement<A, B>): <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, B>
1225
+ <A>(predicate: Predicate<A>): <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, A>
1226
+ },
1227
+ {
1228
+ <R, E, A, B extends A>(self: STM.STM<R, E, A>, refinement: Refinement<A, B>): STM.STM<R, E, B>
1229
+ <R, E, A>(self: STM.STM<R, E, A>, predicate: Predicate<A>): STM.STM<R, E, A>
1230
+ }
1231
+ >(
1232
+ 2,
1233
+ <R, E, A>(self: STM.STM<R, E, A>, predicate: Predicate<A>) =>
1234
+ core.matchSTM(self, { onFailure: core.fail, onSuccess: (a) => predicate(a) ? core.succeed(a) : core.retry })
1235
+ )
1236
+
1237
+ /** @internal */
1238
+ export const retryWhile = dual<
1239
+ <A>(predicate: Predicate<A>) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E, A>,
1240
+ <R, E, A>(self: STM.STM<R, E, A>, predicate: Predicate<A>) => STM.STM<R, E, A>
1241
+ >(
1242
+ 2,
1243
+ (self, predicate) =>
1244
+ core.matchSTM(self, { onFailure: core.fail, onSuccess: (a) => !predicate(a) ? core.succeed(a) : core.retry })
1245
+ )
1246
+
1247
+ /** @internal */
1248
+ export const partition = dual<
1249
+ <R, E, A, A2>(
1250
+ f: (a: A) => STM.STM<R, E, A2>
1251
+ ) => (
1252
+ elements: Iterable<A>
1253
+ ) => STM.STM<R, never, readonly [Array<E>, Array<A2>]>,
1254
+ <R, E, A, A2>(
1255
+ elements: Iterable<A>,
1256
+ f: (a: A) => STM.STM<R, E, A2>
1257
+ ) => STM.STM<R, never, readonly [Array<E>, Array<A2>]>
1258
+ >(2, (elements, f) =>
1259
+ pipe(
1260
+ forEach(elements, (a) => either(f(a))),
1261
+ core.map((as) => effectCore.partitionMap(as, identity))
1262
+ ))
1263
+
1264
+ /** @internal */
1265
+ export const some = <R, E, A>(self: STM.STM<R, E, Option.Option<A>>): STM.STM<R, Option.Option<E>, A> =>
1266
+ core.matchSTM(self, {
1267
+ onFailure: (e) => core.fail(Option.some(e)),
1268
+ onSuccess: Option.match({
1269
+ onNone: () => core.fail(Option.none()),
1270
+ onSome: core.succeed
1271
+ })
1272
+ })
1273
+
1274
+ /* @internal */
1275
+ export const all = ((
1276
+ input: Iterable<STM.All.STMAny> | Record<string, STM.All.STMAny>,
1277
+ options?: STM.All.Options
1278
+ ): STM.STM<any, any, any> => {
1279
+ if (Symbol.iterator in input) {
1280
+ return forEach(input, identity, options as any)
1281
+ } else if (options?.discard) {
1282
+ return forEach(Object.values(input), identity, options as any)
1283
+ }
1284
+
1285
+ return core.map(
1286
+ forEach(
1287
+ Object.entries(input),
1288
+ ([_, e]) => core.map(e, (a) => [_, a] as const)
1289
+ ),
1290
+ (values) => {
1291
+ const res = {}
1292
+ for (const [k, v] of values) {
1293
+ ;(res as any)[k] = v
1294
+ }
1295
+ return res
1296
+ }
1297
+ )
1298
+ }) as STM.All.Signature
1299
+
1300
+ /** @internal */
1301
+ export const succeedNone: STM.STM<never, never, Option.Option<never>> = core.succeed(Option.none())
1302
+
1303
+ /** @internal */
1304
+ export const succeedSome = <A>(value: A): STM.STM<never, never, Option.Option<A>> => core.succeed(Option.some(value))
1305
+
1306
+ /** @internal */
1307
+ export const summarized = dual<
1308
+ <R2, E2, A2, A3>(
1309
+ summary: STM.STM<R2, E2, A2>,
1310
+ f: (before: A2, after: A2) => A3
1311
+ ) => <R, E, A>(
1312
+ self: STM.STM<R, E, A>
1313
+ ) => STM.STM<R2 | R, E2 | E, readonly [A3, A]>,
1314
+ <R, E, A, R2, E2, A2, A3>(
1315
+ self: STM.STM<R, E, A>,
1316
+ summary: STM.STM<R2, E2, A2>,
1317
+ f: (before: A2, after: A2) => A3
1318
+ ) => STM.STM<R2 | R, E2 | E, readonly [A3, A]>
1319
+ >(3, (self, summary, f) =>
1320
+ core.flatMap(summary, (start) =>
1321
+ core.flatMap(self, (value) =>
1322
+ core.map(
1323
+ summary,
1324
+ (end) => [f(start, end), value] as const
1325
+ ))))
1326
+
1327
+ /** @internal */
1328
+ export const suspend = <R, E, A>(evaluate: LazyArg<STM.STM<R, E, A>>): STM.STM<R, E, A> => flatten(core.sync(evaluate))
1329
+
1330
+ /** @internal */
1331
+ export const tap = dual<
1332
+ <A, X extends A, R2, E2, _>(
1333
+ f: (a: X) => STM.STM<R2, E2, _>
1334
+ ) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R2 | R, E2 | E, A>,
1335
+ <R, E, A, X extends A, R2, E2, _>(
1336
+ self: STM.STM<R, E, A>,
1337
+ f: (a: X) => STM.STM<R2, E2, _>
1338
+ ) => STM.STM<R2 | R, E2 | E, A>
1339
+ >(2, (self, f) => core.flatMap(self, (a) => as(f(a as any), a)))
1340
+
1341
+ /** @internal */
1342
+ export const tapBoth = dual<
1343
+ <E, XE extends E, R2, E2, A2, A, XA extends A, R3, E3, A3>(
1344
+ options: {
1345
+ readonly onFailure: (error: XE) => STM.STM<R2, E2, A2>
1346
+ readonly onSuccess: (value: XA) => STM.STM<R3, E3, A3>
1347
+ }
1348
+ ) => <R>(
1349
+ self: STM.STM<R, E, A>
1350
+ ) => STM.STM<R2 | R3 | R, E | E2 | E3, A>,
1351
+ <R, E, XE extends E, R2, E2, A2, A, XA extends A, R3, E3, A3>(
1352
+ self: STM.STM<R, E, A>,
1353
+ options: {
1354
+ readonly onFailure: (error: XE) => STM.STM<R2, E2, A2>
1355
+ readonly onSuccess: (value: XA) => STM.STM<R3, E3, A3>
1356
+ }
1357
+ ) => STM.STM<R2 | R3 | R, E | E2 | E3, A>
1358
+ >(2, (self, { onFailure, onSuccess }) =>
1359
+ core.matchSTM(self, {
1360
+ onFailure: (e) => pipe(onFailure(e as any), core.zipRight(core.fail(e))),
1361
+ onSuccess: (a) => pipe(onSuccess(a as any), as(a))
1362
+ }))
1363
+
1364
+ /** @internal */
1365
+ export const tapError = dual<
1366
+ <E, X extends E, R2, E2, _>(
1367
+ f: (error: X) => STM.STM<R2, E2, _>
1368
+ ) => <R, A>(self: STM.STM<R, E, A>) => STM.STM<R2 | R, E | E2, A>,
1369
+ <R, A, E, X extends E, R2, E2, _>(
1370
+ self: STM.STM<R, E, A>,
1371
+ f: (error: X) => STM.STM<R2, E2, _>
1372
+ ) => STM.STM<R2 | R, E | E2, A>
1373
+ >(2, (self, f) =>
1374
+ core.matchSTM(self, {
1375
+ onFailure: (e) => core.zipRight(f(e as any), core.fail(e)),
1376
+ onSuccess: core.succeed
1377
+ }))
1378
+
1379
+ /** @internal */
1380
+ export const try_: {
1381
+ <A, E>(options: {
1382
+ readonly try: LazyArg<A>
1383
+ readonly catch: (u: unknown) => E
1384
+ }): STM.STM<never, E, A>
1385
+ <A>(try_: LazyArg<A>): STM.STM<never, unknown, A>
1386
+ } = <A, E>(
1387
+ arg: LazyArg<A> | {
1388
+ readonly try: LazyArg<A>
1389
+ readonly catch: (u: unknown) => E
1390
+ }
1391
+ ) => {
1392
+ const evaluate = typeof arg === "function" ? arg : arg.try
1393
+ return suspend(() => {
1394
+ try {
1395
+ return core.succeed(evaluate())
1396
+ } catch (error) {
1397
+ return core.fail("catch" in arg ? arg.catch(error) : error)
1398
+ }
1399
+ })
1400
+ }
1401
+
1402
+ /** @internal */
1403
+ export const unit: STM.STM<never, never, void> = core.succeed(void 0)
1404
+
1405
+ /** @internal */
1406
+ export const unless = dual<
1407
+ (predicate: LazyArg<boolean>) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<R, E, Option.Option<A>>,
1408
+ <R, E, A>(self: STM.STM<R, E, A>, predicate: LazyArg<boolean>) => STM.STM<R, E, Option.Option<A>>
1409
+ >(2, (self, predicate) =>
1410
+ suspend(
1411
+ () => predicate() ? succeedNone : asSome(self)
1412
+ ))
1413
+
1414
+ /** @internal */
1415
+ export const unlessSTM = dual<
1416
+ <R2, E2>(
1417
+ predicate: STM.STM<R2, E2, boolean>
1418
+ ) => <R, E, A>(
1419
+ self: STM.STM<R, E, A>
1420
+ ) => STM.STM<R2 | R, E2 | E, Option.Option<A>>,
1421
+ <R, E, A, R2, E2>(
1422
+ self: STM.STM<R, E, A>,
1423
+ predicate: STM.STM<R2, E2, boolean>
1424
+ ) => STM.STM<R2 | R, E2 | E, Option.Option<A>>
1425
+ >(2, (self, predicate) =>
1426
+ core.flatMap(
1427
+ predicate,
1428
+ (bool) => bool ? succeedNone : asSome(self)
1429
+ ))
1430
+
1431
+ /** @internal */
1432
+ export const unsome = <R, E, A>(self: STM.STM<R, Option.Option<E>, A>): STM.STM<R, E, Option.Option<A>> =>
1433
+ core.matchSTM(self, {
1434
+ onFailure: Option.match({
1435
+ onNone: () => core.succeed(Option.none()),
1436
+ onSome: core.fail
1437
+ }),
1438
+ onSuccess: (a) => core.succeed(Option.some(a))
1439
+ })
1440
+
1441
+ /** @internal */
1442
+ export const validateAll = dual<
1443
+ <R, E, A, B>(
1444
+ f: (a: A) => STM.STM<R, E, B>
1445
+ ) => (
1446
+ elements: Iterable<A>
1447
+ ) => STM.STM<R, RA.NonEmptyArray<E>, Array<B>>,
1448
+ <R, E, A, B>(
1449
+ elements: Iterable<A>,
1450
+ f: (a: A) => STM.STM<R, E, B>
1451
+ ) => STM.STM<R, RA.NonEmptyArray<E>, Array<B>>
1452
+ >(
1453
+ 2,
1454
+ (elements, f) =>
1455
+ core.flatMap(partition(elements, f), ([errors, values]) =>
1456
+ RA.isNonEmptyArray(errors) ?
1457
+ core.fail(errors) :
1458
+ core.succeed(values))
1459
+ )
1460
+
1461
+ /** @internal */
1462
+ export const validateFirst = dual<
1463
+ <R, E, A, B>(f: (a: A) => STM.STM<R, E, B>) => (elements: Iterable<A>) => STM.STM<R, Array<E>, B>,
1464
+ <R, E, A, B>(elements: Iterable<A>, f: (a: A) => STM.STM<R, E, B>) => STM.STM<R, Array<E>, B>
1465
+ >(2, (elements, f) => flip(forEach(elements, (a) => flip(f(a)))))
1466
+
1467
+ /** @internal */
1468
+ export const when = dual<
1469
+ (predicate: LazyArg<boolean>) => <R, E, A>(self: STM.STM<R, E, A>) => STM.STM<R, E, Option.Option<A>>,
1470
+ <R, E, A>(self: STM.STM<R, E, A>, predicate: LazyArg<boolean>) => STM.STM<R, E, Option.Option<A>>
1471
+ >(2, (self, predicate) =>
1472
+ suspend(
1473
+ () => predicate() ? asSome(self) : succeedNone
1474
+ ))
1475
+
1476
+ /** @internal */
1477
+ export const whenSTM = dual<
1478
+ <R2, E2>(
1479
+ predicate: STM.STM<R2, E2, boolean>
1480
+ ) => <R, E, A>(
1481
+ self: STM.STM<R, E, A>
1482
+ ) => STM.STM<R2 | R, E2 | E, Option.Option<A>>,
1483
+ <R, E, A, R2, E2>(
1484
+ self: STM.STM<R, E, A>,
1485
+ predicate: STM.STM<R2, E2, boolean>
1486
+ ) => STM.STM<R2 | R, E2 | E, Option.Option<A>>
1487
+ >(2, (self, predicate) =>
1488
+ core.flatMap(
1489
+ predicate,
1490
+ (bool) => bool ? asSome(self) : succeedNone
1491
+ ))