@fncts/io 0.0.47 → 0.0.49

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 (685) hide show
  1. package/Cached/api.d.ts +1 -1
  2. package/Channel/api.d.ts +80 -80
  3. package/Channel/core-api.d.ts +26 -26
  4. package/Console/definition.d.ts +1 -0
  5. package/CountdownLatch.d.ts +1 -0
  6. package/Fiber/FiberMessage.d.ts +6 -28
  7. package/Fiber/FiberRuntime.d.ts +108 -77
  8. package/Fiber/api/interruptAs.d.ts +2 -2
  9. package/Fiber/definition.d.ts +2 -0
  10. package/FiberScope/definition.d.ts +3 -0
  11. package/FiberSet.d.ts +2 -1
  12. package/Future/State.d.ts +59 -0
  13. package/Future/api.d.ts +8 -3
  14. package/Future/constructors.d.ts +1 -1
  15. package/Future/definition.d.ts +1 -17
  16. package/Future.d.ts +1 -0
  17. package/Hub/api.d.ts +15 -15
  18. package/IO/api/array.d.ts +22 -0
  19. package/IO/api/awaitAllChildren.d.ts +6 -0
  20. package/IO/api/cachedInvalidate.d.ts +15 -0
  21. package/IO/api/forkDaemon.d.ts +1 -1
  22. package/IO/api/onTermination.d.ts +1 -2
  23. package/IO/api/transplant.d.ts +11 -1
  24. package/IO/api.d.ts +247 -225
  25. package/IO/definition.d.ts +12 -25
  26. package/IO.d.ts +3 -1
  27. package/Random/definition.d.ts +1 -0
  28. package/Ref/Synchronized/api.d.ts +1 -1
  29. package/Semaphore/Reservation.d.ts +15 -0
  30. package/Semaphore/constructors.d.ts +13 -0
  31. package/Semaphore/definition.d.ts +29 -0
  32. package/Semaphore.d.ts +3 -40
  33. package/Stream/api.d.ts +164 -164
  34. package/_cjs/Cached/api.cjs +1 -2
  35. package/_cjs/Cached/api.cjs.map +1 -1
  36. package/_cjs/Cached/internal.cjs +1 -2
  37. package/_cjs/Cached/internal.cjs.map +1 -1
  38. package/_cjs/Channel/api/interruptWhen.cjs +1 -2
  39. package/_cjs/Channel/api/interruptWhen.cjs.map +1 -1
  40. package/_cjs/Channel/api/mapOutConcurrentIO.cjs +2 -3
  41. package/_cjs/Channel/api/mapOutConcurrentIO.cjs.map +1 -1
  42. package/_cjs/Channel/api/mergeAll.cjs +1 -2
  43. package/_cjs/Channel/api/mergeAll.cjs.map +1 -1
  44. package/_cjs/Channel/api/mergeAllUnboundedWith.cjs +1 -2
  45. package/_cjs/Channel/api/mergeAllUnboundedWith.cjs.map +1 -1
  46. package/_cjs/Channel/api/mergeAllWith.cjs +2 -3
  47. package/_cjs/Channel/api/mergeAllWith.cjs.map +1 -1
  48. package/_cjs/Channel/api/mergeMap.cjs +1 -2
  49. package/_cjs/Channel/api/mergeMap.cjs.map +1 -1
  50. package/_cjs/Channel/api/mergeWith.cjs +1 -2
  51. package/_cjs/Channel/api/mergeWith.cjs.map +1 -1
  52. package/_cjs/Channel/api/run.cjs +1 -2
  53. package/_cjs/Channel/api/run.cjs.map +1 -1
  54. package/_cjs/Channel/api/runCollect.cjs +1 -2
  55. package/_cjs/Channel/api/runCollect.cjs.map +1 -1
  56. package/_cjs/Channel/api/runDrain.cjs +1 -2
  57. package/_cjs/Channel/api/runDrain.cjs.map +1 -1
  58. package/_cjs/Channel/api/runScoped.cjs +3 -4
  59. package/_cjs/Channel/api/runScoped.cjs.map +1 -1
  60. package/_cjs/Channel/api/toPull.cjs +2 -3
  61. package/_cjs/Channel/api/toPull.cjs.map +1 -1
  62. package/_cjs/Channel/api/zipConcurrent.cjs +1 -2
  63. package/_cjs/Channel/api/zipConcurrent.cjs.map +1 -1
  64. package/_cjs/Channel/api.cjs +206 -207
  65. package/_cjs/Channel/api.cjs.map +1 -1
  66. package/_cjs/Channel/core-api.cjs +43 -42
  67. package/_cjs/Channel/core-api.cjs.map +1 -1
  68. package/_cjs/Channel/internal/AsyncInputConsumer.cjs +0 -4
  69. package/_cjs/Channel/internal/AsyncInputProducer.cjs +0 -4
  70. package/_cjs/Channel/internal/ChannelExecutor.cjs +4 -5
  71. package/_cjs/Channel/internal/ChannelExecutor.cjs.map +1 -1
  72. package/_cjs/Channel/internal/ChannelState.cjs +1 -2
  73. package/_cjs/Channel/internal/ChannelState.cjs.map +1 -1
  74. package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs +1 -2
  75. package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs.map +1 -1
  76. package/_cjs/Clock/api.cjs +1 -2
  77. package/_cjs/Clock/api.cjs.map +1 -1
  78. package/_cjs/Clock/definition.cjs +1 -2
  79. package/_cjs/Clock/definition.cjs.map +1 -1
  80. package/_cjs/Clock/live.cjs +1 -2
  81. package/_cjs/Clock/live.cjs.map +1 -1
  82. package/_cjs/Console/api.cjs +1 -2
  83. package/_cjs/Console/api.cjs.map +1 -1
  84. package/_cjs/Console/definition.cjs +2 -2
  85. package/_cjs/Console/definition.cjs.map +1 -1
  86. package/_cjs/Console/live.cjs +1 -2
  87. package/_cjs/Console/live.cjs.map +1 -1
  88. package/_cjs/CountdownLatch.cjs +3 -3
  89. package/_cjs/CountdownLatch.cjs.map +1 -1
  90. package/_cjs/Differ/api.cjs +1 -2
  91. package/_cjs/Differ/api.cjs.map +1 -1
  92. package/_cjs/Fiber/FiberMessage.cjs +3 -24
  93. package/_cjs/Fiber/FiberMessage.cjs.map +1 -1
  94. package/_cjs/Fiber/FiberRuntime.cjs +879 -636
  95. package/_cjs/Fiber/FiberRuntime.cjs.map +1 -1
  96. package/_cjs/Fiber/api/awaitAll.cjs +1 -2
  97. package/_cjs/Fiber/api/awaitAll.cjs.map +1 -1
  98. package/_cjs/Fiber/api/collectAll.cjs +2 -3
  99. package/_cjs/Fiber/api/collectAll.cjs.map +1 -1
  100. package/_cjs/Fiber/api/fromIO.cjs +1 -2
  101. package/_cjs/Fiber/api/fromIO.cjs.map +1 -1
  102. package/_cjs/Fiber/api/interrupt.cjs +2 -3
  103. package/_cjs/Fiber/api/interrupt.cjs.map +1 -1
  104. package/_cjs/Fiber/api/interruptAll.cjs +2 -3
  105. package/_cjs/Fiber/api/interruptAll.cjs.map +1 -1
  106. package/_cjs/Fiber/api/interruptAs.cjs +5 -10
  107. package/_cjs/Fiber/api/interruptAs.cjs.map +1 -1
  108. package/_cjs/Fiber/api/interruptFork.cjs +2 -3
  109. package/_cjs/Fiber/api/interruptFork.cjs.map +1 -1
  110. package/_cjs/Fiber/api/join.cjs +1 -2
  111. package/_cjs/Fiber/api/join.cjs.map +1 -1
  112. package/_cjs/Fiber/api/joinAll.cjs +1 -2
  113. package/_cjs/Fiber/api/joinAll.cjs.map +1 -1
  114. package/_cjs/Fiber/api/mapFiber.cjs +1 -2
  115. package/_cjs/Fiber/api/mapFiber.cjs.map +1 -1
  116. package/_cjs/Fiber/api/mapIO.cjs +2 -3
  117. package/_cjs/Fiber/api/mapIO.cjs.map +1 -1
  118. package/_cjs/Fiber/api/zipWith.cjs +2 -3
  119. package/_cjs/Fiber/api/zipWith.cjs.map +1 -1
  120. package/_cjs/Fiber/constructors.cjs +2 -3
  121. package/_cjs/Fiber/constructors.cjs.map +1 -1
  122. package/_cjs/Fiber/definition.cjs +6 -4
  123. package/_cjs/Fiber/definition.cjs.map +1 -1
  124. package/_cjs/FiberRef/api/locallyScoped.cjs +1 -2
  125. package/_cjs/FiberRef/api/locallyScoped.cjs.map +1 -1
  126. package/_cjs/FiberRef/api/locallyScopedWith.cjs +1 -2
  127. package/_cjs/FiberRef/api/locallyScopedWith.cjs.map +1 -1
  128. package/_cjs/FiberRef/constructors.cjs +1 -2
  129. package/_cjs/FiberRef/constructors.cjs.map +1 -1
  130. package/_cjs/FiberRef/definition.cjs +1 -2
  131. package/_cjs/FiberRef/definition.cjs.map +1 -1
  132. package/_cjs/FiberRef/operations.cjs +1 -2
  133. package/_cjs/FiberRef/operations.cjs.map +1 -1
  134. package/_cjs/FiberRef/unsafe.cjs +1 -2
  135. package/_cjs/FiberRef/unsafe.cjs.map +1 -1
  136. package/_cjs/FiberRefs/Patch.cjs +1 -2
  137. package/_cjs/FiberRefs/Patch.cjs.map +1 -1
  138. package/_cjs/FiberRefs/api.cjs +1 -2
  139. package/_cjs/FiberRefs/api.cjs.map +1 -1
  140. package/_cjs/FiberRefs/definition.cjs +1 -2
  141. package/_cjs/FiberRefs/definition.cjs.map +1 -1
  142. package/_cjs/FiberScope/definition.cjs +29 -6
  143. package/_cjs/FiberScope/definition.cjs.map +1 -1
  144. package/_cjs/FiberSet.cjs +16 -15
  145. package/_cjs/FiberSet.cjs.map +1 -1
  146. package/_cjs/FiberStatus/definition.cjs +1 -2
  147. package/_cjs/FiberStatus/definition.cjs.map +1 -1
  148. package/_cjs/Future/State.cjs +108 -0
  149. package/_cjs/Future/State.cjs.map +1 -0
  150. package/_cjs/Future/api.cjs +71 -64
  151. package/_cjs/Future/api.cjs.map +1 -1
  152. package/_cjs/Future/constructors.cjs +3 -4
  153. package/_cjs/Future/constructors.cjs.map +1 -1
  154. package/_cjs/Future/definition.cjs +1 -15
  155. package/_cjs/Future/definition.cjs.map +1 -1
  156. package/_cjs/Future.cjs +11 -0
  157. package/_cjs/Future.cjs.map +1 -1
  158. package/_cjs/Hub/api.cjs +56 -57
  159. package/_cjs/Hub/api.cjs.map +1 -1
  160. package/_cjs/Hub/internal.cjs +1 -2
  161. package/_cjs/Hub/internal.cjs.map +1 -1
  162. package/_cjs/IO/api/acquireRelease.cjs +1 -2
  163. package/_cjs/IO/api/acquireRelease.cjs.map +1 -1
  164. package/_cjs/IO/api/acquireReleaseExit.cjs +1 -2
  165. package/_cjs/IO/api/acquireReleaseExit.cjs.map +1 -1
  166. package/_cjs/IO/api/acquireReleaseInterruptible.cjs +1 -2
  167. package/_cjs/IO/api/acquireReleaseInterruptible.cjs.map +1 -1
  168. package/_cjs/IO/api/acquireReleaseInterruptibleExit.cjs +1 -2
  169. package/_cjs/IO/api/acquireReleaseInterruptibleExit.cjs.map +1 -1
  170. package/_cjs/IO/api/addFinalizer.cjs +1 -2
  171. package/_cjs/IO/api/addFinalizer.cjs.map +1 -1
  172. package/_cjs/IO/api/addFinalizerExit.cjs +1 -2
  173. package/_cjs/IO/api/addFinalizerExit.cjs.map +1 -1
  174. package/_cjs/IO/api/all.cjs +1 -2
  175. package/_cjs/IO/api/all.cjs.map +1 -1
  176. package/_cjs/IO/api/array.cjs +51 -0
  177. package/_cjs/IO/api/array.cjs.map +1 -0
  178. package/_cjs/IO/api/asyncIO.cjs +1 -2
  179. package/_cjs/IO/api/asyncIO.cjs.map +1 -1
  180. package/_cjs/IO/api/asyncInterrupt.cjs +1 -2
  181. package/_cjs/IO/api/asyncInterrupt.cjs.map +1 -1
  182. package/_cjs/IO/api/awaitAllChildren.cjs +17 -0
  183. package/_cjs/IO/api/awaitAllChildren.cjs.map +1 -0
  184. package/_cjs/IO/api/blocking.cjs +1 -2
  185. package/_cjs/IO/api/blocking.cjs.map +1 -1
  186. package/_cjs/IO/api/bracket.cjs +1 -2
  187. package/_cjs/IO/api/bracket.cjs.map +1 -1
  188. package/_cjs/IO/api/bracketExit.cjs +1 -2
  189. package/_cjs/IO/api/bracketExit.cjs.map +1 -1
  190. package/_cjs/IO/api/cachedInvalidate.cjs +47 -0
  191. package/_cjs/IO/api/cachedInvalidate.cjs.map +1 -0
  192. package/_cjs/IO/api/clockWith.cjs +1 -2
  193. package/_cjs/IO/api/clockWith.cjs.map +1 -1
  194. package/_cjs/IO/api/concurrency.cjs +1 -2
  195. package/_cjs/IO/api/concurrency.cjs.map +1 -1
  196. package/_cjs/IO/api/concurrentFinalizers.cjs +1 -2
  197. package/_cjs/IO/api/concurrentFinalizers.cjs.map +1 -1
  198. package/_cjs/IO/api/consoleWith.cjs +1 -2
  199. package/_cjs/IO/api/consoleWith.cjs.map +1 -1
  200. package/_cjs/IO/api/daemonChildren.cjs +1 -2
  201. package/_cjs/IO/api/daemonChildren.cjs.map +1 -1
  202. package/_cjs/IO/api/delay.cjs +1 -2
  203. package/_cjs/IO/api/delay.cjs.map +1 -1
  204. package/_cjs/IO/api/descriptor.cjs +1 -2
  205. package/_cjs/IO/api/descriptor.cjs.map +1 -1
  206. package/_cjs/IO/api/diffFiberRefs.cjs +1 -2
  207. package/_cjs/IO/api/diffFiberRefs.cjs.map +1 -1
  208. package/_cjs/IO/api/disconnect.cjs +2 -3
  209. package/_cjs/IO/api/disconnect.cjs.map +1 -1
  210. package/_cjs/IO/api/ensuringChildren.cjs +1 -2
  211. package/_cjs/IO/api/ensuringChildren.cjs.map +1 -1
  212. package/_cjs/IO/api/environment.cjs +1 -2
  213. package/_cjs/IO/api/environment.cjs.map +1 -1
  214. package/_cjs/IO/api/foreachConcurrent.cjs +36 -30
  215. package/_cjs/IO/api/foreachConcurrent.cjs.map +1 -1
  216. package/_cjs/IO/api/foreachExec.cjs +1 -2
  217. package/_cjs/IO/api/foreachExec.cjs.map +1 -1
  218. package/_cjs/IO/api/fork.cjs +2 -3
  219. package/_cjs/IO/api/fork.cjs.map +1 -1
  220. package/_cjs/IO/api/forkAll.cjs +1 -2
  221. package/_cjs/IO/api/forkAll.cjs.map +1 -1
  222. package/_cjs/IO/api/forkDaemon.cjs +5 -6
  223. package/_cjs/IO/api/forkDaemon.cjs.map +1 -1
  224. package/_cjs/IO/api/forkIn.cjs +1 -2
  225. package/_cjs/IO/api/forkIn.cjs.map +1 -1
  226. package/_cjs/IO/api/forkScoped.cjs +1 -2
  227. package/_cjs/IO/api/forkScoped.cjs.map +1 -1
  228. package/_cjs/IO/api/fulfill.cjs +1 -2
  229. package/_cjs/IO/api/fulfill.cjs.map +1 -1
  230. package/_cjs/IO/api/interrupt.cjs +4 -5
  231. package/_cjs/IO/api/interrupt.cjs.map +1 -1
  232. package/_cjs/IO/api/memoize.cjs +1 -2
  233. package/_cjs/IO/api/memoize.cjs.map +1 -1
  234. package/_cjs/IO/api/onTermination.cjs +2 -3
  235. package/_cjs/IO/api/onTermination.cjs.map +1 -1
  236. package/_cjs/IO/api/once.cjs +1 -2
  237. package/_cjs/IO/api/once.cjs.map +1 -1
  238. package/_cjs/IO/api/patchFiberRefs.cjs +1 -2
  239. package/_cjs/IO/api/patchFiberRefs.cjs.map +1 -1
  240. package/_cjs/IO/api/provideLayer.cjs +1 -2
  241. package/_cjs/IO/api/provideLayer.cjs.map +1 -1
  242. package/_cjs/IO/api/provideScope.cjs +1 -2
  243. package/_cjs/IO/api/provideScope.cjs.map +1 -1
  244. package/_cjs/IO/api/provideSomeLayer.cjs +1 -2
  245. package/_cjs/IO/api/provideSomeLayer.cjs.map +1 -1
  246. package/_cjs/IO/api/provideSomeRuntime.cjs +1 -2
  247. package/_cjs/IO/api/provideSomeRuntime.cjs.map +1 -1
  248. package/_cjs/IO/api/race.cjs +2 -3
  249. package/_cjs/IO/api/race.cjs.map +1 -1
  250. package/_cjs/IO/api/raceFirst.cjs +1 -2
  251. package/_cjs/IO/api/raceFirst.cjs.map +1 -1
  252. package/_cjs/IO/api/raceWith.cjs +1 -2
  253. package/_cjs/IO/api/raceWith.cjs.map +1 -1
  254. package/_cjs/IO/api/randomWith.cjs +1 -2
  255. package/_cjs/IO/api/randomWith.cjs.map +1 -1
  256. package/_cjs/IO/api/repeat.cjs +1 -2
  257. package/_cjs/IO/api/repeat.cjs.map +1 -1
  258. package/_cjs/IO/api/retry.cjs +1 -2
  259. package/_cjs/IO/api/retry.cjs.map +1 -1
  260. package/_cjs/IO/api/schedule.cjs +1 -2
  261. package/_cjs/IO/api/schedule.cjs.map +1 -1
  262. package/_cjs/IO/api/scope.cjs +1 -2
  263. package/_cjs/IO/api/scope.cjs.map +1 -1
  264. package/_cjs/IO/api/scopeWith.cjs +1 -2
  265. package/_cjs/IO/api/scopeWith.cjs.map +1 -1
  266. package/_cjs/IO/api/scoped.cjs +1 -2
  267. package/_cjs/IO/api/scoped.cjs.map +1 -1
  268. package/_cjs/IO/api/sleep.cjs +1 -2
  269. package/_cjs/IO/api/sleep.cjs.map +1 -1
  270. package/_cjs/IO/api/stateful.cjs +1 -2
  271. package/_cjs/IO/api/stateful.cjs.map +1 -1
  272. package/_cjs/IO/api/supervised.cjs +1 -2
  273. package/_cjs/IO/api/supervised.cjs.map +1 -1
  274. package/_cjs/IO/api/timeout.cjs +9 -11
  275. package/_cjs/IO/api/timeout.cjs.map +1 -1
  276. package/_cjs/IO/api/transplant.cjs +22 -7
  277. package/_cjs/IO/api/transplant.cjs.map +1 -1
  278. package/_cjs/IO/api/whenFiberRef.cjs +1 -2
  279. package/_cjs/IO/api/whenFiberRef.cjs.map +1 -1
  280. package/_cjs/IO/api/whenRef.cjs +1 -2
  281. package/_cjs/IO/api/whenRef.cjs.map +1 -1
  282. package/_cjs/IO/api/withChildren.cjs +1 -2
  283. package/_cjs/IO/api/withChildren.cjs.map +1 -1
  284. package/_cjs/IO/api/withEarlyRelease.cjs +1 -2
  285. package/_cjs/IO/api/withEarlyRelease.cjs.map +1 -1
  286. package/_cjs/IO/api/withFinalizer.cjs +1 -2
  287. package/_cjs/IO/api/withFinalizer.cjs.map +1 -1
  288. package/_cjs/IO/api/withFinalizerExit.cjs +1 -2
  289. package/_cjs/IO/api/withFinalizerExit.cjs.map +1 -1
  290. package/_cjs/IO/api/zipConcurrent.cjs +5 -6
  291. package/_cjs/IO/api/zipConcurrent.cjs.map +1 -1
  292. package/_cjs/IO/api.cjs +522 -473
  293. package/_cjs/IO/api.cjs.map +1 -1
  294. package/_cjs/IO/definition.cjs +2 -3
  295. package/_cjs/IO/definition.cjs.map +1 -1
  296. package/_cjs/IO/runtime.cjs +9 -10
  297. package/_cjs/IO/runtime.cjs.map +1 -1
  298. package/_cjs/IO.cjs +33 -11
  299. package/_cjs/IO.cjs.map +1 -1
  300. package/_cjs/IOEnv/definition.cjs +1 -2
  301. package/_cjs/IOEnv/definition.cjs.map +1 -1
  302. package/_cjs/IOEnv/live.cjs +1 -2
  303. package/_cjs/IOEnv/live.cjs.map +1 -1
  304. package/_cjs/IOEnv/services.cjs +1 -2
  305. package/_cjs/IOEnv/services.cjs.map +1 -1
  306. package/_cjs/Layer/MemoMap.cjs +1 -2
  307. package/_cjs/Layer/MemoMap.cjs.map +1 -1
  308. package/_cjs/Layer/api.cjs +1 -2
  309. package/_cjs/Layer/api.cjs.map +1 -1
  310. package/_cjs/Logger/api.cjs +1 -2
  311. package/_cjs/Logger/api.cjs.map +1 -1
  312. package/_cjs/Logger/constructors.cjs +1 -2
  313. package/_cjs/Logger/constructors.cjs.map +1 -1
  314. package/_cjs/MVar/api.cjs +1 -2
  315. package/_cjs/MVar/api.cjs.map +1 -1
  316. package/_cjs/Push/api.cjs +2 -3
  317. package/_cjs/Push/api.cjs.map +1 -1
  318. package/_cjs/Push/internal.cjs +1 -2
  319. package/_cjs/Push/internal.cjs.map +1 -1
  320. package/_cjs/Queue/api/dimapIO.cjs +1 -2
  321. package/_cjs/Queue/api/dimapIO.cjs.map +1 -1
  322. package/_cjs/Queue/api/filterInputIO.cjs +1 -2
  323. package/_cjs/Queue/api/filterInputIO.cjs.map +1 -1
  324. package/_cjs/Queue/api/filterOutputIO.cjs +1 -2
  325. package/_cjs/Queue/api/filterOutputIO.cjs.map +1 -1
  326. package/_cjs/Queue/api/poll.cjs +1 -2
  327. package/_cjs/Queue/api/poll.cjs.map +1 -1
  328. package/_cjs/Queue/api/takeBetween.cjs +1 -2
  329. package/_cjs/Queue/api/takeBetween.cjs.map +1 -1
  330. package/_cjs/Queue/api/takeN.cjs +1 -2
  331. package/_cjs/Queue/api/takeN.cjs.map +1 -1
  332. package/_cjs/Queue/api/zipWithIO.cjs +1 -2
  333. package/_cjs/Queue/api/zipWithIO.cjs.map +1 -1
  334. package/_cjs/Queue/constructors.cjs +1 -2
  335. package/_cjs/Queue/constructors.cjs.map +1 -1
  336. package/_cjs/Queue/internal.cjs +1 -2
  337. package/_cjs/Queue/internal.cjs.map +1 -1
  338. package/_cjs/Queue/strategy.cjs +1 -2
  339. package/_cjs/Queue/strategy.cjs.map +1 -1
  340. package/_cjs/Random/api.cjs +1 -2
  341. package/_cjs/Random/api.cjs.map +1 -1
  342. package/_cjs/Random/definition.cjs +2 -2
  343. package/_cjs/Random/definition.cjs.map +1 -1
  344. package/_cjs/Random/live.cjs +1 -2
  345. package/_cjs/Random/live.cjs.map +1 -1
  346. package/_cjs/Ref/Atomic.cjs +1 -2
  347. package/_cjs/Ref/Atomic.cjs.map +1 -1
  348. package/_cjs/Ref/Derived.cjs +1 -2
  349. package/_cjs/Ref/Derived.cjs.map +1 -1
  350. package/_cjs/Ref/DerivedAll.cjs +1 -2
  351. package/_cjs/Ref/DerivedAll.cjs.map +1 -1
  352. package/_cjs/Ref/Synchronized/api.cjs +2 -3
  353. package/_cjs/Ref/Synchronized/api.cjs.map +1 -1
  354. package/_cjs/Ref/Synchronized/constructors.cjs +2 -3
  355. package/_cjs/Ref/Synchronized/constructors.cjs.map +1 -1
  356. package/_cjs/Ref/Synchronized/definition.cjs +2 -3
  357. package/_cjs/Ref/Synchronized/definition.cjs.map +1 -1
  358. package/_cjs/Ref/api/collect.cjs +1 -2
  359. package/_cjs/Ref/api/collect.cjs.map +1 -1
  360. package/_cjs/Ref/api/dimap.cjs +1 -2
  361. package/_cjs/Ref/api/dimap.cjs.map +1 -1
  362. package/_cjs/Ref/api/filter.cjs +1 -2
  363. package/_cjs/Ref/api/filter.cjs.map +1 -1
  364. package/_cjs/Ref/api/modify.cjs +1 -2
  365. package/_cjs/Ref/api/modify.cjs.map +1 -1
  366. package/_cjs/Ref/api.cjs +1 -2
  367. package/_cjs/Ref/api.cjs.map +1 -1
  368. package/_cjs/Ref/constructors.cjs +1 -2
  369. package/_cjs/Ref/constructors.cjs.map +1 -1
  370. package/_cjs/RefSubject/Atomic.cjs +1 -2
  371. package/_cjs/RefSubject/Atomic.cjs.map +1 -1
  372. package/_cjs/RefSubject/Synchronized/api.cjs +1 -2
  373. package/_cjs/RefSubject/Synchronized/api.cjs.map +1 -1
  374. package/_cjs/RefSubject/Synchronized/definition.cjs +1 -2
  375. package/_cjs/RefSubject/Synchronized/definition.cjs.map +1 -1
  376. package/_cjs/RefSubject/api.cjs +1 -2
  377. package/_cjs/RefSubject/api.cjs.map +1 -1
  378. package/_cjs/Reloadable/api.cjs +1 -2
  379. package/_cjs/Reloadable/api.cjs.map +1 -1
  380. package/_cjs/Reloadable/constructors.cjs +1 -2
  381. package/_cjs/Reloadable/constructors.cjs.map +1 -1
  382. package/_cjs/Reloadable/definition.cjs +1 -2
  383. package/_cjs/Reloadable/definition.cjs.map +1 -1
  384. package/_cjs/RuntimeFlag.cjs +0 -4
  385. package/_cjs/RuntimeFlags/Patch.cjs +1 -2
  386. package/_cjs/RuntimeFlags/Patch.cjs.map +1 -1
  387. package/_cjs/RuntimeFlags/RuntimeFlags.cjs +1 -2
  388. package/_cjs/RuntimeFlags/RuntimeFlags.cjs.map +1 -1
  389. package/_cjs/STM/api/atomically.cjs +1 -2
  390. package/_cjs/STM/api/atomically.cjs.map +1 -1
  391. package/_cjs/STM/api/core-api.cjs +1 -2
  392. package/_cjs/STM/api/core-api.cjs.map +1 -1
  393. package/_cjs/STM/api.cjs +1 -2
  394. package/_cjs/STM/api.cjs.map +1 -1
  395. package/_cjs/STM/definition.cjs +2 -3
  396. package/_cjs/STM/definition.cjs.map +1 -1
  397. package/_cjs/STM/driver.cjs +1 -2
  398. package/_cjs/STM/driver.cjs.map +1 -1
  399. package/_cjs/STM/internal/CommitState.cjs +1 -2
  400. package/_cjs/STM/internal/CommitState.cjs.map +1 -1
  401. package/_cjs/STM/internal/Journal.cjs +1 -2
  402. package/_cjs/STM/internal/Journal.cjs.map +1 -1
  403. package/_cjs/Schedule/Decision.cjs +1 -2
  404. package/_cjs/Schedule/Decision.cjs.map +1 -1
  405. package/_cjs/Schedule/api/driver.cjs +1 -2
  406. package/_cjs/Schedule/api/driver.cjs.map +1 -1
  407. package/_cjs/Schedule/api.cjs +1 -2
  408. package/_cjs/Schedule/api.cjs.map +1 -1
  409. package/_cjs/Scope/Finalizer/definition.cjs +1 -2
  410. package/_cjs/Scope/Finalizer/definition.cjs.map +1 -1
  411. package/_cjs/Scope/ReleaseMap/api/releaseAll.cjs +1 -2
  412. package/_cjs/Scope/ReleaseMap/api/releaseAll.cjs.map +1 -1
  413. package/_cjs/Scope/ReleaseMap/api.cjs +1 -2
  414. package/_cjs/Scope/ReleaseMap/api.cjs.map +1 -1
  415. package/_cjs/Scope/ReleaseMap/constructors.cjs +1 -2
  416. package/_cjs/Scope/ReleaseMap/constructors.cjs.map +1 -1
  417. package/_cjs/Scope/ReleaseMap/definition.cjs +1 -2
  418. package/_cjs/Scope/ReleaseMap/definition.cjs.map +1 -1
  419. package/_cjs/Scope/api.cjs +1 -2
  420. package/_cjs/Scope/api.cjs.map +1 -1
  421. package/_cjs/Scope/definition.cjs +1 -2
  422. package/_cjs/Scope/definition.cjs.map +1 -1
  423. package/_cjs/ScopedRef/api.cjs +2 -3
  424. package/_cjs/ScopedRef/api.cjs.map +1 -1
  425. package/_cjs/Semaphore/Reservation.cjs +24 -0
  426. package/_cjs/Semaphore/Reservation.cjs.map +1 -0
  427. package/_cjs/Semaphore/constructors.cjs +25 -0
  428. package/_cjs/Semaphore/constructors.cjs.map +1 -0
  429. package/_cjs/Semaphore/definition.cjs +149 -0
  430. package/_cjs/Semaphore/definition.cjs.map +1 -0
  431. package/_cjs/Semaphore.cjs +31 -138
  432. package/_cjs/Semaphore.cjs.map +1 -1
  433. package/_cjs/Sink/api.cjs +1 -2
  434. package/_cjs/Sink/api.cjs.map +1 -1
  435. package/_cjs/State/api.cjs +1 -2
  436. package/_cjs/State/api.cjs.map +1 -1
  437. package/_cjs/Stream/api/zipAllWith.cjs +1 -2
  438. package/_cjs/Stream/api/zipAllWith.cjs.map +1 -1
  439. package/_cjs/Stream/api/zipWith.cjs +1 -2
  440. package/_cjs/Stream/api/zipWith.cjs.map +1 -1
  441. package/_cjs/Stream/api/zipWithChunks.cjs +1 -2
  442. package/_cjs/Stream/api/zipWithChunks.cjs.map +1 -1
  443. package/_cjs/Stream/api.cjs +702 -703
  444. package/_cjs/Stream/api.cjs.map +1 -1
  445. package/_cjs/Stream/internal/Handoff.cjs +1 -2
  446. package/_cjs/Stream/internal/Handoff.cjs.map +1 -1
  447. package/_cjs/Stream/internal/Pull.cjs +1 -2
  448. package/_cjs/Stream/internal/Pull.cjs.map +1 -1
  449. package/_cjs/Stream/internal/Take.cjs +1 -2
  450. package/_cjs/Stream/internal/Take.cjs.map +1 -1
  451. package/_cjs/Stream/internal/util.cjs +1 -2
  452. package/_cjs/Stream/internal/util.cjs.map +1 -1
  453. package/_cjs/Subject/Atomic.cjs +1 -2
  454. package/_cjs/Subject/Atomic.cjs.map +1 -1
  455. package/_cjs/Subject/api.cjs +1 -2
  456. package/_cjs/Subject/api.cjs.map +1 -1
  457. package/_cjs/SubscriptionRef.cjs +2 -3
  458. package/_cjs/SubscriptionRef.cjs.map +1 -1
  459. package/_cjs/Supervisor/api.cjs +1 -2
  460. package/_cjs/Supervisor/api.cjs.map +1 -1
  461. package/_cjs/Supervisor/constructors.cjs +1 -2
  462. package/_cjs/Supervisor/constructors.cjs.map +1 -1
  463. package/_cjs/Supervisor/definition.cjs +1 -2
  464. package/_cjs/Supervisor/definition.cjs.map +1 -1
  465. package/_cjs/SupervisorPatch.cjs +1 -2
  466. package/_cjs/SupervisorPatch.cjs.map +1 -1
  467. package/_cjs/TExit/definition.cjs +1 -2
  468. package/_cjs/TExit/definition.cjs.map +1 -1
  469. package/_cjs/TFuture/api.cjs +1 -2
  470. package/_cjs/TFuture/api.cjs.map +1 -1
  471. package/_cjs/TFuture/constructors.cjs +1 -2
  472. package/_cjs/TFuture/constructors.cjs.map +1 -1
  473. package/_cjs/TFuture/definition.cjs +1 -2
  474. package/_cjs/TFuture/definition.cjs.map +1 -1
  475. package/_cjs/TReentrantLock/api.cjs +1 -2
  476. package/_cjs/TReentrantLock/api.cjs.map +1 -1
  477. package/_cjs/TReentrantLock/definition.cjs +1 -2
  478. package/_cjs/TReentrantLock/definition.cjs.map +1 -1
  479. package/_cjs/TRef/api.cjs +1 -2
  480. package/_cjs/TRef/api.cjs.map +1 -1
  481. package/_cjs/TRef/constructors.cjs +1 -2
  482. package/_cjs/TRef/constructors.cjs.map +1 -1
  483. package/_cjs/TRef/definition.cjs +1 -2
  484. package/_cjs/TRef/definition.cjs.map +1 -1
  485. package/_cjs/TSemaphore/api.cjs +1 -2
  486. package/_cjs/TSemaphore/api.cjs.map +1 -1
  487. package/_cjs/TSemaphore/constructors.cjs +1 -2
  488. package/_cjs/TSemaphore/constructors.cjs.map +1 -1
  489. package/_cjs/TSemaphore/definition.cjs +1 -2
  490. package/_cjs/TSemaphore/definition.cjs.map +1 -1
  491. package/_cjs/collection/immutable/Conc/dropUntilIO.cjs +1 -2
  492. package/_cjs/collection/immutable/Conc/dropUntilIO.cjs.map +1 -1
  493. package/_cjs/collection/immutable/Conc/dropWhileIO.cjs +1 -2
  494. package/_cjs/collection/immutable/Conc/dropWhileIO.cjs.map +1 -1
  495. package/_cjs/collection/immutable/Conc/filterIO.cjs +1 -2
  496. package/_cjs/collection/immutable/Conc/filterIO.cjs.map +1 -1
  497. package/_cjs/collection/immutable/Conc/findIO.cjs +1 -2
  498. package/_cjs/collection/immutable/Conc/findIO.cjs.map +1 -1
  499. package/_cjs/collection/immutable/Conc/mapIO.cjs +1 -2
  500. package/_cjs/collection/immutable/Conc/mapIO.cjs.map +1 -1
  501. package/_cjs/collection/immutable/Conc/takeWhileIO.cjs +1 -2
  502. package/_cjs/collection/immutable/Conc/takeWhileIO.cjs.map +1 -1
  503. package/_cjs/data/Exit/foreachIO.cjs +1 -2
  504. package/_cjs/data/Exit/foreachIO.cjs.map +1 -1
  505. package/_cjs/global.cjs +0 -4
  506. package/_cjs/index.cjs +0 -4
  507. package/_cjs/internal/HashedPair.cjs +1 -2
  508. package/_cjs/internal/HashedPair.cjs.map +1 -1
  509. package/_cjs/internal/Hub.cjs +1 -2
  510. package/_cjs/internal/Hub.cjs.map +1 -1
  511. package/_cjs/internal/MutableQueue.cjs +1 -2
  512. package/_cjs/internal/MutableQueue.cjs.map +1 -1
  513. package/_cjs/internal/Scheduler.cjs +1 -2
  514. package/_cjs/internal/Scheduler.cjs.map +1 -1
  515. package/_cjs/internal/StackTraceBuilder.cjs +1 -2
  516. package/_cjs/internal/StackTraceBuilder.cjs.map +1 -1
  517. package/_mjs/Cached/api.mjs.map +1 -1
  518. package/_mjs/Channel/api/mapOutConcurrentIO.mjs +1 -1
  519. package/_mjs/Channel/api/mergeAllWith.mjs +1 -1
  520. package/_mjs/Channel/api/runScoped.mjs +2 -2
  521. package/_mjs/Channel/api/runScoped.mjs.map +1 -1
  522. package/_mjs/Channel/api/toPull.mjs +1 -1
  523. package/_mjs/Channel/api/toPull.mjs.map +1 -1
  524. package/_mjs/Channel/api.mjs +205 -205
  525. package/_mjs/Channel/api.mjs.map +1 -1
  526. package/_mjs/Channel/core-api.mjs +43 -42
  527. package/_mjs/Channel/core-api.mjs.map +1 -1
  528. package/_mjs/Channel/internal/AsyncInputConsumer.mjs +1 -1
  529. package/_mjs/Channel/internal/AsyncInputProducer.mjs +1 -1
  530. package/_mjs/Channel/internal/ChannelExecutor.mjs +3 -3
  531. package/_mjs/Channel/internal/ChannelExecutor.mjs.map +1 -1
  532. package/_mjs/Console/definition.mjs +1 -0
  533. package/_mjs/Console/definition.mjs.map +1 -1
  534. package/_mjs/CountdownLatch.mjs +2 -1
  535. package/_mjs/CountdownLatch.mjs.map +1 -1
  536. package/_mjs/Fiber/FiberMessage.mjs +2 -20
  537. package/_mjs/Fiber/FiberMessage.mjs.map +1 -1
  538. package/_mjs/Fiber/FiberRuntime.mjs +877 -633
  539. package/_mjs/Fiber/FiberRuntime.mjs.map +1 -1
  540. package/_mjs/Fiber/api/collectAll.mjs +1 -1
  541. package/_mjs/Fiber/api/collectAll.mjs.map +1 -1
  542. package/_mjs/Fiber/api/interrupt.mjs +1 -1
  543. package/_mjs/Fiber/api/interrupt.mjs.map +1 -1
  544. package/_mjs/Fiber/api/interruptAll.mjs +1 -1
  545. package/_mjs/Fiber/api/interruptAll.mjs.map +1 -1
  546. package/_mjs/Fiber/api/interruptAs.mjs +4 -7
  547. package/_mjs/Fiber/api/interruptAs.mjs.map +1 -1
  548. package/_mjs/Fiber/api/interruptFork.mjs +1 -1
  549. package/_mjs/Fiber/api/interruptFork.mjs.map +1 -1
  550. package/_mjs/Fiber/api/mapIO.mjs +1 -1
  551. package/_mjs/Fiber/api/mapIO.mjs.map +1 -1
  552. package/_mjs/Fiber/api/zipWith.mjs +1 -1
  553. package/_mjs/Fiber/api/zipWith.mjs.map +1 -1
  554. package/_mjs/Fiber/constructors.mjs +1 -1
  555. package/_mjs/Fiber/constructors.mjs.map +1 -1
  556. package/_mjs/Fiber/definition.mjs +5 -2
  557. package/_mjs/Fiber/definition.mjs.map +1 -1
  558. package/_mjs/FiberScope/definition.mjs +28 -4
  559. package/_mjs/FiberScope/definition.mjs.map +1 -1
  560. package/_mjs/FiberSet.mjs +14 -12
  561. package/_mjs/FiberSet.mjs.map +1 -1
  562. package/_mjs/Future/State.mjs +96 -0
  563. package/_mjs/Future/State.mjs.map +1 -0
  564. package/_mjs/Future/api.mjs +67 -61
  565. package/_mjs/Future/api.mjs.map +1 -1
  566. package/_mjs/Future/constructors.mjs +3 -3
  567. package/_mjs/Future/constructors.mjs.map +1 -1
  568. package/_mjs/Future/definition.mjs +0 -12
  569. package/_mjs/Future/definition.mjs.map +1 -1
  570. package/_mjs/Future.mjs +1 -0
  571. package/_mjs/Future.mjs.map +1 -1
  572. package/_mjs/Hub/api.mjs +55 -55
  573. package/_mjs/Hub/api.mjs.map +1 -1
  574. package/_mjs/IO/api/array.mjs +42 -0
  575. package/_mjs/IO/api/array.mjs.map +1 -0
  576. package/_mjs/IO/api/asyncInterrupt.mjs.map +1 -1
  577. package/_mjs/IO/api/awaitAllChildren.mjs +10 -0
  578. package/_mjs/IO/api/awaitAllChildren.mjs.map +1 -0
  579. package/_mjs/IO/api/cachedInvalidate.mjs +39 -0
  580. package/_mjs/IO/api/cachedInvalidate.mjs.map +1 -0
  581. package/_mjs/IO/api/disconnect.mjs +1 -1
  582. package/_mjs/IO/api/disconnect.mjs.map +1 -1
  583. package/_mjs/IO/api/foreachConcurrent.mjs +35 -28
  584. package/_mjs/IO/api/foreachConcurrent.mjs.map +1 -1
  585. package/_mjs/IO/api/fork.mjs +1 -1
  586. package/_mjs/IO/api/fork.mjs.map +1 -1
  587. package/_mjs/IO/api/forkDaemon.mjs +4 -4
  588. package/_mjs/IO/api/forkDaemon.mjs.map +1 -1
  589. package/_mjs/IO/api/interrupt.mjs +3 -3
  590. package/_mjs/IO/api/onTermination.mjs +1 -1
  591. package/_mjs/IO/api/onTermination.mjs.map +1 -1
  592. package/_mjs/IO/api/race.mjs +1 -1
  593. package/_mjs/IO/api/race.mjs.map +1 -1
  594. package/_mjs/IO/api/timeout.mjs +8 -9
  595. package/_mjs/IO/api/timeout.mjs.map +1 -1
  596. package/_mjs/IO/api/transplant.mjs +19 -5
  597. package/_mjs/IO/api/transplant.mjs.map +1 -1
  598. package/_mjs/IO/api/zipConcurrent.mjs +4 -4
  599. package/_mjs/IO/api/zipConcurrent.mjs.map +1 -1
  600. package/_mjs/IO/api.mjs +515 -468
  601. package/_mjs/IO/api.mjs.map +1 -1
  602. package/_mjs/IO/definition.mjs +1 -1
  603. package/_mjs/IO/definition.mjs.map +1 -1
  604. package/_mjs/IO/runtime.mjs +8 -8
  605. package/_mjs/IO/runtime.mjs.map +1 -1
  606. package/_mjs/IO.mjs +3 -1
  607. package/_mjs/IO.mjs.map +1 -1
  608. package/_mjs/IOEnv/definition.mjs.map +1 -1
  609. package/_mjs/Push/api.mjs +1 -1
  610. package/_mjs/Random/definition.mjs +1 -0
  611. package/_mjs/Random/definition.mjs.map +1 -1
  612. package/_mjs/Ref/Synchronized/api.mjs +1 -1
  613. package/_mjs/Ref/Synchronized/api.mjs.map +1 -1
  614. package/_mjs/Ref/Synchronized/constructors.mjs +1 -1
  615. package/_mjs/Ref/Synchronized/definition.mjs +1 -1
  616. package/_mjs/Ref/Synchronized/definition.mjs.map +1 -1
  617. package/_mjs/RuntimeFlag.mjs +1 -1
  618. package/_mjs/STM/definition.mjs +1 -1
  619. package/_mjs/ScopedRef/api.mjs +1 -1
  620. package/_mjs/ScopedRef/api.mjs.map +1 -1
  621. package/_mjs/Semaphore/Reservation.mjs +16 -0
  622. package/_mjs/Semaphore/Reservation.mjs.map +1 -0
  623. package/_mjs/Semaphore/constructors.mjs +17 -0
  624. package/_mjs/Semaphore/constructors.mjs.map +1 -0
  625. package/_mjs/Semaphore/definition.mjs +141 -0
  626. package/_mjs/Semaphore/definition.mjs.map +1 -0
  627. package/_mjs/Semaphore.mjs +4 -133
  628. package/_mjs/Semaphore.mjs.map +1 -1
  629. package/_mjs/Stream/api.mjs +701 -701
  630. package/_mjs/Stream/api.mjs.map +1 -1
  631. package/_mjs/SubscriptionRef.mjs +1 -1
  632. package/_mjs/global.mjs +1 -1
  633. package/_mjs/index.mjs +1 -1
  634. package/_src/Cached/api.ts +3 -3
  635. package/_src/Channel/api/toPull.ts +1 -1
  636. package/_src/Channel/api.ts +273 -272
  637. package/_src/Channel/core-api.ts +57 -55
  638. package/_src/Channel/internal/ChannelExecutor.ts +3 -3
  639. package/_src/Console/definition.ts +1 -0
  640. package/_src/CountdownLatch.ts +2 -0
  641. package/_src/Fiber/FiberMessage.ts +3 -28
  642. package/_src/Fiber/FiberRuntime.ts +988 -616
  643. package/_src/Fiber/api/interruptAs.ts +4 -3
  644. package/_src/Fiber/constructors.ts +1 -1
  645. package/_src/Fiber/definition.ts +4 -0
  646. package/_src/FiberScope/definition.ts +40 -2
  647. package/_src/FiberSet.ts +6 -2
  648. package/_src/Future/State.ts +128 -0
  649. package/_src/Future/api.ts +62 -51
  650. package/_src/Future/constructors.ts +4 -2
  651. package/_src/Future/definition.ts +2 -17
  652. package/_src/Future.ts +4 -3
  653. package/_src/Hub/api.ts +61 -61
  654. package/_src/IO/api/addFinalizerExit.ts +4 -4
  655. package/_src/IO/api/array.ts +49 -0
  656. package/_src/IO/api/asyncInterrupt.ts +1 -1
  657. package/_src/IO/api/awaitAllChildren.ts +6 -0
  658. package/_src/IO/api/cachedInvalidate.ts +42 -0
  659. package/_src/IO/api/foreachConcurrent.ts +39 -23
  660. package/_src/IO/api/fork.ts +1 -1
  661. package/_src/IO/api/forkDaemon.ts +2 -2
  662. package/_src/IO/api/memoize.ts +3 -3
  663. package/_src/IO/api/onTermination.ts +2 -2
  664. package/_src/IO/api/transplant.ts +26 -3
  665. package/_src/IO/api/zipConcurrent.ts +2 -2
  666. package/_src/IO/api.ts +547 -525
  667. package/_src/IO/definition.ts +4 -28
  668. package/_src/IO/runtime.ts +0 -1
  669. package/_src/IO.ts +65 -63
  670. package/_src/IOEnv/definition.ts +1 -4
  671. package/_src/Random/definition.ts +1 -0
  672. package/_src/Ref/Synchronized/api.ts +2 -2
  673. package/_src/Ref/Synchronized/definition.ts +1 -1
  674. package/_src/Semaphore/Reservation.ts +15 -0
  675. package/_src/Semaphore/constructors.ts +14 -0
  676. package/_src/Semaphore/definition.ts +180 -0
  677. package/_src/Semaphore.ts +5 -159
  678. package/_src/Stream/api.ts +679 -679
  679. package/package.json +4 -4
  680. package/IO/api/sequenceT.d.ts +0 -26
  681. package/_cjs/IO/api/sequenceT.cjs +0 -18
  682. package/_cjs/IO/api/sequenceT.cjs.map +0 -1
  683. package/_mjs/IO/api/sequenceT.mjs +0 -10
  684. package/_mjs/IO/api/sequenceT.mjs.map +0 -1
  685. package/_src/IO/api/sequenceT.ts +0 -16
package/_src/IO/api.ts CHANGED
@@ -3,6 +3,7 @@ import type { ShowOptions } from "@fncts/base/data/Showable.js";
3
3
  import type * as P from "@fncts/base/typeclass";
4
4
  import type { _E, _R } from "@fncts/base/types";
5
5
  import type { FiberRuntime } from "@fncts/io/Fiber/FiberRuntime";
6
+ import type { WhileLoop } from "@fncts/io/IO/definition";
6
7
  import type { RuntimeFlags } from "@fncts/io/RuntimeFlags";
7
8
 
8
9
  import { IOError } from "@fncts/base/data/exceptions";
@@ -11,23 +12,6 @@ import { showWithOptions } from "@fncts/base/data/Showable";
11
12
  import { IOPrimitive, IOTag } from "@fncts/io/IO/definition";
12
13
  import { IO } from "@fncts/io/IO/definition";
13
14
 
14
- /**
15
- * Imports an asynchronous side-effect into a `IO`
16
- *
17
- * @tsplus static fncts.io.IOOps async
18
- */
19
- export function async<R, E, A>(
20
- register: (resolve: (_: IO<R, E, A>) => void) => void,
21
- blockingOn: FiberId = FiberId.none,
22
- __tsplusTrace?: string,
23
- ): IO<R, E, A> {
24
- const io = new IOPrimitive(IOTag.Async) as any;
25
- io.i0 = register;
26
- io.i1 = () => blockingOn;
27
- io.trace = __tsplusTrace;
28
- return io;
29
- }
30
-
31
15
  /**
32
16
  * Attempts to convert defects into a failure, throwing away all information
33
17
  * about the cause of the failure.
@@ -39,28 +23,6 @@ export function absorbWith<R, E, A>(f: (e: E) => unknown, __tsplusTrace?: string
39
23
  ma.sandbox.matchIO((cause) => IO.failNow(cause.squashWith(f)), IO.succeedNow);
40
24
  }
41
25
 
42
- /**
43
- * @tsplus pipeable fncts.io.IO zipLeft
44
- * @tsplus pipeable-operator fncts.io.IO <
45
- */
46
- export function zipLeft<R1, E1, B>(fb: IO<R1, E1, B>, __tsplusTrace?: string) {
47
- return <R, E, A>(self: IO<R, E, A>): IO<R1 | R, E1 | E, A> => {
48
- return self.flatMap((a) => fb.map(() => a));
49
- };
50
- }
51
-
52
- /**
53
- * Combine two effectful actions, keeping only the result of the second
54
- *
55
- * @tsplus pipeable fncts.io.IO zipRight
56
- * @tsplus pipeable-operator fncts.io.IO >
57
- */
58
- export function zipRight<R1, E1, B>(fb: IO<R1, E1, B>, __tsplusTrace?: string) {
59
- return <R, E, A>(self: IO<R, E, A>): IO<R1 | R, E1 | E, B> => {
60
- return self.flatMap(() => fb);
61
- };
62
- }
63
-
64
26
  /**
65
27
  * @tsplus pipeable fncts.io.IO as
66
28
  */
@@ -75,8 +37,8 @@ export function as<B>(b: Lazy<B>, __tsplusTrace?: string) {
75
37
  *
76
38
  * @tsplus getter fncts.io.IO asJust
77
39
  */
78
- export function asJust<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, E, Maybe<A>> {
79
- return ma.map(Maybe.just);
40
+ export function asJust<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, E, Maybe<A>> {
41
+ return self.map(Maybe.just);
80
42
  }
81
43
 
82
44
  /**
@@ -84,8 +46,8 @@ export function asJust<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R,
84
46
  *
85
47
  * @tsplus getter fncts.io.IO asJustError
86
48
  */
87
- export function asJustError<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, Maybe<E>, A> {
88
- return ma.mapError(Maybe.just);
49
+ export function asJustError<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, Maybe<E>, A> {
50
+ return self.mapError(Maybe.just);
89
51
  }
90
52
 
91
53
  /**
@@ -95,17 +57,34 @@ export function asUnit<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R
95
57
  return self.as(undefined);
96
58
  }
97
59
 
60
+ /**
61
+ * Imports an asynchronous side-effect into a `IO`
62
+ *
63
+ * @tsplus static fncts.io.IOOps async
64
+ */
65
+ export function async<R, E, A>(
66
+ register: (resolve: (_: IO<R, E, A>) => void) => void,
67
+ blockingOn: FiberId = FiberId.none,
68
+ __tsplusTrace?: string,
69
+ ): IO<R, E, A> {
70
+ const io = new IOPrimitive(IOTag.Async) as any;
71
+ io.i0 = register;
72
+ io.i1 = () => blockingOn;
73
+ io.trace = __tsplusTrace;
74
+ return io;
75
+ }
76
+
98
77
  /**
99
78
  * Returns an IO whose failure and success channels have been mapped by
100
79
  * the specified pair of functions, `f` and `g`.
101
80
  *
102
81
  * @tsplus pipeable fncts.io.IO bimap
103
82
  */
104
- export function bimap<E, A, E1, B>(f: (e: E) => E1, g: (a: A) => B, __tsplusTrace?: string) {
83
+ export function bimap<E, A, E1, B>(onFailure: (e: E) => E1, onSuccess: (a: A) => B, __tsplusTrace?: string) {
105
84
  return <R>(self: IO<R, E, A>): IO<R, E1, B> => {
106
85
  return self.matchIO(
107
- (e) => IO.failNow(f(e)),
108
- (a) => IO.succeedNow(g(a)),
86
+ (e) => IO.failNow(onFailure(e)),
87
+ (a) => IO.succeedNow(onSuccess(a)),
109
88
  );
110
89
  };
111
90
  }
@@ -133,54 +112,14 @@ export function bitap<E, A, R1, E1, R2, E2>(
133
112
  };
134
113
  }
135
114
 
136
- /**
137
- * Recovers from the specified error
138
- *
139
- * @tsplus pipeable fncts.io.IO catch
140
- */
141
- export function catchTagWith<N extends keyof E, K extends E[N] & string, E, R1, E1, A1>(
142
- tag: N,
143
- k: K,
144
- f: (
145
- e: Extract<
146
- E,
147
- {
148
- [n in N]: K;
149
- }
150
- >,
151
- ) => IO<R1, E1, A1>,
152
- __tsplusTrace?: string,
153
- ) {
154
- return <R, A>(
155
- ma: IO<R, E, A>,
156
- ): IO<
157
- R | R1,
158
- | Exclude<
159
- E,
160
- {
161
- [n in N]: K;
162
- }
163
- >
164
- | E1,
165
- A | A1
166
- > => {
167
- return ma.catchAll((e) => {
168
- if (isObject(e) && tag in e && e[tag] === k) {
169
- return f(e as any);
170
- }
171
- return IO.failNow(e as any);
172
- });
173
- };
174
- }
175
-
176
115
  /**
177
116
  * Recovers from all errors
178
117
  *
179
118
  * @tsplus pipeable fncts.io.IO catchAll
180
119
  */
181
- export function catchAll<E, R1, E1, A1>(f: (e: E) => IO<R1, E1, A1>, __tsplusTrace?: string) {
182
- return <R, A>(ma: IO<R, E, A>): IO<R | R1, E1, A | A1> => {
183
- return ma.matchIO(f, IO.succeedNow);
120
+ export function catchAll<E, R1, E1, A1>(onFailure: (e: E) => IO<R1, E1, A1>, __tsplusTrace?: string) {
121
+ return <R, A>(self: IO<R, E, A>): IO<R | R1, E1, A | A1> => {
122
+ return self.matchIO(onFailure, IO.succeedNow);
184
123
  };
185
124
  }
186
125
 
@@ -190,8 +129,8 @@ export function catchAll<E, R1, E1, A1>(f: (e: E) => IO<R1, E1, A1>, __tsplusTra
190
129
  *
191
130
  * @tsplus pipeable fncts.io.IO catchAllCause
192
131
  */
193
- export function catchAllCause<R, E, A, R1, E1, A1>(f: (_: Cause<E>) => IO<R1, E1, A1>, __tsplusTrace?: string) {
194
- return (ma: IO<R, E, A>): IO<R | R1, E1, A | A1> => ma.matchCauseIO(f, IO.succeedNow);
132
+ export function catchAllCause<R, E, A, R1, E1, A1>(onFailure: (_: Cause<E>) => IO<R1, E1, A1>, __tsplusTrace?: string) {
133
+ return (self: IO<R, E, A>): IO<R | R1, E1, A | A1> => self.matchCauseIO(onFailure, IO.succeedNow);
195
134
  }
196
135
 
197
136
  /**
@@ -199,10 +138,10 @@ export function catchAllCause<R, E, A, R1, E1, A1>(f: (_: Cause<E>) => IO<R1, E1
199
138
  *
200
139
  * @tsplus pipeable fncts.io.IO catchJust
201
140
  */
202
- export function catchJust<E, R1, E1, A1>(f: (e: E) => Maybe<IO<R1, E1, A1>>, __tsplusTrace?: string) {
203
- return <R, A>(ma: IO<R, E, A>): IO<R | R1, E | E1, A | A1> => {
204
- return ma.matchCauseIO(
205
- (cause) => cause.failureOrCause.match((e) => f(e).getOrElse(IO.failCauseNow(cause)), IO.failCauseNow),
141
+ export function catchJust<E, R1, E1, A1>(onFailure: (e: E) => Maybe<IO<R1, E1, A1>>, __tsplusTrace?: string) {
142
+ return <R, A>(self: IO<R, E, A>): IO<R | R1, E | E1, A | A1> => {
143
+ return self.matchCauseIO(
144
+ (cause) => cause.failureOrCause.match((e) => onFailure(e).getOrElse(IO.failCauseNow(cause)), IO.failCauseNow),
206
145
  IO.succeedNow,
207
146
  );
208
147
  };
@@ -213,9 +152,12 @@ export function catchJust<E, R1, E1, A1>(f: (e: E) => Maybe<IO<R1, E1, A1>>, __t
213
152
  *
214
153
  * @tsplus pipeable fncts.io.IO catchJustCause
215
154
  */
216
- export function catchJustCause<E, R1, E1, A1>(f: (_: Cause<E>) => Maybe<IO<R1, E1, A1>>, __tsplusTrace?: string) {
217
- return <R, A>(ma: IO<R, E, A>): IO<R | R1, E | E1, A | A1> => {
218
- return ma.matchCauseIO((cause) => f(cause).getOrElse(IO.failCauseNow(cause)), IO.succeedNow);
155
+ export function catchJustCause<E, R1, E1, A1>(
156
+ onFailure: (_: Cause<E>) => Maybe<IO<R1, E1, A1>>,
157
+ __tsplusTrace?: string,
158
+ ) {
159
+ return <R, A>(self: IO<R, E, A>): IO<R | R1, E | E1, A | A1> => {
160
+ return self.matchCauseIO((cause) => onFailure(cause).getOrElse(IO.failCauseNow(cause)), IO.succeedNow);
219
161
  };
220
162
  }
221
163
 
@@ -229,9 +171,9 @@ export function catchJustCause<E, R1, E1, A1>(f: (_: Cause<E>) => Maybe<IO<R1, E
229
171
  *
230
172
  * @tsplus pipeable fncts.io.IO catchJustDefect
231
173
  */
232
- export function catchJustDefect<R1, E1, A1>(f: (_: unknown) => Maybe<IO<R1, E1, A1>>, __tsplusTrace?: string) {
233
- return <R, E, A>(ma: IO<R, E, A>): IO<R | R1, E | E1, A | A1> => {
234
- return ma.unrefineWith(f, IO.failNow).catchAll((a) => a as IO<R | R1, E | E1, A | A1>);
174
+ export function catchJustDefect<R1, E1, A1>(onFailure: (_: unknown) => Maybe<IO<R1, E1, A1>>, __tsplusTrace?: string) {
175
+ return <R, E, A>(self: IO<R, E, A>): IO<R | R1, E | E1, A | A1> => {
176
+ return self.unrefineWith(onFailure, IO.failNow).catchAll((a) => a as IO<R | R1, E | E1, A | A1>);
235
177
  };
236
178
  }
237
179
 
@@ -240,56 +182,50 @@ export function catchJustDefect<R1, E1, A1>(f: (_: unknown) => Maybe<IO<R1, E1,
240
182
  *
241
183
  * @tsplus pipeable IO catchTag
242
184
  */
243
- export function catchTag<
244
- K extends E["_tag"] & string,
245
- E extends {
246
- _tag: string;
247
- },
248
- R1,
249
- E1,
250
- A1,
251
- >(
252
- k: K,
253
- f: (
254
- e: Extract<
255
- E,
256
- {
257
- _tag: K;
258
- }
259
- >,
260
- ) => IO<R1, E1, A1>,
185
+ export function catchTag<T extends E["_tag"] & string, E extends { _tag: string }, R1, E1, A1>(
186
+ tag: T,
187
+ onFailure: (e: Extract<E, { _tag: T }>) => IO<R1, E1, A1>,
261
188
  __tsplusTrace?: string,
262
189
  ) {
263
- return <R, A>(
264
- ma: IO<R, E, A>,
265
- ): IO<
266
- R | R1,
267
- | Exclude<
268
- E,
269
- {
270
- _tag: K;
271
- }
272
- >
273
- | E1,
274
- A | A1
275
- > => {
276
- return ma.catch("_tag", k, f);
190
+ return <R, A>(self: IO<R, E, A>): IO<R | R1, Exclude<E, { _tag: T }> | E1, A | A1> => {
191
+ return self.catch("_tag", tag, onFailure);
192
+ };
193
+ }
194
+
195
+ /**
196
+ * Recovers from the specified error
197
+ *
198
+ * @tsplus pipeable fncts.io.IO catch
199
+ */
200
+ export function catchTagWith<K extends keyof E, T extends E[K] & string, E, R1, E1, A1>(
201
+ tagKey: K,
202
+ tag: T,
203
+ onFailure: (e: Extract<E, { [n in K]: T }>) => IO<R1, E1, A1>,
204
+ __tsplusTrace?: string,
205
+ ) {
206
+ return <R, A>(self: IO<R, E, A>): IO<R | R1, Exclude<E, { [n in K]: T }> | E1, A | A1> => {
207
+ return self.catchAll((e) => {
208
+ if (isObject(e) && tagKey in e && e[tagKey] === tag) {
209
+ return onFailure(e as any);
210
+ }
211
+ return IO.failNow(e as any);
212
+ });
277
213
  };
278
214
  }
279
215
 
280
216
  /**
281
217
  * @tsplus getter fncts.io.IO cause
282
218
  */
283
- export function cause<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, Cause<E>> {
284
- return ma.matchCauseIO(IO.succeedNow, () => IO.succeedNow(Cause.empty()));
219
+ export function cause<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, Cause<E>> {
220
+ return self.matchCauseIO(IO.succeedNow, () => IO.succeedNow(Cause.empty()));
285
221
  }
286
222
 
287
223
  /**
288
224
  * @tsplus pipeable fncts.io.IO causeAsError
289
225
  */
290
226
  export function causeAsError(__tsplusTrace?: string) {
291
- return <R, E, A>(ma: IO<R, E, A>): IO<R, Cause<E>, A> => {
292
- return ma.matchCauseIO(IO.failNow, IO.succeedNow);
227
+ return <R, E, A>(self: IO<R, E, A>): IO<R, Cause<E>, A> => {
228
+ return self.matchCauseIO(IO.failNow, IO.succeedNow);
293
229
  };
294
230
  }
295
231
 
@@ -307,48 +243,37 @@ export function checkInterruptible<R, E, A>(
307
243
  }
308
244
 
309
245
  /**
310
- * Returns an IO that models the execution of this effect, followed by
311
- * the passing of its value to the specified continuation function `f`,
312
- * followed by the effect that it returns.
313
- *
314
- * @tsplus pipeable fncts.io.IO flatMap
315
- */
316
- export function flatMap<A, R1, E1, B>(f: (a: A) => IO<R1, E1, B>, __tsplusTrace?: string) {
317
- return <R, E>(ma: IO<R, E, A>): IO<R | R1, E | E1, B> => {
318
- const io = new IOPrimitive(IOTag.OnSuccess) as any;
319
- io.i0 = ma;
320
- io.i1 = f;
321
- io.trace = __tsplusTrace;
322
-
323
- return io;
324
- };
325
- }
326
-
327
- /**
328
- * @tsplus pipeable fncts.io.IO flatMapError
246
+ * @tsplus pipeable fncts.io.IO collect
329
247
  */
330
- export function flatMapError<R1, E, E1>(f: (e: E) => IO<R1, never, E1>, __tsplusTrace?: string) {
331
- return <R, A>(ma: IO<R, E, A>): IO<R | R1, E1, A> => {
332
- return ma.swapWith((effect) => effect.flatMap(f));
248
+ export function collect<A, E1, A1>(f: Lazy<E1>, pf: (a: A) => Maybe<A1>, __tsplusTrace?: string) {
249
+ return <R, E>(self: IO<R, E, A>): IO<R, E | E1, A1> => {
250
+ return self.collectIO(f, (a) => pf(a).map(IO.succeedNow));
333
251
  };
334
252
  }
335
253
 
336
254
  /**
337
- * @tsplus pipeable fncts.io.IO collect
255
+ * @tsplus pipeable fncts.io.IO collectIO
338
256
  */
339
- export function collect<A, E1, A1>(f: Lazy<E1>, pf: (a: A) => Maybe<A1>, __tsplusTrace?: string) {
340
- return <R, E>(ma: IO<R, E, A>): IO<R, E | E1, A1> => {
341
- return ma.collectIO(f, (a) => pf(a).map(IO.succeedNow));
257
+ export function collectIO<A, R1, E1, A1, E2>(
258
+ onNothing: Lazy<E2>,
259
+ pf: (a: A) => Maybe<IO<R1, E1, A1>>,
260
+ __tsplusTrace?: string,
261
+ ) {
262
+ return <R, E>(self: IO<R, E, A>): IO<R | R1, E | E1 | E2, A1> => {
263
+ return self.flatMap((a) => pf(a).getOrElse(IO.fail(onNothing)));
342
264
  };
343
265
  }
344
266
 
345
267
  /**
346
- * @tsplus pipeable fncts.io.IO collectIO
268
+ * @tsplus static fncts.io.IOOps if
347
269
  */
348
- export function collectIO<A, R1, E1, A1, E2>(f: Lazy<E2>, pf: (a: A) => Maybe<IO<R1, E1, A1>>, __tsplusTrace?: string) {
349
- return <R, E>(ma: IO<R, E, A>): IO<R | R1, E | E1 | E2, A1> => {
350
- return ma.flatMap((a) => pf(a).getOrElse(IO.fail(f)));
351
- };
270
+ export function cond<R, E, A, R1, E1, A1>(
271
+ b: boolean,
272
+ onTrue: Lazy<IO<R, E, A>>,
273
+ onFalse: Lazy<IO<R1, E1, A1>>,
274
+ __tsplusTrace?: string,
275
+ ): IO<R | R1, E | E1, A | A1> {
276
+ return IO.succeedNow(b).ifIO(onTrue, onFalse);
352
277
  }
353
278
 
354
279
  /**
@@ -372,7 +297,12 @@ export function condIO<R, R1, E, A>(
372
297
  * @tsplus static fncts.io.IOOps defer
373
298
  */
374
299
  export function defer<R = never, E = never, A = never>(io: Lazy<IO<R, E, A>>, __tsplusTrace?: string): IO<R, E, A> {
375
- return IO.succeed(io).flatMap(identity);
300
+ const out = new IOPrimitive(IOTag.OnSuccess) as any;
301
+ out.i0 = IO.unit;
302
+ out.i1 = io;
303
+ out.trace = __tsplusTrace;
304
+
305
+ return out;
376
306
  }
377
307
 
378
308
  /**
@@ -382,7 +312,7 @@ export function defer<R = never, E = never, A = never>(io: Lazy<IO<R, E, A>>, __
382
312
  * @tsplus static fncts.io.IOOps deferTry
383
313
  */
384
314
  export function deferTry<R = never, E = never, A = never>(
385
- io: () => IO<R, E, A>,
315
+ io: Lazy<IO<R, E, A>>,
386
316
  __tsplusTrace?: string,
387
317
  ): IO<R, unknown, A> {
388
318
  return IO.defer(() => {
@@ -403,7 +333,7 @@ export function deferTry<R = never, E = never, A = never>(
403
333
  * @tsplus static IOOps deferTryCatch
404
334
  */
405
335
  export function deferTryCatch<R, E, A, E1>(
406
- io: () => IO<R, E, A>,
336
+ io: Lazy<IO<R, E, A>>,
407
337
  onThrow: (error: unknown) => E1,
408
338
  __tsplusTrace?: string,
409
339
  ): IO<R, E | E1, A> {
@@ -421,57 +351,61 @@ export function deferTryCatch<R, E, A, E1>(
421
351
  *
422
352
  * @tsplus getter fncts.io.IO either
423
353
  */
424
- export function either<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): URIO<R, Either<E, A>> {
425
- return ma.match(Either.left, Either.right);
354
+ export function either<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): URIO<R, Either<E, A>> {
355
+ return self.match(Either.left, Either.right);
426
356
  }
427
357
 
428
358
  /**
429
359
  * @tsplus pipeable fncts.io.IO errorAsCause
430
360
  */
431
361
  export function errorAsCause(__tsplusTrace?: string) {
432
- return <R, E, A>(ma: IO<R, Cause<E>, A>): IO<R, E, A> => {
433
- return ma.matchIO(IO.failCauseNow, IO.succeedNow);
362
+ return <R, E, A>(self: IO<R, Cause<E>, A>): IO<R, E, A> => {
363
+ return self.matchIO(IO.failCauseNow, IO.succeedNow);
434
364
  };
435
365
  }
436
366
 
437
367
  /**
438
368
  * @tsplus getter fncts.io.IO eventually
439
369
  */
440
- export function eventually<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, A> {
441
- return ma.orElse(ma.eventually);
370
+ export function eventually<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, A> {
371
+ return self.orElse(self.eventually);
442
372
  }
443
373
 
444
374
  /**
445
- * @tsplus pipeable fncts.io.IO extend
375
+ * @tsplus pipeable fncts.io.IO exitWith
446
376
  */
447
- export function extend<R, E, A, B>(f: (wa: IO<R, E, A>) => B, __tsplusTrace?: string) {
448
- return (wa: IO<R, E, A>): IO<R, E, B> => {
449
- return wa.matchIO(IO.failNow, (_) => IO.succeed(f(wa)));
377
+ export function exitWith<E, A, R1, E1, B>(f: (exit: Exit<E, A>) => IO<R1, E1, B>, __tsplusTrace?: string) {
378
+ return <R>(self: IO<R, E, A>): IO<R | R1, E1, B> => {
379
+ return self.matchCauseIO(
380
+ (cause) => f(Exit.failCause(cause)),
381
+ (a) => f(Exit.succeed(a)),
382
+ );
450
383
  };
451
384
  }
452
385
 
453
386
  /**
454
- * @tsplus static fncts.io.IOOps fail
387
+ * @tsplus pipeable fncts.io.IO extend
455
388
  */
456
- export function fail<E>(e: Lazy<E>, __tsplusTrace?: string): FIO<E, never> {
457
- return IO.failCause(Cause.fail(e()));
389
+ export function extend<R, E, A, B>(f: (io: IO<R, E, A>) => B, __tsplusTrace?: string) {
390
+ return (self: IO<R, E, A>): IO<R, E, B> => {
391
+ return self.matchIO(IO.failNow, (_) => IO.succeed(f(self)));
392
+ };
458
393
  }
459
394
 
460
395
  /**
461
- * @tsplus static fncts.io.IOOps failNow
396
+ * @tsplus static fncts.io.IOOps fail
462
397
  */
463
- export function failNow<E>(e: E, __tsplusTrace?: string): FIO<E, never> {
464
- return IO.failCause(Cause.fail(e));
398
+ export function fail<E>(e: Lazy<E>, __tsplusTrace?: string): FIO<E, never> {
399
+ return IO.failCause(Cause.fail(e()));
465
400
  }
466
401
 
467
402
  /**
468
- * @tsplus static fncts.io.IOOps refailCause
403
+ * Returns an effect that models failure with the specified lazily-evaluated `Cause`.
404
+ *
405
+ * @tsplus static fncts.io.IOOps failCause
469
406
  */
470
- export function refailCause<E>(cause: Cause<E>, __tsplusTrace?: string): FIO<E, never> {
471
- const io = new IOPrimitive(IOTag.Fail) as any;
472
- io.i0 = () => cause;
473
- io.trace = __tsplusTrace;
474
- return io;
407
+ export function failCause<E = never, A = never>(cause: Lazy<Cause<E>>, __tsplusTrace?: string): FIO<E, A> {
408
+ return IO.stackTrace(__tsplusTrace).flatMap((trace) => IO.refailCause(Cause.traced(cause(), trace)));
475
409
  }
476
410
 
477
411
  /**
@@ -487,12 +421,10 @@ export function failCauseNow<E>(cause: Cause<E>, __tsplusTrace?: string): FIO<E,
487
421
  }
488
422
 
489
423
  /**
490
- * Returns an effect that models failure with the specified lazily-evaluated `Cause`.
491
- *
492
- * @tsplus static fncts.io.IOOps failCause
424
+ * @tsplus static fncts.io.IOOps failNow
493
425
  */
494
- export function failCause<E = never, A = never>(cause: Lazy<Cause<E>>, __tsplusTrace?: string): FIO<E, A> {
495
- return IO.stackTrace(__tsplusTrace).flatMap((trace) => IO.refailCause(Cause.traced(cause(), trace)));
426
+ export function failNow<E>(e: E, __tsplusTrace?: string): FIO<E, never> {
427
+ return IO.failCause(Cause.fail(e));
496
428
  }
497
429
 
498
430
  /**
@@ -586,11 +518,13 @@ export function filterOrElse<A, B extends A, R1, E1, A1>(
586
518
  or: (a: Exclude<A, B>) => IO<R1, E1, A1>,
587
519
  __tsplusTrace?: string,
588
520
  ): <R, E>(fa: IO<R, E, A>) => IO<R | R1, E | E1, B | A1>;
521
+
589
522
  export function filterOrElse<A, R1, E1, A1>(
590
523
  predicate: Predicate<A>,
591
524
  or: (a: A) => IO<R1, E1, A1>,
592
525
  __tsplusTrace?: string,
593
526
  ): <R, E>(fa: IO<R, E, A>) => IO<R | R1, E | E1, A | A1>;
527
+
594
528
  export function filterOrElse<A>(predicate: Predicate<A>, or: unknown, __tsplusTrace?: string) {
595
529
  return <R, E, R1, E1, A1>(fa: IO<R, E, A>): IO<R | R1, E | E1, A | A1> => {
596
530
  return fa.flatMap(
@@ -608,26 +542,17 @@ export function filterOrFail<A, B extends A, E1>(
608
542
  refinement: Refinement<A, B>,
609
543
  failWith: (a: Exclude<A, B>) => E1,
610
544
  ): <R, E>(fa: IO<R, E, A>) => IO<R, E | E1, B>;
545
+
611
546
  export function filterOrFail<A, E1>(
612
547
  predicate: Predicate<A>,
613
548
  failWith: (a: A) => E1,
614
549
  ): <R, E>(fa: IO<R, E, A>) => IO<R, E | E1, A>;
550
+
615
551
  export function filterOrFail<A>(predicate: Predicate<A>, failWith: unknown, __tsplusTrace?: string) {
616
552
  return <R, E, E1>(fa: IO<R, E, A>): IO<R, E | E1, A> => {
617
553
  return fa.filterOrElse(predicate, (a) => IO.failNow((failWith as (a: A) => E1)(a)));
618
554
  };
619
555
  }
620
-
621
- /**
622
- * Returns an `IO` that yields the value of the first
623
- * `IO` to succeed.
624
- *
625
- * @tsplus static fncts.io.IOOps firstSuccess
626
- */
627
- export function firstSuccess<R, E, A>(mas: NonEmptyArray<IO<R, E, A>>, __tsplusTrace?: string): IO<R, E, A> {
628
- return mas.reduce((b, a) => b.orElse(a));
629
- }
630
-
631
556
  /**
632
557
  * Halts with specified `unknown` if the predicate fails.
633
558
  *
@@ -643,11 +568,47 @@ export function filterOrHalt<A>(
643
568
  haltWith: (a: A) => unknown,
644
569
  __tsplusTrace?: string,
645
570
  ): <R, E>(fa: IO<R, E, A>) => IO<R, E, A>;
571
+
646
572
  export function filterOrHalt<A>(predicate: Predicate<A>, haltWith: unknown, __tsplusTrace?: string) {
647
573
  return <R, E>(fa: IO<R, E, A>): IO<R, E, A> => {
648
574
  return fa.filterOrElse(predicate, (a) => IO.haltNow((haltWith as (a: A) => unknown)(a)));
649
575
  };
650
576
  }
577
+ /**
578
+ * Returns an `IO` that yields the value of the first
579
+ * `IO` to succeed.
580
+ *
581
+ * @tsplus static fncts.io.IOOps firstSuccess
582
+ */
583
+ export function firstSuccess<R, E, A>(ios: ReadonlyNonEmptyArray<IO<R, E, A>>, __tsplusTrace?: string): IO<R, E, A> {
584
+ return ios.reduce((b, a) => b.orElse(a));
585
+ }
586
+ /**
587
+ * Returns an IO that models the execution of this effect, followed by
588
+ * the passing of its value to the specified continuation function `f`,
589
+ * followed by the effect that it returns.
590
+ *
591
+ * @tsplus pipeable fncts.io.IO flatMap
592
+ */
593
+ export function flatMap<A, R1, E1, B>(f: (a: A) => IO<R1, E1, B>, __tsplusTrace?: string) {
594
+ return <R, E>(self: IO<R, E, A>): IO<R | R1, E | E1, B> => {
595
+ const io = new IOPrimitive(IOTag.OnSuccess) as any;
596
+ io.i0 = self;
597
+ io.i1 = f;
598
+ io.trace = __tsplusTrace;
599
+
600
+ return io;
601
+ };
602
+ }
603
+
604
+ /**
605
+ * @tsplus pipeable fncts.io.IO flatMapError
606
+ */
607
+ export function flatMapError<R1, E, E1>(f: (e: E) => IO<R1, never, E1>, __tsplusTrace?: string) {
608
+ return <R, A>(self: IO<R, E, A>): IO<R | R1, E1, A> => {
609
+ return self.swapWith((effect) => effect.flatMap(f));
610
+ };
611
+ }
651
612
 
652
613
  /**
653
614
  * @tsplus getter fncts.io.IO flatten
@@ -655,11 +616,11 @@ export function filterOrHalt<A>(predicate: Predicate<A>, haltWith: unknown, __ts
655
616
  export function flatten<R, E, R1, E1, A>(self: IO<R, E, IO<R1, E1, A>>, __tsplusTrace?: string): IO<R | R1, E | E1, A> {
656
617
  return self.flatMap(identity);
657
618
  }
658
-
659
619
  /**
660
620
  * Folds an `Iterable<A>` using an effectful function f, working sequentially from left to right.
661
621
  *
662
622
  * @tsplus static fncts.io.IOOps foldLeft
623
+ * @tsplus fluent fncts.Iterable foldLeftIO
663
624
  */
664
625
  export function foldLeft<A, B, R, E>(
665
626
  as: Iterable<A>,
@@ -674,29 +635,21 @@ export function foldLeft<A, B, R, E>(
674
635
  * Combines an array of `IO`s using a `Monoid`
675
636
  *
676
637
  * @tsplus static fncts.io.IOOps foldMap
638
+ * @tsplus fluent fncts.Iterable foldMapIO
677
639
  */
678
640
  export function foldMap<R, E, A, M>(
679
- as: Iterable<IO<R, E, A>>,
641
+ ios: Iterable<IO<R, E, A>>,
680
642
  f: (a: A) => M,
681
643
  /** @tsplus auto */ M: P.Monoid<M>,
682
644
  ): IO<R, E, M> {
683
- return IO.foldLeft(as, M.nat, (m, a) => a.map((a) => M.combine(f(a))(m)));
684
- }
685
-
686
- function foldRightLoop<A, B, R, E>(
687
- iterator: Iterator<A>,
688
- b: UIO<B>,
689
- f: (a: A, b: IO<R, E, B>) => IO<R, E, B>,
690
- __tsplusTrace?: string,
691
- ): IO<R, E, B> {
692
- const next = iterator.next();
693
- return next.done ? b : f(next.value, foldRightLoop(iterator, b, f));
645
+ return IO.foldLeft(ios, M.nat, (m, a) => a.map((a) => M.combine(f(a))(m)));
694
646
  }
695
647
 
696
648
  /**
697
649
  * Performs a right-associative fold of an `Iterable<A>`
698
650
  *
699
651
  * @tsplus static fncts.io.IOOps foldRight
652
+ * @tsplus fluent fncts.Iterable foldRightIO
700
653
  */
701
654
  export function foldRight<A, B, R, E>(
702
655
  as: Iterable<A>,
@@ -707,14 +660,14 @@ export function foldRight<A, B, R, E>(
707
660
  return foldRightLoop(as[Symbol.iterator](), b, f);
708
661
  }
709
662
 
710
- function foreachWithIndexDiscardLoop<A, R, E, B>(
663
+ function foldRightLoop<A, B, R, E>(
711
664
  iterator: Iterator<A>,
712
- f: (i: number, a: A) => IO<R, E, B>,
713
- i = 0,
665
+ b: UIO<B>,
666
+ f: (a: A, b: IO<R, E, B>) => IO<R, E, B>,
714
667
  __tsplusTrace?: string,
715
- ): IO<R, E, void> {
668
+ ): IO<R, E, B> {
716
669
  const next = iterator.next();
717
- return next.done ? IO.unit : f(i, next.value).flatMap(() => foreachWithIndexDiscardLoop(iterator, f, i + 1));
670
+ return next.done ? b : f(next.value, foldRightLoop(iterator, b, f));
718
671
  }
719
672
 
720
673
  /**
@@ -725,6 +678,7 @@ function foreachWithIndexDiscardLoop<A, R, E, B>(
725
678
  * If you do not need the results, see `foreachUnit` for a more efficient implementation.
726
679
  *
727
680
  * @tsplus static fncts.io.IOOps foreach
681
+ * @tsplus fluent fncts.Iterable foreachIO
728
682
  */
729
683
  export function foreach<A, R, E, B>(
730
684
  as: Iterable<A>,
@@ -742,6 +696,21 @@ export function foreach<A, R, E, B>(
742
696
  });
743
697
  }
744
698
 
699
+ /**
700
+ * Applies the function `f` to each element of the `Iterable<A>` and runs
701
+ * produced IOs sequentially.
702
+ *
703
+ * @tsplus static fncts.io.IOOps foreachDiscard
704
+ * @tsplus fluent fncts.Iterable foreachDiscardIO
705
+ */
706
+ export function foreachDiscard<A, R, E, B>(
707
+ as: Iterable<A>,
708
+ f: (a: A) => IO<R, E, B>,
709
+ __tsplusTrace?: string,
710
+ ): IO<R, E, void> {
711
+ return IO.defer(foreachWithIndexDiscardLoop(as[Symbol.iterator](), (_, a) => f(a)));
712
+ }
713
+
745
714
  /**
746
715
  * Applies the function `f` to each element of the `Iterable<A>` and
747
716
  * returns the results in a new `Conc<B>`.
@@ -750,6 +719,7 @@ export function foreach<A, R, E, B>(
750
719
  * If you do not need the results, see `foreachUnit` for a more efficient implementation.
751
720
  *
752
721
  * @tsplus static fncts.io.IOOps foreachWithIndex
722
+ * @tsplus fluent fncts.Iterable foreachWithIndexIO
753
723
  */
754
724
  export function foreachWithIndex<A, R, E, B>(
755
725
  as: Iterable<A>,
@@ -769,6 +739,7 @@ export function foreachWithIndex<A, R, E, B>(
769
739
 
770
740
  /**
771
741
  * @tsplus static fncts.io.IOOps foreachWithIndexDiscard
742
+ * @tsplus fluent fncts.Iterable foreachWithIndexDiscardIO
772
743
  */
773
744
  export function foreachWithIndexDiscard<A, R, E, B>(
774
745
  as: Iterable<A>,
@@ -778,18 +749,14 @@ export function foreachWithIndexDiscard<A, R, E, B>(
778
749
  return IO.defer(foreachWithIndexDiscardLoop(as[Symbol.iterator](), f));
779
750
  }
780
751
 
781
- /**
782
- * Applies the function `f` to each element of the `Iterable<A>` and runs
783
- * produced IOs sequentially.
784
- *
785
- * @tsplus static fncts.io.IOOps foreachDiscard
786
- */
787
- export function foreachDiscard<A, R, E, B>(
788
- as: Iterable<A>,
789
- f: (a: A) => IO<R, E, B>,
752
+ function foreachWithIndexDiscardLoop<A, R, E, B>(
753
+ iterator: Iterator<A>,
754
+ f: (i: number, a: A) => IO<R, E, B>,
755
+ i = 0,
790
756
  __tsplusTrace?: string,
791
757
  ): IO<R, E, void> {
792
- return IO.defer(foreachWithIndexDiscardLoop(as[Symbol.iterator](), (_, a) => f(a)));
758
+ const next = iterator.next();
759
+ return next.done ? IO.unit : f(i, next.value).flatMap(() => foreachWithIndexDiscardLoop(iterator, f, i + 1));
793
760
  }
794
761
 
795
762
  /**
@@ -869,9 +836,19 @@ export function fromMaybeNow<A = never>(maybe: Maybe<A>, __tsplusTrace?: string)
869
836
 
870
837
  /**
871
838
  * Create an IO that when executed will construct `promise` and wait for its result,
872
- * errors will be handled using `onReject`
839
+ * errors will produce failure as `unknown`
873
840
  *
874
- * @tsplus static fncts.io.IOOps fromPromiseCatch
841
+ * @tsplus static fncts.io.IOOps fromPromise
842
+ */
843
+ export function fromPromise<A>(promise: Lazy<Promise<A>>, __tsplusTrace?: string): FIO<unknown, A> {
844
+ return IO.fromPromiseCatch(promise, identity);
845
+ }
846
+
847
+ /**
848
+ * Create an IO that when executed will construct `promise` and wait for its result,
849
+ * errors will be handled using `onReject`
850
+ *
851
+ * @tsplus static fncts.io.IOOps fromPromiseCatch
875
852
  */
876
853
  export function fromPromiseCatch<E, A>(
877
854
  promise: Lazy<Promise<A>>,
@@ -885,16 +862,6 @@ export function fromPromiseCatch<E, A>(
885
862
  });
886
863
  }
887
864
 
888
- /**
889
- * Create an IO that when executed will construct `promise` and wait for its result,
890
- * errors will produce failure as `unknown`
891
- *
892
- * @tsplus static fncts.io.IOOps fromPromise
893
- */
894
- export function fromPromise<A>(promise: Lazy<Promise<A>>, __tsplusTrace?: string): FIO<unknown, A> {
895
- return IO.fromPromiseCatch(promise, identity);
896
- }
897
-
898
865
  /**
899
866
  * Like fromPromise but produces a defect in case of errors
900
867
  *
@@ -920,6 +887,13 @@ export function get<R, E, A>(ma: IO<R, E, Maybe<A>>, __tsplusTrace?: string): IO
920
887
  );
921
888
  }
922
889
 
890
+ /**
891
+ * @tsplus static fncts.io.IOOps getFiberRefs
892
+ */
893
+ export function getFiberRefs(__tsplusTrace?: string): UIO<FiberRefs> {
894
+ return IO.withFiberRuntime((fiberState) => IO.succeed(fiberState.getFiberRefs()));
895
+ }
896
+
923
897
  /**
924
898
  * Extracts the optional value, or returns the given 'orElse'.
925
899
  *
@@ -942,15 +916,6 @@ export function getOrElseIO<R1, E1, B>(orElse: Lazy<IO<R1, E1, B>>, __tsplusTrac
942
916
  };
943
917
  }
944
918
 
945
- /**
946
- * Lifts a Maybe into an IO. If the option is `Nothing`, fail with `onNothing`.
947
- *
948
- * @tsplus static fncts.io.IOOps getOrFailWith
949
- */
950
- export function getOrFailWith<E, A>(maybe: Maybe<A>, onNothing: Lazy<E>, __tsplusTrace?: string): FIO<E, A> {
951
- return IO.defer(maybe.match(() => IO.fail(onNothing), IO.succeedNow));
952
- }
953
-
954
919
  /**
955
920
  * Lifts a Maybe into a IO, if the Maybe is `Nothing` it fails with Unit.
956
921
  *
@@ -961,10 +926,12 @@ export function getOrFailUnit<A>(option: Maybe<A>, __tsplusTrace?: string): FIO<
961
926
  }
962
927
 
963
928
  /**
964
- * @tsplus static fncts.io.IOOps getFiberRefs
929
+ * Lifts a Maybe into an IO. If the option is `Nothing`, fail with `onNothing`.
930
+ *
931
+ * @tsplus static fncts.io.IOOps getOrFailWith
965
932
  */
966
- export function getFiberRefs(__tsplusTrace?: string): UIO<FiberRefs> {
967
- return IO.withFiberRuntime((fiberState) => IO.succeed(fiberState.getFiberRefs()));
933
+ export function getOrFailWith<E, A>(maybe: Maybe<A>, onNothing: Lazy<E>, __tsplusTrace?: string): FIO<E, A> {
934
+ return IO.defer(maybe.match(() => IO.fail(onNothing), IO.succeedNow));
968
935
  }
969
936
 
970
937
  /**
@@ -988,6 +955,7 @@ export function halt(e: Lazy<unknown>, __tsplusTrace?: string): UIO<never> {
988
955
  export function haltNow(e: unknown, __tsplusTrace?: string): UIO<never> {
989
956
  return IO.failCauseNow(Cause.halt(e, Trace.none), __tsplusTrace);
990
957
  }
958
+
991
959
  /**
992
960
  * @tsplus pipeable fncts.io.IO ifIO
993
961
  */
@@ -1001,23 +969,11 @@ export function ifIO<R1, E1, B, R2, E2, C>(
1001
969
  };
1002
970
  }
1003
971
 
1004
- /**
1005
- * @tsplus static fncts.io.IOOps if
1006
- */
1007
- export function cond<R, E, A, R1, E1, A1>(
1008
- b: boolean,
1009
- onTrue: Lazy<IO<R, E, A>>,
1010
- onFalse: Lazy<IO<R1, E1, A1>>,
1011
- __tsplusTrace?: string,
1012
- ): IO<R | R1, E | E1, A | A1> {
1013
- return IO.succeedNow(b).ifIO(onTrue, onFalse);
1014
- }
1015
-
1016
972
  /**
1017
973
  * @tsplus getter fncts.io.IO ignore
1018
974
  */
1019
- export function ignore<R, E, A>(fa: IO<R, E, A>, __tsplusTrace?: string): URIO<R, void> {
1020
- return fa.match(
975
+ export function ignore<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): URIO<R, void> {
976
+ return self.match(
1021
977
  () => undefined,
1022
978
  () => undefined,
1023
979
  );
@@ -1028,20 +984,19 @@ export function ignore<R, E, A>(fa: IO<R, E, A>, __tsplusTrace?: string): URIO<R
1028
984
  *
1029
985
  * @tsplus getter fncts.io.IO isFailure
1030
986
  */
1031
- export function isFailure<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, boolean> {
1032
- return ma.match(
987
+ export function isFailure<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, boolean> {
988
+ return self.match(
1033
989
  () => true,
1034
990
  () => false,
1035
991
  );
1036
992
  }
1037
-
1038
993
  /**
1039
994
  * Folds a `IO` to a boolean describing whether or not it is a success
1040
995
  *
1041
996
  * @tsplus getter fncts.io.IO isSuccess
1042
997
  */
1043
- export function isSuccess<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, boolean> {
1044
- return ma.match(
998
+ export function isSuccess<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, boolean> {
999
+ return self.match(
1045
1000
  () => false,
1046
1001
  () => true,
1047
1002
  );
@@ -1071,15 +1026,6 @@ export function iterate<R, E, A>(
1071
1026
  return cont(initial) ? body(initial).flatMap((a) => IO.iterate(a, cont, body)) : IO.succeedNow(initial);
1072
1027
  }
1073
1028
 
1074
- /**
1075
- * Returns an IO with the value on the left part.
1076
- *
1077
- * @tsplus static fncts.io.IOOps left
1078
- */
1079
- export function left<A>(a: Lazy<A>, __tsplusTrace?: string): UIO<Either<A, never>> {
1080
- return IO.succeed(a).flatMap((a) => IO.succeedNow(Either.left(a)));
1081
- }
1082
-
1083
1029
  /**
1084
1030
  * @tsplus getter fncts.io.IO just
1085
1031
  */
@@ -1090,6 +1036,15 @@ export function just<R, E, A>(self: IO<R, E, Maybe<A>>): IO<R, Maybe<E>, A> {
1090
1036
  );
1091
1037
  }
1092
1038
 
1039
+ /**
1040
+ * Returns an IO with the value on the left part.
1041
+ *
1042
+ * @tsplus static fncts.io.IOOps left
1043
+ */
1044
+ export function left<A>(a: Lazy<A>, __tsplusTrace?: string): UIO<Either<A, never>> {
1045
+ return IO.succeed(a).flatMap((a) => IO.succeedNow(Either.left(a)));
1046
+ }
1047
+
1093
1048
  /**
1094
1049
  * @tsplus static fncts.io.IOOps log
1095
1050
  */
@@ -1100,13 +1055,6 @@ export function log(message: Lazy<string>, __tsplusTrace?: string): UIO<void> {
1100
1055
  });
1101
1056
  }
1102
1057
 
1103
- /**
1104
- * @tsplus static fncts.io.IOOps show
1105
- */
1106
- export function show(message: Lazy<unknown>, options?: Partial<ShowOptions>, __tsplusTrace?: string): UIO<void> {
1107
- return IO.log(showWithOptions(message, options));
1108
- }
1109
-
1110
1058
  /**
1111
1059
  * Loops with the specified effectual function, collecting the results into a
1112
1060
  * list. The moral equivalent of:
@@ -1174,8 +1122,8 @@ export function loopUnit<A, R, E>(
1174
1122
  * @tsplus pipeable fncts.io.IO map
1175
1123
  */
1176
1124
  export function map<A, B>(f: (a: A) => B, __tsplusTrace?: string) {
1177
- return <R, E>(fa: IO<R, E, A>): IO<R, E, B> => {
1178
- return fa.flatMap((a) => IO.succeedNow(f(a)));
1125
+ return <R, E>(self: IO<R, E, A>): IO<R, E, B> => {
1126
+ return self.flatMap((a) => IO.succeedNow(f(a)));
1179
1127
  };
1180
1128
  }
1181
1129
 
@@ -1189,23 +1137,11 @@ export function map<A, B>(f: (a: A) => B, __tsplusTrace?: string) {
1189
1137
  * @tsplus pipeable fncts.io.IO mapError
1190
1138
  */
1191
1139
  export function mapError<E, E1>(f: (e: E) => E1, __tsplusTrace?: string) {
1192
- return <R, A>(fea: IO<R, E, A>): IO<R, E1, A> => {
1193
- return fea.matchCauseIO((cause) => IO.failCauseNow(cause.map(f)), IO.succeedNow);
1140
+ return <R, A>(self: IO<R, E, A>): IO<R, E1, A> => {
1141
+ return self.matchCauseIO((cause) => IO.failCauseNow(cause.map(f)), IO.succeedNow);
1194
1142
  };
1195
1143
  }
1196
1144
 
1197
- /**
1198
- * @tsplus static fncts.io.IOOps mapTryCatch
1199
- */
1200
- export function mapTryCatch<R, E, A, E1, B>(
1201
- io: IO<R, E, A>,
1202
- f: (a: A) => B,
1203
- onThrow: (u: unknown) => E1,
1204
- __tsplusTrace?: string,
1205
- ): IO<R, E | E1, B> {
1206
- return io.flatMap((a) => IO.tryCatch(() => f(a), onThrow));
1207
- }
1208
-
1209
1145
  /**
1210
1146
  * Returns an IO with its full cause of failure mapped using
1211
1147
  * the specified function. This can be used to transform errors
@@ -1214,8 +1150,34 @@ export function mapTryCatch<R, E, A, E1, B>(
1214
1150
  * @tsplus pipeable fncts.io.IO mapErrorCause
1215
1151
  */
1216
1152
  export function mapErrorCause<E, E1>(f: (cause: Cause<E>) => Cause<E1>, __tsplusTrace?: string) {
1217
- return <R, A>(ma: IO<R, E, A>): IO<R, E1, A> => {
1218
- return ma.matchCauseIO((cause) => IO.failCauseNow(f(cause)), IO.succeedNow);
1153
+ return <R, A>(self: IO<R, E, A>): IO<R, E1, A> => {
1154
+ return self.matchCauseIO((cause) => IO.failCauseNow(f(cause)), IO.succeedNow);
1155
+ };
1156
+ }
1157
+
1158
+ /**
1159
+ * @tsplus static fncts.io.IOOps mapTryCatch
1160
+ * @tsplus pipeable fncts.io.IO mapTryCatch
1161
+ */
1162
+ export function mapTryCatch<A, E1, B>(f: (a: A) => B, onThrow: (u: unknown) => E1, __tsplusTrace?: string) {
1163
+ return <R, E>(self: IO<R, E, A>): IO<R, E | E1, B> => {
1164
+ return self.flatMap((a) => IO.tryCatch(() => f(a), onThrow));
1165
+ };
1166
+ }
1167
+
1168
+ /**
1169
+ * Folds over the failure value or the success value to yield an IO that
1170
+ * does not fail, but succeeds with the value returned by the left or right
1171
+ * function passed to `match_`.
1172
+ *
1173
+ * @tsplus pipeable fncts.io.IO match
1174
+ */
1175
+ export function match<E, A, B, C>(onFailure: (e: E) => B, onSuccess: (a: A) => C, __tsplusTrace?: string) {
1176
+ return <R>(self: IO<R, E, A>): IO<R, never, B | C> => {
1177
+ return self.matchIO(
1178
+ (e) => IO.succeedNow(onFailure(e)),
1179
+ (a) => IO.succeedNow(onSuccess(a)),
1180
+ );
1219
1181
  };
1220
1182
  }
1221
1183
 
@@ -1270,22 +1232,6 @@ export function matchIO<R1, R2, E, E1, E2, A, A1, A2>(
1270
1232
  };
1271
1233
  }
1272
1234
 
1273
- /**
1274
- * Folds over the failure value or the success value to yield an IO that
1275
- * does not fail, but succeeds with the value returned by the left or right
1276
- * function passed to `match_`.
1277
- *
1278
- * @tsplus pipeable fncts.io.IO match
1279
- */
1280
- export function match<E, A, B, C>(onFailure: (e: E) => B, onSuccess: (a: A) => C, __tsplusTrace?: string) {
1281
- return <R>(self: IO<R, E, A>): IO<R, never, B | C> => {
1282
- return self.matchIO(
1283
- (e) => IO.succeedNow(onFailure(e)),
1284
- (a) => IO.succeedNow(onSuccess(a)),
1285
- );
1286
- };
1287
- }
1288
-
1289
1235
  /**
1290
1236
  * A version of `matchIO` that gives you the (optional) trace of the error.
1291
1237
  *
@@ -1296,8 +1242,8 @@ export function matchTraceIO<E, A, R1, E1, A1, R2, E2, A2>(
1296
1242
  onSuccess: (a: A) => IO<R2, E2, A2>,
1297
1243
  __tsplusTrace?: string,
1298
1244
  ) {
1299
- return <R>(ma: IO<R, E, A>): IO<R | R1 | R2, E1 | E2, A1 | A2> => {
1300
- return ma.matchCauseIO(
1245
+ return <R>(self: IO<R, E, A>): IO<R | R1 | R2, E1 | E2, A1 | A2> => {
1246
+ return self.matchCauseIO(
1301
1247
  (cause) => cause.failureTraceOrCause.match(([e, trace]) => onFailure(e, trace), IO.failCauseNow),
1302
1248
  onSuccess,
1303
1249
  );
@@ -1307,15 +1253,15 @@ export function matchTraceIO<E, A, R1, E1, A1, R2, E2, A2>(
1307
1253
  /**
1308
1254
  * @tsplus getter fncts.io.IO maybe
1309
1255
  */
1310
- export function maybe<R, E, A>(io: IO<R, E, A>, __tsplusTrace?: string): URIO<R, Maybe<A>> {
1311
- return io.match(() => Nothing(), Maybe.just);
1256
+ export function maybe<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): URIO<R, Maybe<A>> {
1257
+ return self.match(() => Nothing(), Maybe.just);
1312
1258
  }
1313
1259
 
1314
1260
  /**
1315
1261
  * @tsplus getter fncts.io.IO merge
1316
1262
  */
1317
- export function merge<R, E, A>(io: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, A | E> {
1318
- return io.matchIO(IO.succeedNow, IO.succeedNow);
1263
+ export function merge<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, A | E> {
1264
+ return self.matchIO(IO.succeedNow, IO.succeedNow);
1319
1265
  }
1320
1266
 
1321
1267
  /**
@@ -1324,12 +1270,39 @@ export function merge<R, E, A>(io: IO<R, E, A>, __tsplusTrace?: string): IO<R, n
1324
1270
  * @tsplus static fncts.io.IOOps mergeAll
1325
1271
  */
1326
1272
  export function mergeAll<R, E, A, B>(
1327
- fas: Iterable<IO<R, E, A>>,
1273
+ ios: Iterable<IO<R, E, A>>,
1328
1274
  b: B,
1329
1275
  f: (b: B, a: A) => B,
1330
1276
  __tsplusTrace?: string,
1331
1277
  ): IO<R, E, B> {
1332
- return fas.foldLeft(IO.succeed(b) as IO<R, E, B>, (b, a) => b.zipWith(a, f));
1278
+ return ios.foldLeft(IO.succeed(b) as IO<R, E, B>, (b, a) => b.zipWith(a, f));
1279
+ }
1280
+
1281
+ /**
1282
+ * @tsplus static fncts.io.IOOps refailCause
1283
+ */
1284
+ export function refailCause<E>(cause: Lazy<Cause<E>>, __tsplusTrace?: string): FIO<E, never> {
1285
+ const io = new IOPrimitive(IOTag.Fail) as any;
1286
+ io.i0 = cause;
1287
+ io.trace = __tsplusTrace;
1288
+ return io;
1289
+ }
1290
+
1291
+ /**
1292
+ * @tsplus static fncts.io.IOOps refailCauseNow
1293
+ */
1294
+ export function refailCauseNow<E>(cause: Cause<E>, __tsplusTrace?: string): FIO<E, never> {
1295
+ const io = new IOPrimitive(IOTag.Fail) as any;
1296
+ io.i0 = () => cause;
1297
+ io.trace = __tsplusTrace;
1298
+ return io;
1299
+ }
1300
+
1301
+ /**
1302
+ * @tsplus static fncts.io.IOOps show
1303
+ */
1304
+ export function show(message: Lazy<unknown>, options?: Partial<ShowOptions>, __tsplusTrace?: string): UIO<void> {
1305
+ return IO.log(showWithOptions(message, options));
1333
1306
  }
1334
1307
 
1335
1308
  /**
@@ -1337,13 +1310,59 @@ export function mergeAll<R, E, A, B>(
1337
1310
  */
1338
1311
  export const nothing = IO.succeedNow(Nothing());
1339
1312
 
1313
+ /**
1314
+ * Returns an `IO` that submerges an `Either` into the `IO`.
1315
+ *
1316
+ * @tsplus getter fncts.io.IO absolve
1317
+ */
1318
+ export function absolve<R, E, E1, A>(self: IO<R, E, Either<E1, A>>, __tsplusTrace?: string): IO<R, E | E1, A> {
1319
+ return self.flatMap((ea) => ea.match(IO.failNow, IO.succeedNow));
1320
+ }
1321
+
1322
+ /**
1323
+ * @tsplus static fncts.io.IOOps attempt
1324
+ */
1325
+ export function attempt<A>(effect: Lazy<A>, __tsplusTrace?: string): FIO<unknown, A> {
1326
+ return IO.defer(() => {
1327
+ try {
1328
+ return Exit.succeed(effect());
1329
+ } catch (u) {
1330
+ return IO.withFiberRuntime((fiberState) => {
1331
+ if (!fiberState.isFatal(u)) {
1332
+ throw new IOError(Cause.fail(u));
1333
+ } else {
1334
+ throw u;
1335
+ }
1336
+ });
1337
+ }
1338
+ });
1339
+ }
1340
+
1341
+ /**
1342
+ * Exposes all parallel errors in a single call
1343
+ *
1344
+ * @tsplus pipeable fncts.io.IO concurrentErrors
1345
+ */
1346
+ export function concurrentErrors(__tsplusTrace?: string) {
1347
+ return <R, E, A>(self: IO<R, E, A>): IO<R, List<E>, A> => {
1348
+ return self.matchCauseIO((cause) => {
1349
+ const f = cause.failures;
1350
+ if (f.length === 0) {
1351
+ return IO.failCauseNow(cause as Cause<never>);
1352
+ } else {
1353
+ return IO.failNow(f);
1354
+ }
1355
+ }, IO.succeedNow);
1356
+ };
1357
+ }
1358
+
1340
1359
  /**
1341
1360
  * Converts an option on errors into an option on values.
1342
1361
  *
1343
1362
  * @tsplus getter fncts.io.IO optional
1344
1363
  */
1345
- export function optional<R, E, A>(ma: IO<R, Maybe<E>, A>, __tsplusTrace?: string): IO<R, E, Maybe<A>> {
1346
- return ma.matchIO(
1364
+ export function optional<R, E, A>(self: IO<R, Maybe<E>, A>, __tsplusTrace?: string): IO<R, E, Maybe<A>> {
1365
+ return self.matchIO(
1347
1366
  (me) => me.match(() => IO.succeedNow(Nothing()), IO.failNow),
1348
1367
  (a) => IO.succeedNow(Just(a)),
1349
1368
  );
@@ -1358,9 +1377,9 @@ export function optional<R, E, A>(ma: IO<R, Maybe<E>, A>, __tsplusTrace?: string
1358
1377
  * @tsplus pipeable fncts.io.IO or
1359
1378
  * @tsplus pipeable-operator fncts.io.IO ||
1360
1379
  */
1361
- export function or<R1, E1>(mb: IO<R1, E1, boolean>, __tsplusTrace?: string) {
1362
- return <R, E>(ma: IO<R, E, boolean>): IO<R | R1, E | E1, boolean> => {
1363
- return ma.flatMap((b) => (b ? IO.succeedNow(true) : mb));
1380
+ export function or<R1, E1>(or: IO<R1, E1, boolean>, __tsplusTrace?: string) {
1381
+ return <R, E>(self: IO<R, E, boolean>): IO<R | R1, E | E1, boolean> => {
1382
+ return self.flatMap((b) => (b ? IO.succeedNow(true) : or));
1364
1383
  };
1365
1384
  }
1366
1385
 
@@ -1368,8 +1387,8 @@ export function or<R1, E1>(mb: IO<R1, E1, boolean>, __tsplusTrace?: string) {
1368
1387
  * @tsplus pipeable fncts.io.IO orElse
1369
1388
  */
1370
1389
  export function orElse<R1, E1, A1>(that: Lazy<IO<R1, E1, A1>>, __tsplusTrace?: string) {
1371
- return <R, E, A>(ma: IO<R, E, A>): IO<R | R1, E1, A | A1> => {
1372
- return ma.tryOrElse(that, IO.succeedNow);
1390
+ return <R, E, A>(self: IO<R, E, A>): IO<R | R1, E1, A | A1> => {
1391
+ return self.tryOrElse(that, IO.succeedNow);
1373
1392
  };
1374
1393
  }
1375
1394
 
@@ -1386,8 +1405,8 @@ export function orElseEither<R1, E1, A1>(that: Lazy<IO<R1, E1, A1>>, __tsplusTra
1386
1405
  * @tsplus pipeable fncts.io.IO orElseFail
1387
1406
  */
1388
1407
  export function orElseFail<E1>(e: Lazy<E1>, __tsplusTrace?: string) {
1389
- return <R, E, A>(ma: IO<R, E, A>): IO<R, E1, A> => {
1390
- return ma.orElse(IO.fail(e));
1408
+ return <R, E, A>(self: IO<R, E, A>): IO<R, E1, A> => {
1409
+ return self.orElse(IO.fail(e));
1391
1410
  };
1392
1411
  }
1393
1412
 
@@ -1395,8 +1414,8 @@ export function orElseFail<E1>(e: Lazy<E1>, __tsplusTrace?: string) {
1395
1414
  * @tsplus pipeable fncts.io.IO orElseMaybe
1396
1415
  */
1397
1416
  export function orElseMaybe<R1, E1, A1>(that: Lazy<IO<R1, Maybe<E1>, A1>>, __tsplusTrace?: string) {
1398
- return <R, E, A>(ma: IO<R, Maybe<E>, A>): IO<R | R1, Maybe<E | E1>, A | A1> => {
1399
- return ma.catchAll((me) => me.match(that, (e) => IO.fail(Just(e))));
1417
+ return <R, E, A>(self: IO<R, Maybe<E>, A>): IO<R | R1, Maybe<E | E1>, A | A1> => {
1418
+ return self.catchAll((me) => me.match(that, (e) => IO.fail(Just(e))));
1400
1419
  };
1401
1420
  }
1402
1421
 
@@ -1404,49 +1423,31 @@ export function orElseMaybe<R1, E1, A1>(that: Lazy<IO<R1, Maybe<E1>, A1>>, __tsp
1404
1423
  * @tsplus pipeable fncts.io.IO orElseSucceed
1405
1424
  */
1406
1425
  export function orElseSucceed<A1>(a: Lazy<A1>, __tsplusTrace?: string) {
1407
- return <R, E, A>(ma: IO<R, E, A>): IO<R, E, A | A1> => {
1408
- return ma.orElse(IO.succeed(a));
1426
+ return <R, E, A>(self: IO<R, E, A>): IO<R, E, A | A1> => {
1427
+ return self.orElse(IO.succeed(a));
1409
1428
  };
1410
1429
  }
1411
1430
 
1412
1431
  /**
1413
1432
  * @tsplus getter fncts.io.IO orHalt
1414
1433
  */
1415
- export function orHalt<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, A> {
1416
- return ma.orHaltWith(identity);
1434
+ export function orHalt<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, A> {
1435
+ return self.orHaltWith(identity);
1417
1436
  }
1418
1437
 
1419
1438
  /**
1420
1439
  * @tsplus getter fncts.io.IO orHaltKeep
1421
1440
  */
1422
- export function orHaltKeep<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, A> {
1423
- return ma.matchCauseIO((cause) => IO.failCauseNow(cause.flatMap(Cause.halt)), IO.succeedNow);
1441
+ export function orHaltKeep<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, A> {
1442
+ return self.matchCauseIO((cause) => IO.failCauseNow(cause.flatMap(Cause.halt)), IO.succeedNow);
1424
1443
  }
1425
1444
 
1426
1445
  /**
1427
1446
  * @tsplus pipeable fncts.io.IO orHaltWith
1428
1447
  */
1429
1448
  export function orHaltWith<E>(f: (e: E) => unknown, __tsplusTrace?: string) {
1430
- return <R, A>(ma: IO<R, E, A>): IO<R, never, A> => {
1431
- return ma.matchIO((e) => IO.haltNow(f(e)), IO.succeedNow);
1432
- };
1433
- }
1434
-
1435
- /**
1436
- * Exposes all parallel errors in a single call
1437
- *
1438
- * @tsplus pipeable fncts.io.IO concurrentErrors
1439
- */
1440
- export function concurrentErrors(__tsplusTrace?: string) {
1441
- return <R, E, A>(io: IO<R, E, A>): IO<R, List<E>, A> => {
1442
- return io.matchCauseIO((cause) => {
1443
- const f = cause.failures;
1444
- if (f.length === 0) {
1445
- return IO.failCauseNow(cause as Cause<never>);
1446
- } else {
1447
- return IO.failNow(f);
1448
- }
1449
- }, IO.succeedNow);
1449
+ return <R, A>(self: IO<R, E, A>): IO<R, never, A> => {
1450
+ return self.matchIO((e) => IO.haltNow(f(e)), IO.succeedNow);
1450
1451
  };
1451
1452
  }
1452
1453
 
@@ -1470,8 +1471,8 @@ export function partition<R, E, A, B>(
1470
1471
  * @tsplus pipeable fncts.io.IO refineOrHalt
1471
1472
  */
1472
1473
  export function refineOrHalt<E, E1>(pf: (e: E) => Maybe<E1>, __tsplusTrace?: string) {
1473
- return <R, A>(fa: IO<R, E, A>): IO<R, E1, A> => {
1474
- return fa.refineOrHaltWith(pf, identity);
1474
+ return <R, A>(self: IO<R, E, A>): IO<R, E1, A> => {
1475
+ return self.refineOrHaltWith(pf, identity);
1475
1476
  };
1476
1477
  }
1477
1478
 
@@ -1482,8 +1483,8 @@ export function refineOrHalt<E, E1>(pf: (e: E) => Maybe<E1>, __tsplusTrace?: str
1482
1483
  * @tsplus pipeable fncts.io.IO refineOrHaltWith
1483
1484
  */
1484
1485
  export function refineOrHaltWith<E, E1>(pf: (e: E) => Maybe<E1>, f: (e: E) => unknown, __tsplusTrace?: string) {
1485
- return <R, A>(fa: IO<R, E, A>): IO<R, E1, A> => {
1486
- return fa.catchAll((e) => pf(e).match(() => IO.haltNow(f(e)), IO.failNow));
1486
+ return <R, A>(self: IO<R, E, A>): IO<R, E1, A> => {
1487
+ return self.catchAll((e) => pf(e).match(() => IO.haltNow(f(e)), IO.failNow));
1487
1488
  };
1488
1489
  }
1489
1490
 
@@ -1494,8 +1495,8 @@ export function refineOrHaltWith<E, E1>(pf: (e: E) => Maybe<E1>, f: (e: E) => un
1494
1495
  * @tsplus pipeable fncts.io.IO reject
1495
1496
  */
1496
1497
  export function reject<A, E1>(pf: (a: A) => Maybe<E1>, __tsplusTrace?: string) {
1497
- return <R, E>(fa: IO<R, E, A>): IO<R, E | E1, A> => {
1498
- return fa.rejectIO((a) => pf(a).map(IO.failNow));
1498
+ return <R, E>(self: IO<R, E, A>): IO<R, E | E1, A> => {
1499
+ return self.rejectIO((a) => pf(a).map(IO.failNow));
1499
1500
  };
1500
1501
  }
1501
1502
 
@@ -1507,8 +1508,8 @@ export function reject<A, E1>(pf: (a: A) => Maybe<E1>, __tsplusTrace?: string) {
1507
1508
  * @tsplus pipeable fncts.io.IO rejectIO
1508
1509
  */
1509
1510
  export function rejectIO<A, R1, E1>(pf: (a: A) => Maybe<IO<R1, E1, E1>>, __tsplusTrace?: string) {
1510
- return <R, E>(fa: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1511
- return fa.flatMap((a) =>
1511
+ return <R, E>(self: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1512
+ return self.flatMap((a) =>
1512
1513
  pf(a).match(
1513
1514
  () => IO.succeedNow(a),
1514
1515
  (io) => io.flatMap(IO.failNow),
@@ -1523,8 +1524,21 @@ export function rejectIO<A, R1, E1>(pf: (a: A) => Maybe<IO<R1, E1, E1>>, __tsplu
1523
1524
  * @tsplus pipeable fncts.io.IO repeatN
1524
1525
  */
1525
1526
  export function repeatN_(n: number, __tsplusTrace?: string) {
1526
- return <R, E, A>(ma: IO<R, E, A>): IO<R, E, A> => {
1527
- return ma.flatMap((a) => (n <= 0 ? IO.succeed(a) : ma.repeatN(n - 1)));
1527
+ return <R, E, A>(self: IO<R, E, A>): IO<R, E, A> => {
1528
+ return self.flatMap((a) => {
1529
+ let i = n;
1530
+ let s = a;
1531
+ return IO.whileLoop(
1532
+ i > 0,
1533
+ () => {
1534
+ i -= 1;
1535
+ return self;
1536
+ },
1537
+ (a) => {
1538
+ s = a;
1539
+ },
1540
+ ).as(s);
1541
+ });
1528
1542
  };
1529
1543
  }
1530
1544
 
@@ -1534,8 +1548,8 @@ export function repeatN_(n: number, __tsplusTrace?: string) {
1534
1548
  * @tsplus pipeable fncts.io.IO repeatUntil
1535
1549
  */
1536
1550
  export function repeatUntil<A>(f: (a: A) => boolean, __tsplusTrace?: string) {
1537
- return <R, E>(ma: IO<R, E, A>): IO<R, E, A> => {
1538
- return ma.repeatUntilIO((a) => IO.succeedNow(f(a)));
1551
+ return <R, E>(self: IO<R, E, A>): IO<R, E, A> => {
1552
+ return self.repeatUntilIO((a) => IO.succeedNow(f(a)));
1539
1553
  };
1540
1554
  }
1541
1555
 
@@ -1545,8 +1559,8 @@ export function repeatUntil<A>(f: (a: A) => boolean, __tsplusTrace?: string) {
1545
1559
  * @tsplus pipeable fncts.io.IO repeatUntilIO
1546
1560
  */
1547
1561
  export function repeatUntilIO<A, R1, E1>(f: (a: A) => IO<R1, E1, boolean>, __tsplusTrace?: string) {
1548
- return <R, E>(ma: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1549
- return ma.flatMap((a) => f(a).flatMap((b) => (b ? IO.succeed(a) : ma.repeatUntilIO(f))));
1562
+ return <R, E>(self: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1563
+ return self.flatMap((a) => f(a).flatMap((b) => (b ? IO.succeed(a) : self.repeatUntilIO(f))));
1550
1564
  };
1551
1565
  }
1552
1566
 
@@ -1556,8 +1570,8 @@ export function repeatUntilIO<A, R1, E1>(f: (a: A) => IO<R1, E1, boolean>, __tsp
1556
1570
  * @tsplus pipeable fncts.io.IO repeatWhile
1557
1571
  */
1558
1572
  export function repeatWhile<A>(f: (a: A) => boolean, __tsplusTrace?: string) {
1559
- return <R, E>(ma: IO<R, E, A>): IO<R, E, A> => {
1560
- return ma.repeatWhileIO((a) => IO.succeedNow(f(a)));
1573
+ return <R, E>(self: IO<R, E, A>): IO<R, E, A> => {
1574
+ return self.repeatWhileIO((a) => IO.succeedNow(f(a)));
1561
1575
  };
1562
1576
  }
1563
1577
 
@@ -1567,8 +1581,8 @@ export function repeatWhile<A>(f: (a: A) => boolean, __tsplusTrace?: string) {
1567
1581
  * @tsplus pipeable fncts.io.IO repeatWhileIO
1568
1582
  */
1569
1583
  export function repeatWhileIO<A, R1, E1>(f: (a: A) => IO<R1, E1, boolean>, __tsplusTrace?: string) {
1570
- return <R, E>(ma: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1571
- return ma.flatMap((a) => f(a).flatMap((b) => (b ? ma.repeatWhileIO(f) : IO.succeed(a))));
1584
+ return <R, E>(self: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1585
+ return self.flatMap((a) => f(a).flatMap((b) => (b ? self.repeatWhileIO(f) : IO.succeed(a))));
1572
1586
  };
1573
1587
  }
1574
1588
 
@@ -1576,8 +1590,8 @@ export function repeatWhileIO<A, R1, E1>(f: (a: A) => IO<R1, E1, boolean>, __tsp
1576
1590
  * @tsplus pipeable fncts.io.IO replicate
1577
1591
  */
1578
1592
  export function replicate(n: number, __tsplusTrace?: string) {
1579
- return <R, E, A>(self: IO<R, E, A>): ImmutableArray<IO<R, E, A>> => {
1580
- return ImmutableArray.range(0, n).map(() => self);
1593
+ return <R, E, A>(self: IO<R, E, A>): ReadonlyArray<IO<R, E, A>> => {
1594
+ return Array.range(0, n).map(() => self);
1581
1595
  };
1582
1596
  }
1583
1597
 
@@ -1585,8 +1599,8 @@ export function replicate(n: number, __tsplusTrace?: string) {
1585
1599
  * @tsplus pipeable fncts.io.IO require
1586
1600
  */
1587
1601
  export function require<E>(error: Lazy<E>, __tsplusTrace?: string) {
1588
- return <R, A>(ma: IO<R, E, Maybe<A>>): IO<R, E, A> => {
1589
- return ma.flatMap((ma) => ma.match(() => IO.fail(error), IO.succeedNow));
1602
+ return <R, A>(self: IO<R, E, Maybe<A>>): IO<R, E, A> => {
1603
+ return self.flatMap((ma) => ma.match(() => IO.fail(error), IO.succeedNow));
1590
1604
  };
1591
1605
  }
1592
1606
 
@@ -1596,8 +1610,8 @@ export function require<E>(error: Lazy<E>, __tsplusTrace?: string) {
1596
1610
  *
1597
1611
  * @tsplus getter fncts.io.IO result
1598
1612
  */
1599
- export function result<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, Exit<E, A>> {
1600
- return ma.matchCauseIO(
1613
+ export function result<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, never, Exit<E, A>> {
1614
+ return self.matchCauseIO(
1601
1615
  (cause) => IO.succeedNow(Exit.failCause(cause)),
1602
1616
  (a) => IO.succeedNow(Exit.succeed(a)),
1603
1617
  );
@@ -1608,8 +1622,8 @@ export function result<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R,
1608
1622
  *
1609
1623
  * @tsplus getter fncts.io.IO resurrect
1610
1624
  */
1611
- export function resurrect<R, E, A>(io: IO<R, E, A>, __tsplusTrace?: string): IO<R, unknown, A> {
1612
- return io.unrefineWith(Maybe.just, identity);
1625
+ export function resurrect<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, unknown, A> {
1626
+ return self.unrefineWith(Maybe.just, identity);
1613
1627
  }
1614
1628
 
1615
1629
  /**
@@ -1618,8 +1632,8 @@ export function resurrect<R, E, A>(io: IO<R, E, A>, __tsplusTrace?: string): IO<
1618
1632
  * @tsplus pipeable fncts.io.IO retryUntil
1619
1633
  */
1620
1634
  export function retryUntil<E>(f: (e: E) => boolean, __tsplusTrace?: string) {
1621
- return <R, A>(fa: IO<R, E, A>): IO<R, E, A> => {
1622
- return fa.retryUntilIO((e) => IO.succeedNow(f(e)));
1635
+ return <R, A>(self: IO<R, E, A>): IO<R, E, A> => {
1636
+ return self.retryUntilIO((e) => IO.succeedNow(f(e)));
1623
1637
  };
1624
1638
  }
1625
1639
 
@@ -1629,8 +1643,8 @@ export function retryUntil<E>(f: (e: E) => boolean, __tsplusTrace?: string) {
1629
1643
  * @tsplus pipeable fncts.io.IO retryUntilIO
1630
1644
  */
1631
1645
  export function retryUntilIO<E, R1, E1>(f: (e: E) => IO<R1, E1, boolean>, __tsplusTrace?: string) {
1632
- return <R, A>(fa: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1633
- return fa.catchAll((e) => f(e).flatMap((b) => (b ? IO.failNow(e) : fa.retryUntilIO(f))));
1646
+ return <R, A>(self: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1647
+ return self.catchAll((e) => f(e).flatMap((b) => (b ? IO.failNow(e) : self.retryUntilIO(f))));
1634
1648
  };
1635
1649
  }
1636
1650
 
@@ -1640,8 +1654,8 @@ export function retryUntilIO<E, R1, E1>(f: (e: E) => IO<R1, E1, boolean>, __tspl
1640
1654
  * @tsplus pipeable fncts.io.IO retryWhile
1641
1655
  */
1642
1656
  export function retryWhile<E>(f: (e: E) => boolean, __tsplusTrace?: string) {
1643
- return <R, A>(fa: IO<R, E, A>): IO<R, E, A> => {
1644
- return fa.retryWhileIO((e) => IO.succeedNow(f(e)));
1657
+ return <R, A>(self: IO<R, E, A>): IO<R, E, A> => {
1658
+ return self.retryWhileIO((e) => IO.succeedNow(f(e)));
1645
1659
  };
1646
1660
  }
1647
1661
 
@@ -1651,8 +1665,8 @@ export function retryWhile<E>(f: (e: E) => boolean, __tsplusTrace?: string) {
1651
1665
  * @tsplus pipeable fncts.io.IO retryWhileIO
1652
1666
  */
1653
1667
  export function retryWhileIO<E, R1, E1>(f: (e: E) => IO<R1, E1, boolean>, __tsplusTrace?: string) {
1654
- return <R, A>(fa: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1655
- return fa.catchAll((e) => f(e).flatMap((b) => (b ? fa.retryWhileIO(f) : IO.fail(e))));
1668
+ return <R, A>(self: IO<R, E, A>): IO<R | R1, E | E1, A> => {
1669
+ return self.catchAll((e) => f(e).flatMap((b) => (b ? self.retryWhileIO(f) : IO.fail(e))));
1656
1670
  };
1657
1671
  }
1658
1672
 
@@ -1661,16 +1675,16 @@ export function retryWhileIO<E, R1, E1>(f: (e: E) => IO<R1, E1, boolean>, __tspl
1661
1675
  *
1662
1676
  * @tsplus getter fncts.io.IO sandbox
1663
1677
  */
1664
- export function sandbox<R, E, A>(fa: IO<R, E, A>, __tsplusTrace?: string): IO<R, Cause<E>, A> {
1665
- return fa.matchCauseIO(IO.failNow, IO.succeedNow);
1678
+ export function sandbox<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, Cause<E>, A> {
1679
+ return self.matchCauseIO(IO.failNow, IO.succeedNow);
1666
1680
  }
1667
1681
 
1668
1682
  /**
1669
1683
  * @tsplus pipeable fncts.io.IO sandboxWith
1670
1684
  */
1671
1685
  export function sandboxWith<R, E, A, E1>(f: (_: IO<R, Cause<E>, A>) => IO<R, Cause<E1>, A>, __tsplusTrace?: string) {
1672
- return (ma: IO<R, E, A>): IO<R, E1, A> => {
1673
- return f(ma.sandbox).unsandbox;
1686
+ return (self: IO<R, E, A>): IO<R, E1, A> => {
1687
+ return f(self.sandbox).unsandbox;
1674
1688
  };
1675
1689
  }
1676
1690
 
@@ -1688,18 +1702,6 @@ export function sequenceIterableDiscard<R, E, A>(as: Iterable<IO<R, E, A>>, __ts
1688
1702
  return IO.foreachDiscard(as, identity);
1689
1703
  }
1690
1704
 
1691
- /**
1692
- * Creates a `IO` that has succeeded with a pure value
1693
- *
1694
- * @tsplus static fncts.io.IOOps succeedNow
1695
- */
1696
- export function succeedNow<A>(value: A, __tsplusTrace?: string): IO<never, never, A> {
1697
- const io = new IOPrimitive(IOTag.SucceedNow) as any;
1698
- io.i0 = value;
1699
- io.trace = __tsplusTrace;
1700
- return io;
1701
- }
1702
-
1703
1705
  /**
1704
1706
  * Imports a total synchronous effect into a pure `IO` value.
1705
1707
  * The effect must not throw any exceptions. If you wonder if the effect
@@ -1715,6 +1717,18 @@ export function succeed<A>(effect: Lazy<A>, __tsplusTrace?: string): UIO<A> {
1715
1717
  return io;
1716
1718
  }
1717
1719
 
1720
+ /**
1721
+ * Creates a `IO` that has succeeded with a pure value
1722
+ *
1723
+ * @tsplus static fncts.io.IOOps succeedNow
1724
+ */
1725
+ export function succeedNow<A>(value: A, __tsplusTrace?: string): IO<never, never, A> {
1726
+ const io = new IOPrimitive(IOTag.SucceedNow) as any;
1727
+ io.i0 = value;
1728
+ io.trace = __tsplusTrace;
1729
+ return io;
1730
+ }
1731
+
1718
1732
  /**
1719
1733
  * @tsplus pipeable fncts.io.IO summarized
1720
1734
  */
@@ -1734,8 +1748,8 @@ export function summarized<R1, E1, B, C>(summary: IO<R1, E1, B>, f: (start: B, e
1734
1748
  *
1735
1749
  * @tsplus getter fncts.io.IO swap
1736
1750
  */
1737
- export function swap<R, E, A>(pab: IO<R, E, A>, __tsplusTrace?: string): IO<R, A, E> {
1738
- return pab.matchIO(IO.succeedNow, IO.failNow);
1751
+ export function swap<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): IO<R, A, E> {
1752
+ return self.matchIO(IO.succeedNow, IO.failNow);
1739
1753
  }
1740
1754
 
1741
1755
  /**
@@ -1744,66 +1758,7 @@ export function swap<R, E, A>(pab: IO<R, E, A>, __tsplusTrace?: string): IO<R, A
1744
1758
  * @tsplus pipeable fncts.io.IO swapWith
1745
1759
  */
1746
1760
  export function swapWith<R, E, A, R1, E1, A1>(f: (ma: IO<R, A, E>) => IO<R1, A1, E1>, __tsplusTrace?: string) {
1747
- return (fa: IO<R, E, A>): IO<R1, E1, A1> => f(fa.swap).swap;
1748
- }
1749
-
1750
- /**
1751
- * A more powerful variation of `timed` that allows specifying the clock.
1752
- *
1753
- * @tsplus pipeable fncts.io.IO timedWith
1754
- */
1755
- export function timedWith<R1, E1>(msTime: IO<R1, E1, number>, __tsplusTrace?: string) {
1756
- return <R, E, A>(ma: IO<R, E, A>): IO<R1 | R, E1 | E, readonly [number, A]> =>
1757
- ma.summarized(msTime, (start, end) => end - start);
1758
- }
1759
-
1760
- /**
1761
- * @tsplus static fncts.io.IOOps attempt
1762
- */
1763
- export function attempt<A>(effect: Lazy<A>, __tsplusTrace?: string): FIO<unknown, A> {
1764
- return IO.defer(() => {
1765
- try {
1766
- return Exit.succeed(effect());
1767
- } catch (u) {
1768
- return IO.withFiberRuntime((fiberState) => {
1769
- if (!fiberState.isFatal(u)) {
1770
- throw new IOError(Cause.fail(u));
1771
- } else {
1772
- throw u;
1773
- }
1774
- });
1775
- }
1776
- });
1777
- }
1778
-
1779
- /**
1780
- * Creates a `IO` that has succeeded with a pure value
1781
- *
1782
- * @tsplus static fncts.io.IOOps tryCatch
1783
- */
1784
- export function tryCatch<E, A>(effect: Lazy<A>, onThrow: (error: unknown) => E, __tsplusTrace?: string): FIO<E, A> {
1785
- return IO.defer(() => {
1786
- try {
1787
- return Exit.succeed(effect());
1788
- } catch (u) {
1789
- return IO.withFiberRuntime((fiberState) => {
1790
- if (!fiberState.isFatal(u)) {
1791
- throw new IOError(Cause.fail(onThrow(u)));
1792
- } else {
1793
- throw u;
1794
- }
1795
- });
1796
- }
1797
- });
1798
- }
1799
-
1800
- /**
1801
- * Returns an `IO` that submerges an `Either` into the `IO`.
1802
- *
1803
- * @tsplus getter fncts.io.IO absolve
1804
- */
1805
- export function absolve<R, E, E1, A>(ma: IO<R, E, Either<E1, A>>, __tsplusTrace?: string): IO<R, E | E1, A> {
1806
- return ma.flatMap((ea) => ea.match(IO.failNow, IO.succeedNow));
1761
+ return (self: IO<R, E, A>): IO<R1, E1, A1> => f(self.swap).swap;
1807
1762
  }
1808
1763
 
1809
1764
  /**
@@ -1827,8 +1782,8 @@ export function tap<A, R1, E1, B>(f: (a: A) => IO<R1, E1, B>, __tsplusTrace?: st
1827
1782
  * @tsplus pipeable fncts.io.IO tapCause
1828
1783
  */
1829
1784
  export function tapCause<R, E, E2>(f: (e: Cause<E2>) => IO<R, E, any>, __tsplusTrace?: string) {
1830
- return <R2, A2>(ma: IO<R2, E2, A2>): IO<R2 | R, E | E2, A2> => {
1831
- return ma.matchCauseIO((c) => f(c).flatMap(() => IO.failCauseNow(c)), IO.succeedNow);
1785
+ return <R2, A2>(self: IO<R2, E2, A2>): IO<R2 | R, E | E2, A2> => {
1786
+ return self.matchCauseIO((c) => f(c).flatMap(() => IO.failCauseNow(c)), IO.succeedNow);
1832
1787
  };
1833
1788
  }
1834
1789
 
@@ -1861,6 +1816,37 @@ export function tapErrorCause<E, R1, E1>(f: (e: Cause<E>) => IO<R1, E1, any>, __
1861
1816
  };
1862
1817
  }
1863
1818
 
1819
+ /**
1820
+ * A more powerful variation of `timed` that allows specifying the clock.
1821
+ *
1822
+ * @tsplus pipeable fncts.io.IO timedWith
1823
+ */
1824
+ export function timedWith<R1, E1>(msTime: IO<R1, E1, number>, __tsplusTrace?: string) {
1825
+ return <R, E, A>(self: IO<R, E, A>): IO<R1 | R, E1 | E, readonly [number, A]> =>
1826
+ self.summarized(msTime, (start, end) => end - start);
1827
+ }
1828
+
1829
+ /**
1830
+ * Creates a `IO` that has succeeded with a pure value
1831
+ *
1832
+ * @tsplus static fncts.io.IOOps tryCatch
1833
+ */
1834
+ export function tryCatch<E, A>(effect: Lazy<A>, onThrow: (error: unknown) => E, __tsplusTrace?: string): FIO<E, A> {
1835
+ return IO.defer(() => {
1836
+ try {
1837
+ return Exit.succeed(effect());
1838
+ } catch (u) {
1839
+ return IO.withFiberRuntime((fiberState) => {
1840
+ if (!fiberState.isFatal(u)) {
1841
+ throw new IOError(Cause.fail(onThrow(u)));
1842
+ } else {
1843
+ throw u;
1844
+ }
1845
+ });
1846
+ }
1847
+ });
1848
+ }
1849
+
1864
1850
  /**
1865
1851
  * @tsplus pipeable fncts.io.IO tryOrElse
1866
1852
  */
@@ -1869,8 +1855,8 @@ export function tryOrElse<A, R1, E1, A1, R2, E2, A2>(
1869
1855
  onSuccess: (a: A) => IO<R2, E2, A2>,
1870
1856
  __tsplusTrace?: string,
1871
1857
  ) {
1872
- return <R, E>(ma: IO<R, E, A>): IO<R | R1 | R2, E1 | E2, A1 | A2> => {
1873
- return ma.matchCauseIO((cause) => cause.keepDefects.match(that, IO.failCauseNow), onSuccess);
1858
+ return <R, E>(self: IO<R, E, A>): IO<R | R1 | R2, E1 | E2, A1 | A2> => {
1859
+ return self.matchCauseIO((cause) => cause.keepDefects.match(that, IO.failCauseNow), onSuccess);
1874
1860
  };
1875
1861
  }
1876
1862
 
@@ -1898,8 +1884,8 @@ export function unjust<R, E, A>(self: IO<R, Maybe<E>, A>, __tsplusTrace?: string
1898
1884
  * @tsplus pipeable fncts.io.IO unrefineWith
1899
1885
  */
1900
1886
  export function unrefineWith<E, E1, E2>(pf: (u: unknown) => Maybe<E1>, f: (e: E) => E2, __tsplusTrace?: string) {
1901
- return <R, A>(fa: IO<R, E, A>): IO<R, E1 | E2, A> => {
1902
- return fa.catchAllCause((cause) =>
1887
+ return <R, A>(self: IO<R, E, A>): IO<R, E1 | E2, A> => {
1888
+ return self.catchAllCause((cause) =>
1903
1889
  cause.find((c) => (c.isHalt() ? pf(c.value) : Nothing())).match(() => IO.failCauseNow(cause.map(f)), IO.failNow),
1904
1890
  );
1905
1891
  };
@@ -1910,8 +1896,8 @@ export function unrefineWith<E, E1, E2>(pf: (u: unknown) => Maybe<E1>, f: (e: E)
1910
1896
  *
1911
1897
  * @tsplus getter fncts.io.IO unsandbox
1912
1898
  */
1913
- export function unsandbox<R, E, A>(ma: IO<R, Cause<E>, A>, __tsplusTrace?: string): IO<R, E, A> {
1914
- return ma.mapErrorCause((cause) => cause.flatten);
1899
+ export function unsandbox<R, E, A>(self: IO<R, Cause<E>, A>, __tsplusTrace?: string): IO<R, E, A> {
1900
+ return self.mapErrorCause((cause) => cause.flatten);
1915
1901
  }
1916
1902
 
1917
1903
  /**
@@ -1935,12 +1921,29 @@ export function updateFiberRefs(
1935
1921
  */
1936
1922
  export const via: typeof pipe = pipe;
1937
1923
 
1924
+ /**
1925
+ * @tsplus static fncts.io.IOOps stackTrace
1926
+ */
1927
+ export function stackTrace(__tsplusTrace?: string): UIO<Trace> {
1928
+ return IO.withFiberRuntime((state) => IO.succeedNow(state.generateStackTrace()));
1929
+ }
1930
+
1931
+ /**
1932
+ * @tsplus static fncts.io.IOOps updateRuntimeFlags
1933
+ */
1934
+ export function updateRuntimeFlags(patch: RuntimeFlags.Patch, __tsplusTrace?: string): IO<never, never, void> {
1935
+ const io = new IOPrimitive(IOTag.UpdateRuntimeFlags) as any;
1936
+ io.i0 = patch;
1937
+ io.trace = __tsplusTrace;
1938
+ return io;
1939
+ }
1940
+
1938
1941
  /**
1939
1942
  * @tsplus pipeable fncts.io.IO when
1940
1943
  */
1941
1944
  export function when(b: Lazy<boolean>, __tsplusTrace?: string) {
1942
- return <R, E, A>(ma: IO<R, E, A>): IO<R, E, void> => {
1943
- return ma.whenIO(IO.succeed(b));
1945
+ return <R, E, A>(self: IO<R, E, A>): IO<R, E, void> => {
1946
+ return self.whenIO(IO.succeed(b));
1944
1947
  };
1945
1948
  }
1946
1949
 
@@ -1951,11 +1954,27 @@ export function when(b: Lazy<boolean>, __tsplusTrace?: string) {
1951
1954
  * @tsplus static fncts.io.IOOps whenIO
1952
1955
  */
1953
1956
  export function whenIO<R1, E1>(mb: IO<R1, E1, boolean>, __tsplusTrace?: string) {
1954
- return <R, E, A>(ma: IO<R, E, A>): IO<R1 | R, E | E1, Maybe<A>> => {
1955
- return mb.flatMap((b) => (b ? ma.asJust : IO.nothing));
1957
+ return <R, E, A>(self: IO<R, E, A>): IO<R1 | R, E | E1, Maybe<A>> => {
1958
+ return mb.flatMap((b) => (b ? self.asJust : IO.nothing));
1956
1959
  };
1957
1960
  }
1958
1961
 
1962
+ /**
1963
+ * @tsplus static fncts.io.IOOps whileLoop
1964
+ */
1965
+ export function whileLoop<R, E, A>(
1966
+ check: Lazy<boolean>,
1967
+ body: Lazy<IO<R, E, A>>,
1968
+ process: (a: A) => any,
1969
+ __tsPlusTrace?: string,
1970
+ ): IO<R, E, void> {
1971
+ const io = new IOPrimitive(IOTag.WhileLoop);
1972
+ io.i0 = check;
1973
+ io.i1 = body;
1974
+ io.i2 = process;
1975
+ return io as WhileLoop;
1976
+ }
1977
+
1959
1978
  /**
1960
1979
  * @tsplus static fncts.io.IOOps withFiberRuntime
1961
1980
  */
@@ -1969,25 +1988,6 @@ export function withFiberRuntime<R, E, A>(
1969
1988
  return io;
1970
1989
  }
1971
1990
 
1972
- /**
1973
- * @tsplus static fncts.io.IOOps updateRuntimeFlags
1974
- */
1975
- export function updateRuntimeFlags(patch: RuntimeFlags.Patch, __tsplusTrace?: string): IO<never, never, void> {
1976
- const io = new IOPrimitive(IOTag.UpdateRuntimeFlags) as any;
1977
- io.i0 = patch;
1978
- io.trace = __tsplusTrace;
1979
- return io;
1980
- }
1981
-
1982
- /**
1983
- * @tsplus static fncts.io.IOOps stackTrace
1984
- */
1985
- export function stackTrace(__tsplusTrace?: string): UIO<Trace> {
1986
- const io = new IOPrimitive(IOTag.GenerateStackTrace) as any;
1987
- io.trace = __tsplusTrace;
1988
- return io;
1989
- }
1990
-
1991
1991
  /**
1992
1992
  * Returns an effect that yields to the runtime system, starting on a fresh
1993
1993
  * stack. Manual use of this method can improve fairness, at the cost of
@@ -2006,6 +2006,28 @@ export function zip<R1, E1, B>(that: IO<R1, E1, B>, __tsplusTrace?: string) {
2006
2006
  };
2007
2007
  }
2008
2008
 
2009
+ /**
2010
+ * @tsplus pipeable fncts.io.IO zipLeft
2011
+ * @tsplus pipeable-operator fncts.io.IO <
2012
+ */
2013
+ export function zipLeft<R1, E1, B>(fb: IO<R1, E1, B>, __tsplusTrace?: string) {
2014
+ return <R, E, A>(self: IO<R, E, A>): IO<R1 | R, E1 | E, A> => {
2015
+ return self.flatMap((a) => fb.map(() => a));
2016
+ };
2017
+ }
2018
+
2019
+ /**
2020
+ * Combine two effectful actions, keeping only the result of the second
2021
+ *
2022
+ * @tsplus pipeable fncts.io.IO zipRight
2023
+ * @tsplus pipeable-operator fncts.io.IO >
2024
+ */
2025
+ export function zipRight<R1, E1, B>(fb: IO<R1, E1, B>, __tsplusTrace?: string) {
2026
+ return <R, E, A>(self: IO<R, E, A>): IO<R1 | R, E1 | E, B> => {
2027
+ return self.flatMap(() => fb);
2028
+ };
2029
+ }
2030
+
2009
2031
  /**
2010
2032
  * @tsplus pipeable fncts.io.IO zipWith
2011
2033
  */
@@ -2015,6 +2037,13 @@ export function zipWith<A, R1, E1, B, C>(that: IO<R1, E1, B>, f: (a: A, b: B) =>
2015
2037
  };
2016
2038
  }
2017
2039
 
2040
+ /**
2041
+ * @internal
2042
+ */
2043
+ export const __adapter = (_: any) => {
2044
+ return _;
2045
+ };
2046
+
2018
2047
  export class GenIO<R, E, A> {
2019
2048
  readonly _R!: () => R;
2020
2049
  readonly _E!: () => E;
@@ -2030,13 +2059,6 @@ export class GenIO<R, E, A> {
2030
2059
  }
2031
2060
  }
2032
2061
 
2033
- /**
2034
- * @internal
2035
- */
2036
- export const __adapter = (_: any) => {
2037
- return _;
2038
- };
2039
-
2040
2062
  const adapter = (_: any, __tsplusTrace?: string) => {
2041
2063
  return new GenIO(__adapter(_), __tsplusTrace);
2042
2064
  };