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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (779) hide show
  1. package/Bigint/dist/effect-Bigint.cjs.dev.js +125 -1
  2. package/Bigint/dist/effect-Bigint.cjs.mjs +6 -1
  3. package/Bigint/dist/effect-Bigint.cjs.prod.js +125 -1
  4. package/Bigint/dist/effect-Bigint.esm.js +111 -2
  5. package/Boolean/dist/effect-Boolean.cjs.dev.js +1 -1
  6. package/Boolean/dist/effect-Boolean.cjs.prod.js +1 -1
  7. package/Boolean/dist/effect-Boolean.esm.js +1 -1
  8. package/Brand/dist/effect-Brand.cjs.dev.js +3 -3
  9. package/Brand/dist/effect-Brand.cjs.prod.js +3 -3
  10. package/Cache/dist/effect-Cache.cjs.dev.js +32 -32
  11. package/Cache/dist/effect-Cache.cjs.prod.js +32 -32
  12. package/Cause/dist/effect-Cause.cjs.dev.js +17 -17
  13. package/Cause/dist/effect-Cause.cjs.mjs +1 -1
  14. package/Cause/dist/effect-Cause.cjs.prod.js +17 -17
  15. package/Cause/dist/effect-Cause.esm.js +4 -4
  16. package/Channel/dist/effect-Channel.cjs.dev.js +50 -50
  17. package/Channel/dist/effect-Channel.cjs.mjs +3 -3
  18. package/Channel/dist/effect-Channel.cjs.prod.js +50 -50
  19. package/Channel/dist/effect-Channel.esm.js +8 -8
  20. package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.dev.js +36 -36
  21. package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.prod.js +36 -36
  22. package/Chunk/dist/effect-Chunk.cjs.dev.js +3 -3
  23. package/Chunk/dist/effect-Chunk.cjs.prod.js +3 -3
  24. package/Clock/dist/effect-Clock.cjs.dev.js +16 -16
  25. package/Clock/dist/effect-Clock.cjs.prod.js +16 -16
  26. package/Config/dist/effect-Config.cjs.dev.js +11 -11
  27. package/Config/dist/effect-Config.cjs.prod.js +11 -11
  28. package/ConfigError/dist/effect-ConfigError.cjs.dev.js +4 -4
  29. package/ConfigError/dist/effect-ConfigError.cjs.prod.js +4 -4
  30. package/ConfigProvider/dist/effect-ConfigProvider.cjs.dev.js +17 -17
  31. package/ConfigProvider/dist/effect-ConfigProvider.cjs.prod.js +17 -17
  32. package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.dev.js +5 -5
  33. package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.prod.js +5 -5
  34. package/ConfigSecret/dist/effect-ConfigSecret.cjs.dev.js +4 -4
  35. package/ConfigSecret/dist/effect-ConfigSecret.cjs.prod.js +4 -4
  36. package/Console/dist/effect-Console.cjs.dev.js +35 -35
  37. package/Console/dist/effect-Console.cjs.prod.js +35 -35
  38. package/Context/dist/effect-Context.cjs.dev.js +3 -8
  39. package/Context/dist/effect-Context.cjs.prod.js +3 -8
  40. package/Data/dist/effect-Data.cjs.dev.js +141 -54
  41. package/Data/dist/effect-Data.cjs.mjs +2 -0
  42. package/Data/dist/effect-Data.cjs.prod.js +141 -54
  43. package/Data/dist/effect-Data.esm.js +51 -3
  44. package/DefaultServices/dist/effect-DefaultServices.cjs.dev.js +16 -16
  45. package/DefaultServices/dist/effect-DefaultServices.cjs.prod.js +16 -16
  46. package/Deferred/dist/effect-Deferred.cjs.dev.js +8 -8
  47. package/Deferred/dist/effect-Deferred.cjs.prod.js +8 -8
  48. package/Differ/dist/effect-Differ.cjs.dev.js +11 -11
  49. package/Differ/dist/effect-Differ.cjs.prod.js +11 -11
  50. package/Duration/dist/effect-Duration.cjs.dev.js +3 -3
  51. package/Duration/dist/effect-Duration.cjs.prod.js +3 -3
  52. package/Effect/dist/effect-Effect.cjs.dev.js +44 -44
  53. package/Effect/dist/effect-Effect.cjs.prod.js +44 -44
  54. package/Effectable/dist/effect-Effectable.cjs.dev.js +24 -14
  55. package/Effectable/dist/effect-Effectable.cjs.mjs +5 -4
  56. package/Effectable/dist/effect-Effectable.cjs.prod.js +24 -14
  57. package/Effectable/dist/effect-Effectable.esm.js +15 -5
  58. package/Either/dist/effect-Either.cjs.dev.js +3 -3
  59. package/Either/dist/effect-Either.cjs.prod.js +3 -3
  60. package/Encoding/dist/effect-Encoding.cjs.dev.js +3 -3
  61. package/Encoding/dist/effect-Encoding.cjs.prod.js +3 -3
  62. package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.dev.js +2 -2
  63. package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.prod.js +2 -2
  64. package/Exit/dist/effect-Exit.cjs.dev.js +8 -8
  65. package/Exit/dist/effect-Exit.cjs.prod.js +8 -8
  66. package/Fiber/dist/effect-Fiber.cjs.dev.js +29 -29
  67. package/Fiber/dist/effect-Fiber.cjs.prod.js +29 -29
  68. package/FiberId/dist/effect-FiberId.cjs.dev.js +5 -5
  69. package/FiberId/dist/effect-FiberId.cjs.prod.js +5 -5
  70. package/FiberRef/dist/effect-FiberRef.cjs.dev.js +29 -29
  71. package/FiberRef/dist/effect-FiberRef.cjs.prod.js +29 -29
  72. package/FiberRefs/dist/effect-FiberRefs.cjs.dev.js +9 -9
  73. package/FiberRefs/dist/effect-FiberRefs.cjs.prod.js +9 -9
  74. package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.dev.js +10 -10
  75. package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.prod.js +10 -10
  76. package/GroupBy/dist/effect-GroupBy.cjs.dev.js +42 -42
  77. package/GroupBy/dist/effect-GroupBy.cjs.prod.js +42 -42
  78. package/HashMap/dist/effect-HashMap.cjs.dev.js +20 -20
  79. package/HashMap/dist/effect-HashMap.cjs.prod.js +20 -20
  80. package/HashSet/dist/effect-HashSet.cjs.dev.js +20 -20
  81. package/HashSet/dist/effect-HashSet.cjs.prod.js +20 -20
  82. package/KeyedPool/dist/effect-KeyedPool.cjs.dev.js +33 -33
  83. package/KeyedPool/dist/effect-KeyedPool.cjs.prod.js +33 -33
  84. package/Layer/dist/effect-Layer.cjs.dev.js +32 -32
  85. package/Layer/dist/effect-Layer.cjs.prod.js +32 -32
  86. package/List/dist/effect-List.cjs.dev.js +3 -3
  87. package/List/dist/effect-List.cjs.prod.js +3 -3
  88. package/LogLevel/dist/effect-LogLevel.cjs.dev.js +8 -8
  89. package/LogLevel/dist/effect-LogLevel.cjs.prod.js +8 -8
  90. package/Logger/dist/effect-Logger.cjs.dev.js +33 -33
  91. package/Logger/dist/effect-Logger.cjs.prod.js +33 -33
  92. package/Metric/dist/effect-Metric.cjs.dev.js +27 -27
  93. package/Metric/dist/effect-Metric.cjs.prod.js +27 -27
  94. package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.dev.js +4 -4
  95. package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.prod.js +4 -4
  96. package/MetricHook/dist/effect-MetricHook.cjs.dev.js +6 -6
  97. package/MetricHook/dist/effect-MetricHook.cjs.prod.js +6 -6
  98. package/MetricKey/dist/effect-MetricKey.cjs.dev.js +6 -6
  99. package/MetricKey/dist/effect-MetricKey.cjs.prod.js +6 -6
  100. package/MetricKeyType/dist/effect-MetricKeyType.cjs.dev.js +4 -4
  101. package/MetricKeyType/dist/effect-MetricKeyType.cjs.prod.js +4 -4
  102. package/MetricPolling/dist/effect-MetricPolling.cjs.dev.js +30 -30
  103. package/MetricPolling/dist/effect-MetricPolling.cjs.prod.js +30 -30
  104. package/MetricRegistry/dist/effect-MetricRegistry.cjs.dev.js +8 -8
  105. package/MetricRegistry/dist/effect-MetricRegistry.cjs.prod.js +8 -8
  106. package/MetricState/dist/effect-MetricState.cjs.dev.js +1 -1
  107. package/MetricState/dist/effect-MetricState.cjs.prod.js +1 -1
  108. package/MutableHashMap/dist/effect-MutableHashMap.cjs.dev.js +4 -4
  109. package/MutableHashMap/dist/effect-MutableHashMap.cjs.prod.js +4 -4
  110. package/MutableHashSet/dist/effect-MutableHashSet.cjs.dev.js +4 -4
  111. package/MutableHashSet/dist/effect-MutableHashSet.cjs.prod.js +4 -4
  112. package/MutableQueue/dist/effect-MutableQueue.cjs.dev.js +3 -3
  113. package/MutableQueue/dist/effect-MutableQueue.cjs.prod.js +3 -3
  114. package/Number/dist/effect-Number.cjs.dev.js +1 -1
  115. package/Number/dist/effect-Number.cjs.prod.js +1 -1
  116. package/Number/dist/effect-Number.esm.js +1 -1
  117. package/Option/dist/effect-Option.cjs.dev.js +9 -9
  118. package/Option/dist/effect-Option.cjs.prod.js +9 -9
  119. package/Pool/dist/effect-Pool.cjs.dev.js +31 -31
  120. package/Pool/dist/effect-Pool.cjs.prod.js +31 -31
  121. package/PubSub/dist/effect-PubSub.cjs.d.mts +2 -0
  122. package/PubSub/dist/effect-PubSub.cjs.d.mts.map +1 -0
  123. package/PubSub/dist/effect-PubSub.cjs.d.ts +2 -0
  124. package/PubSub/dist/effect-PubSub.cjs.d.ts.map +1 -0
  125. package/{Hub/dist/effect-Hub.cjs.dev.js → PubSub/dist/effect-PubSub.cjs.dev.js} +163 -163
  126. package/PubSub/dist/effect-PubSub.cjs.js +7 -0
  127. package/{Hub/dist/effect-Hub.cjs.mjs → PubSub/dist/effect-PubSub.cjs.mjs} +1 -1
  128. package/{Hub/dist/effect-Hub.cjs.prod.js → PubSub/dist/effect-PubSub.cjs.prod.js} +163 -163
  129. package/{Hub/dist/effect-Hub.esm.js → PubSub/dist/effect-PubSub.esm.js} +15 -15
  130. package/PubSub/package.json +4 -0
  131. package/Queue/dist/effect-Queue.cjs.dev.js +28 -28
  132. package/Queue/dist/effect-Queue.cjs.prod.js +28 -28
  133. package/README.md +5 -5
  134. package/Random/dist/effect-Random.cjs.dev.js +16 -16
  135. package/Random/dist/effect-Random.cjs.prod.js +16 -16
  136. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.dev.js +3 -3
  137. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.prod.js +3 -3
  138. package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.dev.js +3 -3
  139. package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.prod.js +3 -3
  140. package/RedBlackTree/dist/effect-RedBlackTree.cjs.dev.js +4 -4
  141. package/RedBlackTree/dist/effect-RedBlackTree.cjs.prod.js +4 -4
  142. package/Ref/dist/effect-Ref.cjs.dev.js +9 -9
  143. package/Ref/dist/effect-Ref.cjs.prod.js +9 -9
  144. package/Reloadable/dist/effect-Reloadable.cjs.dev.js +44 -44
  145. package/Reloadable/dist/effect-Reloadable.cjs.prod.js +44 -44
  146. package/Request/dist/effect-Request.cjs.dev.js +29 -29
  147. package/Request/dist/effect-Request.cjs.prod.js +29 -29
  148. package/RequestBlock/dist/effect-RequestBlock.cjs.dev.js +36 -36
  149. package/RequestBlock/dist/effect-RequestBlock.cjs.prod.js +36 -36
  150. package/RequestResolver/dist/effect-RequestResolver.cjs.dev.js +38 -38
  151. package/RequestResolver/dist/effect-RequestResolver.cjs.prod.js +38 -38
  152. package/Resource/dist/effect-Resource.cjs.dev.js +34 -34
  153. package/Resource/dist/effect-Resource.cjs.prod.js +34 -34
  154. package/Runtime/dist/effect-Runtime.cjs.dev.js +34 -34
  155. package/Runtime/dist/effect-Runtime.cjs.prod.js +34 -34
  156. package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.dev.js +33 -33
  157. package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.prod.js +33 -33
  158. package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.dev.js +6 -6
  159. package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.prod.js +6 -6
  160. package/STM/dist/effect-STM.cjs.dev.js +48 -48
  161. package/STM/dist/effect-STM.cjs.prod.js +48 -48
  162. package/Schedule/dist/effect-Schedule.cjs.dev.js +19 -19
  163. package/Schedule/dist/effect-Schedule.cjs.prod.js +19 -19
  164. package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.dev.js +3 -3
  165. package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.prod.js +3 -3
  166. package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.dev.js +3 -3
  167. package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.prod.js +3 -3
  168. package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.dev.js +3 -3
  169. package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.prod.js +3 -3
  170. package/Scheduler/dist/effect-Scheduler.cjs.dev.js +8 -8
  171. package/Scheduler/dist/effect-Scheduler.cjs.prod.js +8 -8
  172. package/Scope/dist/effect-Scope.cjs.dev.js +27 -27
  173. package/Scope/dist/effect-Scope.cjs.prod.js +27 -27
  174. package/ScopedCache/dist/effect-ScopedCache.cjs.dev.js +78 -61
  175. package/ScopedCache/dist/effect-ScopedCache.cjs.prod.js +78 -61
  176. package/ScopedRef/dist/effect-ScopedRef.cjs.dev.js +34 -34
  177. package/ScopedRef/dist/effect-ScopedRef.cjs.prod.js +34 -34
  178. package/Sink/dist/effect-Sink.cjs.dev.js +43 -43
  179. package/Sink/dist/effect-Sink.cjs.mjs +1 -1
  180. package/Sink/dist/effect-Sink.cjs.prod.js +43 -43
  181. package/Sink/dist/effect-Sink.esm.js +5 -5
  182. package/SortedMap/dist/effect-SortedMap.cjs.dev.js +3 -3
  183. package/SortedMap/dist/effect-SortedMap.cjs.prod.js +3 -3
  184. package/SortedSet/dist/effect-SortedSet.cjs.dev.js +3 -3
  185. package/SortedSet/dist/effect-SortedSet.cjs.prod.js +3 -3
  186. package/Stream/dist/effect-Stream.cjs.dev.js +60 -60
  187. package/Stream/dist/effect-Stream.cjs.mjs +5 -5
  188. package/Stream/dist/effect-Stream.cjs.prod.js +60 -60
  189. package/Stream/dist/effect-Stream.esm.js +15 -15
  190. package/Streamable/dist/effect-Streamable.cjs.d.mts +2 -0
  191. package/Streamable/dist/effect-Streamable.cjs.d.mts.map +1 -0
  192. package/Streamable/dist/effect-Streamable.cjs.d.ts +2 -0
  193. package/Streamable/dist/effect-Streamable.cjs.d.ts.map +1 -0
  194. package/Streamable/dist/effect-Streamable.cjs.dev.js +152 -0
  195. package/Streamable/dist/effect-Streamable.cjs.js +7 -0
  196. package/Streamable/dist/effect-Streamable.cjs.mjs +3 -0
  197. package/Streamable/dist/effect-Streamable.cjs.prod.js +152 -0
  198. package/Streamable/dist/effect-Streamable.esm.js +42 -0
  199. package/Streamable/package.json +4 -0
  200. package/String/dist/effect-String.cjs.dev.js +4 -4
  201. package/String/dist/effect-String.cjs.prod.js +4 -4
  202. package/String/dist/effect-String.esm.js +1 -1
  203. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.dev.js +48 -48
  204. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.prod.js +48 -48
  205. package/Supervisor/dist/effect-Supervisor.cjs.dev.js +34 -34
  206. package/Supervisor/dist/effect-Supervisor.cjs.prod.js +34 -34
  207. package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.dev.js +30 -30
  208. package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.prod.js +30 -30
  209. package/TArray/dist/effect-TArray.cjs.dev.js +46 -46
  210. package/TArray/dist/effect-TArray.cjs.prod.js +46 -46
  211. package/TDeferred/dist/effect-TDeferred.cjs.dev.js +45 -45
  212. package/TDeferred/dist/effect-TDeferred.cjs.prod.js +45 -45
  213. package/TMap/dist/effect-TMap.cjs.dev.js +47 -47
  214. package/TMap/dist/effect-TMap.cjs.prod.js +47 -47
  215. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.dev.js +44 -44
  216. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.prod.js +44 -44
  217. package/TPubSub/dist/effect-TPubSub.cjs.d.mts +2 -0
  218. package/TPubSub/dist/effect-TPubSub.cjs.d.mts.map +1 -0
  219. package/TPubSub/dist/effect-TPubSub.cjs.d.ts +2 -0
  220. package/TPubSub/dist/effect-TPubSub.cjs.d.ts.map +1 -0
  221. package/{THub/dist/effect-THub.cjs.dev.js → TPubSub/dist/effect-TPubSub.cjs.dev.js} +101 -101
  222. package/TPubSub/dist/effect-TPubSub.cjs.js +7 -0
  223. package/{THub/dist/effect-THub.cjs.mjs → TPubSub/dist/effect-TPubSub.cjs.mjs} +2 -2
  224. package/{THub/dist/effect-THub.cjs.prod.js → TPubSub/dist/effect-TPubSub.cjs.prod.js} +101 -101
  225. package/TPubSub/dist/effect-TPubSub.esm.js +157 -0
  226. package/TPubSub/package.json +4 -0
  227. package/TQueue/dist/effect-TQueue.cjs.dev.js +46 -46
  228. package/TQueue/dist/effect-TQueue.cjs.prod.js +46 -46
  229. package/TRandom/dist/effect-TRandom.cjs.dev.js +50 -50
  230. package/TRandom/dist/effect-TRandom.cjs.prod.js +50 -50
  231. package/TReentrantLock/dist/effect-TReentrantLock.cjs.dev.js +46 -46
  232. package/TReentrantLock/dist/effect-TReentrantLock.cjs.prod.js +46 -46
  233. package/TRef/dist/effect-TRef.cjs.dev.js +44 -44
  234. package/TRef/dist/effect-TRef.cjs.prod.js +44 -44
  235. package/TSemaphore/dist/effect-TSemaphore.cjs.dev.js +45 -45
  236. package/TSemaphore/dist/effect-TSemaphore.cjs.prod.js +45 -45
  237. package/TSet/dist/effect-TSet.cjs.dev.js +47 -47
  238. package/TSet/dist/effect-TSet.cjs.prod.js +47 -47
  239. package/Take/dist/effect-Take.cjs.dev.js +36 -36
  240. package/Take/dist/effect-Take.cjs.prod.js +36 -36
  241. package/TestAnnotation/dist/effect-TestAnnotation.cjs.dev.js +8 -8
  242. package/TestAnnotation/dist/effect-TestAnnotation.cjs.prod.js +8 -8
  243. package/TestAnnotations/dist/effect-TestAnnotations.cjs.dev.js +25 -25
  244. package/TestAnnotations/dist/effect-TestAnnotations.cjs.prod.js +25 -25
  245. package/TestClock/dist/effect-TestClock.cjs.dev.js +46 -46
  246. package/TestClock/dist/effect-TestClock.cjs.prod.js +46 -46
  247. package/TestConfig/dist/effect-TestConfig.cjs.dev.js +3 -8
  248. package/TestConfig/dist/effect-TestConfig.cjs.prod.js +3 -8
  249. package/TestContext/dist/effect-TestContext.cjs.dev.js +37 -37
  250. package/TestContext/dist/effect-TestContext.cjs.prod.js +37 -37
  251. package/TestLive/dist/effect-TestLive.cjs.dev.js +17 -17
  252. package/TestLive/dist/effect-TestLive.cjs.prod.js +17 -17
  253. package/TestServices/dist/effect-TestServices.cjs.dev.js +42 -42
  254. package/TestServices/dist/effect-TestServices.cjs.prod.js +42 -42
  255. package/TestSized/dist/effect-TestSized.cjs.dev.js +11 -11
  256. package/TestSized/dist/effect-TestSized.cjs.prod.js +11 -11
  257. package/Tracer/dist/effect-Tracer.cjs.dev.js +16 -16
  258. package/Tracer/dist/effect-Tracer.cjs.prod.js +16 -16
  259. package/dist/{Context-01a123ac.cjs.prod.js → Context-9fe5eb16.cjs.prod.js} +5 -5
  260. package/dist/{Context-593661f6.cjs.dev.js → Context-da73ddfa.cjs.dev.js} +5 -5
  261. package/dist/{Effectable-2f022879.cjs.dev.js → Effectable-7314aed8.cjs.dev.js} +63 -10
  262. package/dist/{Effectable-cd8f3a96.cjs.prod.js → Effectable-c4c14a2b.cjs.prod.js} +63 -10
  263. package/dist/{Either-7a881c7a.cjs.prod.js → Either-d43f082c.cjs.prod.js} +6 -79
  264. package/dist/{Either-12bbe00c.cjs.dev.js → Either-fa0ef1d9.cjs.dev.js} +6 -79
  265. package/dist/{ExecutionStrategy-14d3053a.cjs.prod.js → ExecutionStrategy-4808fe5d.cjs.prod.js} +2 -2
  266. package/dist/{ExecutionStrategy-70f1a920.cjs.dev.js → ExecutionStrategy-7d9d457b.cjs.dev.js} +2 -2
  267. package/dist/{HashSet-0b4ff1e4.cjs.dev.js → HashSet-5963ad6b.cjs.dev.js} +32 -32
  268. package/dist/{HashSet-6257b66d.cjs.prod.js → HashSet-ac02a3e1.cjs.prod.js} +32 -32
  269. package/dist/Option-463b42e6.cjs.dev.js +81 -0
  270. package/dist/Option-935e5d7c.cjs.prod.js +81 -0
  271. package/dist/{Ref-a3a4e50d.cjs.prod.js → Ref-4014b526.cjs.prod.js} +1 -1
  272. package/dist/{Ref-74b592a4.cjs.dev.js → Ref-acdee7ef.cjs.dev.js} +1 -1
  273. package/dist/{cache-75fbef45.cjs.prod.js → cache-5c7d77e4.cjs.prod.js} +17 -17
  274. package/dist/{cache-e1ea3923.cjs.dev.js → cache-7eed9d33.cjs.dev.js} +17 -17
  275. package/dist/{circular-6f16b226.cjs.prod.js → circular-1f481ffb.cjs.prod.js} +33 -33
  276. package/dist/{circular-f406f9a4.cjs.prod.js → circular-9e10a5a7.cjs.prod.js} +6 -6
  277. package/dist/{circular-58ff5e9c.cjs.dev.js → circular-c2dbce1a.cjs.dev.js} +33 -33
  278. package/dist/{circular-30564534.cjs.dev.js → circular-c8b65bdb.cjs.dev.js} +6 -6
  279. package/dist/{config-80900693.cjs.dev.js → config-3b7935a3.cjs.dev.js} +3 -3
  280. package/dist/{config-d0ddc159.cjs.prod.js → config-5ba54da1.cjs.prod.js} +3 -3
  281. package/dist/{configProvider-93617d6d.cjs.prod.js → configProvider-b6b20998.cjs.prod.js} +29 -29
  282. package/dist/{configProvider-ce43fdbf.cjs.dev.js → configProvider-f34a82f1.cjs.dev.js} +29 -29
  283. package/dist/{core-0b0539de.cjs.prod.js → core-07202cc0.cjs.prod.js} +711 -726
  284. package/dist/{core-60ca562a.cjs.prod.js → core-7411d1e1.cjs.prod.js} +3 -3
  285. package/dist/{core-b4d7b4f5.cjs.dev.js → core-b7401357.cjs.dev.js} +711 -726
  286. package/dist/{core-13f8a866.cjs.dev.js → core-c5747f88.cjs.dev.js} +3 -3
  287. package/dist/{core-effect-892f3686.cjs.dev.js → core-effect-1c564d42.cjs.dev.js} +77 -75
  288. package/dist/{core-effect-c65770cd.cjs.prod.js → core-effect-9201ea63.cjs.prod.js} +77 -75
  289. package/dist/{dataSource-3ba9e4d3.cjs.dev.js → dataSource-b5eda714.cjs.dev.js} +2 -2
  290. package/dist/{dataSource-7df3a5f6.cjs.prod.js → dataSource-b83bc277.cjs.prod.js} +2 -2
  291. package/dist/declarations/src/Bigint.d.ts +92 -1
  292. package/dist/declarations/src/Bigint.d.ts.map +1 -1
  293. package/dist/declarations/src/Boolean.d.ts +1 -1
  294. package/dist/declarations/src/Cause.d.ts +6 -6
  295. package/dist/declarations/src/Cause.d.ts.map +1 -1
  296. package/dist/declarations/src/Channel.d.ts +7 -7
  297. package/dist/declarations/src/Channel.d.ts.map +1 -1
  298. package/dist/declarations/src/Data.d.ts +30 -0
  299. package/dist/declarations/src/Data.d.ts.map +1 -1
  300. package/dist/declarations/src/Effect.d.ts +4 -2
  301. package/dist/declarations/src/Effect.d.ts.map +1 -1
  302. package/dist/declarations/src/Effectable.d.ts +14 -4
  303. package/dist/declarations/src/Effectable.d.ts.map +1 -1
  304. package/dist/declarations/src/Metric.d.ts +31 -7
  305. package/dist/declarations/src/Metric.d.ts.map +1 -1
  306. package/dist/declarations/src/MetricHook.d.ts +7 -4
  307. package/dist/declarations/src/MetricHook.d.ts.map +1 -1
  308. package/dist/declarations/src/MetricKey.d.ts +24 -4
  309. package/dist/declarations/src/MetricKey.d.ts.map +1 -1
  310. package/dist/declarations/src/MetricKeyType.d.ts +9 -6
  311. package/dist/declarations/src/MetricKeyType.d.ts.map +1 -1
  312. package/dist/declarations/src/MetricRegistry.d.ts +2 -2
  313. package/dist/declarations/src/MetricRegistry.d.ts.map +1 -1
  314. package/dist/declarations/src/MetricState.d.ts +15 -9
  315. package/dist/declarations/src/MetricState.d.ts.map +1 -1
  316. package/dist/declarations/src/Number.d.ts +1 -1
  317. package/dist/declarations/src/{Hub.d.ts → PubSub.d.ts} +38 -38
  318. package/dist/declarations/src/PubSub.d.ts.map +1 -0
  319. package/dist/declarations/src/Sink.d.ts +4 -4
  320. package/dist/declarations/src/Sink.d.ts.map +1 -1
  321. package/dist/declarations/src/Stream.d.ts +24 -24
  322. package/dist/declarations/src/Stream.d.ts.map +1 -1
  323. package/dist/declarations/src/Streamable.d.ts +27 -0
  324. package/dist/declarations/src/Streamable.d.ts.map +1 -0
  325. package/dist/declarations/src/String.d.ts +1 -1
  326. package/dist/declarations/src/SubscriptionRef.d.ts.map +1 -1
  327. package/dist/declarations/src/TPubSub.d.ts +146 -0
  328. package/dist/declarations/src/TPubSub.d.ts.map +1 -0
  329. package/dist/declarations/src/index.d.ts +15 -15
  330. package/dist/declarations/src/index.d.ts.map +1 -1
  331. package/dist/{defaultServices-5530ff0e.cjs.dev.js → defaultServices-755d5b46.cjs.dev.js} +6 -6
  332. package/dist/{defaultServices-086b8ac9.cjs.prod.js → defaultServices-9d7ce86f.cjs.prod.js} +6 -6
  333. package/dist/effect.cjs.dev.js +9 -9
  334. package/dist/effect.cjs.mjs +3 -3
  335. package/dist/effect.cjs.prod.js +9 -9
  336. package/dist/effect.esm.js +6 -6
  337. package/dist/{fiber-1bfb4c1d.cjs.dev.js → fiber-5156eff2.cjs.dev.js} +12 -12
  338. package/dist/{fiber-2eb0a4c1.cjs.prod.js → fiber-9519d109.cjs.prod.js} +12 -12
  339. package/dist/{fiberRefs-be6b6a70.cjs.prod.js → fiberRefs-558c17e6.cjs.prod.js} +1 -1
  340. package/dist/{fiberRefs-be4fae6a.cjs.dev.js → fiberRefs-98b71233.cjs.dev.js} +1 -1
  341. package/dist/{fiberRuntime-2d31e120.cjs.prod.js → fiberRuntime-31ae011f.cjs.prod.js} +99 -100
  342. package/dist/{fiberRuntime-c7280769.cjs.dev.js → fiberRuntime-d3872282.cjs.dev.js} +99 -100
  343. package/dist/{groupBy-0702739b.cjs.prod.js → groupBy-724f64ef.cjs.prod.js} +4 -4
  344. package/dist/{groupBy-7f852bf3.cjs.dev.js → groupBy-862cc2da.cjs.dev.js} +4 -4
  345. package/dist/{hook-e72b20fd.cjs.dev.js → hook-8cefc909.cjs.dev.js} +8 -4
  346. package/dist/{hook-470b717e.cjs.prod.js → hook-98ce30e4.cjs.prod.js} +8 -4
  347. package/dist/{key-f0a1408a.cjs.dev.js → key-198b6670.cjs.dev.js} +3 -3
  348. package/dist/{key-378a6a2c.cjs.prod.js → key-eb8a12b2.cjs.prod.js} +3 -3
  349. package/dist/{keyType-cf67c69c.cjs.prod.js → keyType-0c5e6178.cjs.prod.js} +9 -2
  350. package/dist/{keyType-55f27f07.cjs.dev.js → keyType-7c164b82.cjs.dev.js} +9 -2
  351. package/dist/{layer-b42e8022.cjs.dev.js → layer-29574350.cjs.dev.js} +33 -33
  352. package/dist/{layer-d103b49b.cjs.prod.js → layer-51ff4846.cjs.prod.js} +33 -33
  353. package/dist/{patch-a1b2802f.cjs.dev.js → patch-0220a642.cjs.dev.js} +1 -1
  354. package/dist/{patch-c4d6c61e.cjs.prod.js → patch-7c559bb2.cjs.prod.js} +1 -1
  355. package/dist/{pathPatch-15c8d723.cjs.prod.js → pathPatch-b56a4da2.cjs.prod.js} +1 -1
  356. package/dist/{pathPatch-d9d41297.cjs.dev.js → pathPatch-fab016f1.cjs.dev.js} +1 -1
  357. package/dist/{pool-ef44ba82.cjs.dev.js → pool-3211287f.cjs.dev.js} +31 -31
  358. package/dist/{pool-e414eb88.cjs.prod.js → pool-f77d7705.cjs.prod.js} +31 -31
  359. package/dist/{query-1d0157db.cjs.prod.js → query-a52b25f0.cjs.prod.js} +11 -11
  360. package/dist/{query-54337864.cjs.dev.js → query-c36decd5.cjs.dev.js} +11 -11
  361. package/dist/{queue-27ac9d98.cjs.prod.js → queue-315ea45d.cjs.prod.js} +22 -22
  362. package/dist/{queue-533d70d4.cjs.dev.js → queue-7a223c44.cjs.dev.js} +22 -22
  363. package/dist/{registry-1099de3f.cjs.dev.js → registry-62ff192e.cjs.dev.js} +4 -4
  364. package/dist/{registry-013ecdde.cjs.prod.js → registry-d5258dff.cjs.prod.js} +4 -4
  365. package/dist/{runtime-ea174155.cjs.prod.js → runtime-005f8a9b.cjs.prod.js} +7 -7
  366. package/dist/{runtime-afad6a9b.cjs.dev.js → runtime-57c8ddf8.cjs.dev.js} +7 -7
  367. package/dist/{schedule-1d92198c.cjs.prod.js → schedule-8cdf6bf1.cjs.prod.js} +40 -40
  368. package/dist/{schedule-e0f55cab.cjs.dev.js → schedule-e7a9f93f.cjs.dev.js} +40 -40
  369. package/dist/scopedRef-789d7fef.cjs.prod.js +55 -0
  370. package/dist/scopedRef-eb19c7a6.cjs.dev.js +55 -0
  371. package/dist/{singleProducerAsyncInput-4105a342.cjs.dev.js → singleProducerAsyncInput-9ff8389b.cjs.dev.js} +1 -1
  372. package/dist/{singleProducerAsyncInput-21463e16.cjs.prod.js → singleProducerAsyncInput-f9b258b1.cjs.prod.js} +1 -1
  373. package/dist/{sink-9129504b.cjs.prod.js → sink-572d8981.cjs.prod.js} +17 -17
  374. package/dist/{sink-ee393b63.cjs.dev.js → sink-8d3427e7.cjs.dev.js} +17 -17
  375. package/dist/{state-dd1bd066.cjs.prod.js → state-0bdf02b7.cjs.prod.js} +2 -6
  376. package/dist/{state-8fbec044.cjs.dev.js → state-931050c4.cjs.dev.js} +2 -6
  377. package/dist/{stm-537da66b.cjs.dev.js → stm-8aca0022.cjs.dev.js} +3 -3
  378. package/dist/{stm-5043c3cb.cjs.prod.js → stm-f250b596.cjs.prod.js} +3 -3
  379. package/dist/{stream-c7eda5bc.cjs.dev.js → stream-34d80d2c.cjs.dev.js} +31 -28
  380. package/dist/{stream-13637643.cjs.prod.js → stream-ea4f4d44.cjs.prod.js} +31 -28
  381. package/dist/{synchronizedRef-37e32854.cjs.dev.js → synchronizedRef-a12fd967.cjs.dev.js} +6 -6
  382. package/dist/{synchronizedRef-b4cde4de.cjs.prod.js → synchronizedRef-ed8aa6ac.cjs.prod.js} +6 -6
  383. package/dist/{tArray-df1bae1c.cjs.dev.js → tArray-17f078f2.cjs.dev.js} +3 -3
  384. package/dist/{tArray-d5476a2d.cjs.prod.js → tArray-d184e22f.cjs.prod.js} +3 -3
  385. package/dist/{tMap-a3e14c05.cjs.dev.js → tMap-1a5aa78b.cjs.dev.js} +4 -4
  386. package/dist/{tMap-20ef43ea.cjs.prod.js → tMap-e219f30e.cjs.prod.js} +4 -4
  387. package/dist/{tQueue-bd3cf539.cjs.dev.js → tQueue-0a4fc773.cjs.dev.js} +3 -3
  388. package/dist/{tQueue-c02c22bd.cjs.prod.js → tQueue-47129ad0.cjs.prod.js} +3 -3
  389. package/dist/{tRef-49e44dde.cjs.prod.js → tRef-ab4c5713.cjs.prod.js} +1 -1
  390. package/dist/{tRef-75dd04b3.cjs.dev.js → tRef-b860ef05.cjs.dev.js} +1 -1
  391. package/internal/Context.esm.js +4 -4
  392. package/internal/Data.esm.js +4 -1
  393. package/internal/Differ/ChunkPatch.esm.js +1 -1
  394. package/internal/Differ/ContextPatch.esm.js +1 -1
  395. package/internal/Differ/HashMapPatch.esm.js +1 -1
  396. package/internal/Differ/HashSetPatch.esm.js +1 -1
  397. package/internal/Differ/OrPatch.esm.js +1 -1
  398. package/internal/Effectable.esm.js +9 -9
  399. package/internal/Either.esm.js +3 -3
  400. package/internal/Option.esm.js +3 -3
  401. package/internal/cache.esm.js +1 -1
  402. package/internal/cause.esm.js +6 -21
  403. package/internal/channel.esm.js +5 -5
  404. package/internal/core-effect.esm.js +6 -4
  405. package/internal/fiberRuntime.esm.js +3 -3
  406. package/internal/layer.esm.js +1 -1
  407. package/internal/metric/hook.esm.js +7 -3
  408. package/internal/metric/key.esm.js +2 -2
  409. package/internal/metric/keyType.esm.js +9 -2
  410. package/internal/metric/registry.esm.js +2 -2
  411. package/internal/metric/state.esm.js +2 -6
  412. package/internal/metric.esm.js +3 -3
  413. package/internal/{hub.esm.js → pubsub.esm.js} +108 -108
  414. package/internal/request.esm.js +1 -1
  415. package/internal/sink.esm.js +8 -8
  416. package/internal/stm/{tHub.esm.js → tPubSub.esm.js} +30 -30
  417. package/internal/stream.esm.js +23 -20
  418. package/internal/subscriptionRef.esm.js +8 -8
  419. package/package.json +66 -211
  420. package/src/.index.ts +30 -0
  421. package/src/Bigint.ts +497 -0
  422. package/src/Boolean.ts +261 -0
  423. package/src/Brand.ts +336 -0
  424. package/src/Cache.ts +250 -0
  425. package/src/Cause.ts +813 -0
  426. package/src/Channel.ts +2244 -0
  427. package/src/ChannelChildExecutorDecision.ts +138 -0
  428. package/src/ChannelMergeDecision.ts +94 -0
  429. package/src/ChannelMergeState.ts +166 -0
  430. package/src/ChannelMergeStrategy.ts +107 -0
  431. package/src/ChannelSingleProducerAsyncInput.ts +68 -0
  432. package/src/ChannelUpstreamPullRequest.ts +110 -0
  433. package/src/ChannelUpstreamPullStrategy.ts +120 -0
  434. package/src/Chunk.ts +1314 -0
  435. package/src/Clock.ts +111 -0
  436. package/src/Config.ts +447 -0
  437. package/src/ConfigError.ts +267 -0
  438. package/src/ConfigProvider.ts +296 -0
  439. package/src/ConfigProviderPathPatch.ts +100 -0
  440. package/src/ConfigSecret.ts +76 -0
  441. package/src/Console.ts +222 -0
  442. package/src/Context.ts +365 -0
  443. package/src/Data.ts +367 -0
  444. package/src/DefaultServices.ts +34 -0
  445. package/src/Deferred.ts +283 -0
  446. package/src/Differ.ts +406 -0
  447. package/src/Duration.ts +558 -0
  448. package/src/Effect.ts +5177 -0
  449. package/src/Effectable.ts +107 -0
  450. package/src/Either.ts +593 -0
  451. package/src/Encoding.ts +130 -0
  452. package/src/Equal.ts +64 -0
  453. package/src/Equivalence.ts +235 -0
  454. package/src/ExecutionStrategy.ts +111 -0
  455. package/src/Exit.ts +464 -0
  456. package/src/Fiber.ts +650 -0
  457. package/src/FiberId.ts +187 -0
  458. package/src/FiberRef.ts +399 -0
  459. package/src/FiberRefs.ts +160 -0
  460. package/src/FiberRefsPatch.ts +105 -0
  461. package/src/FiberStatus.ts +108 -0
  462. package/src/Function.ts +834 -0
  463. package/src/GlobalValue.ts +20 -0
  464. package/src/GroupBy.ts +102 -0
  465. package/src/HKT.ts +44 -0
  466. package/src/Hash.ts +162 -0
  467. package/src/HashMap.ts +373 -0
  468. package/src/HashSet.ts +300 -0
  469. package/src/Inspectable.ts +45 -0
  470. package/src/KeyedPool.ts +160 -0
  471. package/src/Layer.ts +866 -0
  472. package/src/List.ts +942 -0
  473. package/src/LogLevel.ts +266 -0
  474. package/src/LogSpan.ts +25 -0
  475. package/src/Logger.ts +321 -0
  476. package/src/Metric.ts +657 -0
  477. package/src/MetricBoundaries.ts +70 -0
  478. package/src/MetricHook.ts +139 -0
  479. package/src/MetricKey.ts +227 -0
  480. package/src/MetricKeyType.ts +257 -0
  481. package/src/MetricLabel.ts +47 -0
  482. package/src/MetricPair.ts +70 -0
  483. package/src/MetricPolling.ts +136 -0
  484. package/src/MetricRegistry.ts +47 -0
  485. package/src/MetricState.ts +256 -0
  486. package/src/MutableHashMap.ts +187 -0
  487. package/src/MutableHashSet.ts +118 -0
  488. package/src/MutableList.ts +289 -0
  489. package/src/MutableQueue.ts +227 -0
  490. package/src/MutableRef.ts +204 -0
  491. package/src/NonEmptyIterable.ts +30 -0
  492. package/src/Number.ts +406 -0
  493. package/src/Option.ts +1307 -0
  494. package/src/Order.ts +328 -0
  495. package/src/Ordering.ts +112 -0
  496. package/src/Pipeable.ts +318 -0
  497. package/src/Pool.ts +148 -0
  498. package/src/Predicate.ts +704 -0
  499. package/src/PubSub.ts +175 -0
  500. package/src/Queue.ts +575 -0
  501. package/src/Random.ts +115 -0
  502. package/src/ReadonlyArray.ts +2017 -0
  503. package/src/ReadonlyRecord.ts +641 -0
  504. package/src/RedBlackTree.ts +415 -0
  505. package/src/Ref.ts +159 -0
  506. package/src/Reloadable.ts +136 -0
  507. package/src/Request.ts +285 -0
  508. package/src/RequestBlock.ts +157 -0
  509. package/src/RequestResolver.ts +305 -0
  510. package/src/Resource.ts +97 -0
  511. package/src/Runtime.ts +216 -0
  512. package/src/RuntimeFlags.ts +336 -0
  513. package/src/RuntimeFlagsPatch.ts +183 -0
  514. package/src/STM.ts +2076 -0
  515. package/src/Schedule.ts +1396 -0
  516. package/src/ScheduleDecision.ts +62 -0
  517. package/src/ScheduleInterval.ts +151 -0
  518. package/src/ScheduleIntervals.ts +122 -0
  519. package/src/Scheduler.ts +359 -0
  520. package/src/Scope.ts +171 -0
  521. package/src/ScopedCache.ts +148 -0
  522. package/src/ScopedRef.ts +95 -0
  523. package/src/Sink.ts +1431 -0
  524. package/src/SortedMap.ts +229 -0
  525. package/src/SortedSet.ts +385 -0
  526. package/src/Stream.ts +4540 -0
  527. package/src/StreamEmit.ts +83 -0
  528. package/src/StreamHaltStrategy.ts +111 -0
  529. package/src/Streamable.ts +42 -0
  530. package/src/String.ts +682 -0
  531. package/src/Struct.ts +151 -0
  532. package/src/SubscriptionRef.ts +273 -0
  533. package/src/Supervisor.ts +239 -0
  534. package/src/Symbol.ts +28 -0
  535. package/src/SynchronizedRef.ts +249 -0
  536. package/src/TArray.ts +494 -0
  537. package/src/TDeferred.ts +99 -0
  538. package/src/TMap.ts +510 -0
  539. package/src/TPriorityQueue.ts +223 -0
  540. package/src/TPubSub.ts +187 -0
  541. package/src/TQueue.ts +431 -0
  542. package/src/TRandom.ts +129 -0
  543. package/src/TReentrantLock.ts +224 -0
  544. package/src/TRef.ts +176 -0
  545. package/src/TSemaphore.ts +129 -0
  546. package/src/TSet.ts +349 -0
  547. package/src/Take.ts +257 -0
  548. package/src/TestAnnotation.ts +166 -0
  549. package/src/TestAnnotationMap.ts +124 -0
  550. package/src/TestAnnotations.ts +113 -0
  551. package/src/TestClock.ts +552 -0
  552. package/src/TestConfig.ts +49 -0
  553. package/src/TestContext.ts +35 -0
  554. package/src/TestLive.ts +55 -0
  555. package/src/TestServices.ts +392 -0
  556. package/src/TestSized.ts +55 -0
  557. package/src/Tracer.ts +119 -0
  558. package/src/Tuple.ts +204 -0
  559. package/src/Types.ts +123 -0
  560. package/src/Unify.ts +118 -0
  561. package/src/Utils.ts +699 -0
  562. package/src/index.ts +840 -0
  563. package/src/internal/Common.ts +56 -0
  564. package/src/internal/Context.ts +252 -0
  565. package/src/internal/Data.ts +55 -0
  566. package/src/internal/Differ/ChunkPatch.ts +209 -0
  567. package/src/internal/Differ/ContextPatch.ts +229 -0
  568. package/src/internal/Differ/HashMapPatch.ts +217 -0
  569. package/src/internal/Differ/HashSetPatch.ts +174 -0
  570. package/src/internal/Differ/OrPatch.ts +296 -0
  571. package/src/internal/Differ.ts +184 -0
  572. package/src/internal/Effectable.ts +92 -0
  573. package/src/internal/Either.ts +107 -0
  574. package/src/internal/Encoding/Base64.ts +282 -0
  575. package/src/internal/Encoding/Base64Url.ts +28 -0
  576. package/src/internal/Encoding/Common.ts +24 -0
  577. package/src/internal/Encoding/Hex.ts +315 -0
  578. package/src/internal/HashMap/array.ts +49 -0
  579. package/src/internal/HashMap/bitwise.ts +32 -0
  580. package/src/internal/HashMap/config.ts +14 -0
  581. package/src/internal/HashMap/keySet.ts +8 -0
  582. package/src/internal/HashMap/node.ts +390 -0
  583. package/src/internal/HashMap.ts +533 -0
  584. package/src/internal/HashSet.ts +319 -0
  585. package/src/internal/Iterable.ts +54 -0
  586. package/src/internal/Option.ts +79 -0
  587. package/src/internal/ReadonlyArray.ts +8 -0
  588. package/src/internal/RedBlackTree/iterator.ts +207 -0
  589. package/src/internal/RedBlackTree/node.ts +48 -0
  590. package/src/internal/RedBlackTree.ts +1195 -0
  591. package/src/internal/Stack.ts +4 -0
  592. package/src/internal/blockedRequests.ts +512 -0
  593. package/src/internal/cache.ts +714 -0
  594. package/src/internal/cause.ts +1205 -0
  595. package/src/internal/channel/channelExecutor.ts +1193 -0
  596. package/src/internal/channel/channelState.ts +132 -0
  597. package/src/internal/channel/childExecutorDecision.ts +95 -0
  598. package/src/internal/channel/continuation.ts +171 -0
  599. package/src/internal/channel/mergeDecision.ts +115 -0
  600. package/src/internal/channel/mergeState.ts +120 -0
  601. package/src/internal/channel/mergeStrategy.ts +72 -0
  602. package/src/internal/channel/singleProducerAsyncInput.ts +261 -0
  603. package/src/internal/channel/subexecutor.ts +229 -0
  604. package/src/internal/channel/upstreamPullRequest.ts +83 -0
  605. package/src/internal/channel/upstreamPullStrategy.ts +86 -0
  606. package/src/internal/channel.ts +2516 -0
  607. package/src/internal/clock.ts +97 -0
  608. package/src/internal/completedRequestMap.ts +9 -0
  609. package/src/internal/concurrency.ts +83 -0
  610. package/src/internal/config.ts +598 -0
  611. package/src/internal/configError.ts +291 -0
  612. package/src/internal/configProvider/pathPatch.ts +97 -0
  613. package/src/internal/configProvider.ts +692 -0
  614. package/src/internal/configSecret.ts +71 -0
  615. package/src/internal/console.ts +136 -0
  616. package/src/internal/core-effect.ts +2146 -0
  617. package/src/internal/core-stream.ts +999 -0
  618. package/src/internal/core.ts +2765 -0
  619. package/src/internal/dataSource.ts +258 -0
  620. package/src/internal/defaultServices/console.ts +97 -0
  621. package/src/internal/defaultServices.ts +140 -0
  622. package/src/internal/deferred.ts +44 -0
  623. package/src/internal/effect/circular.ts +664 -0
  624. package/src/internal/executionStrategy.ts +72 -0
  625. package/src/internal/fiber.ts +350 -0
  626. package/src/internal/fiberId.ts +270 -0
  627. package/src/internal/fiberMessage.ts +85 -0
  628. package/src/internal/fiberRefs/patch.ts +144 -0
  629. package/src/internal/fiberRefs.ts +239 -0
  630. package/src/internal/fiberRuntime.ts +3477 -0
  631. package/src/internal/fiberScope.ts +72 -0
  632. package/src/internal/fiberStatus.ts +118 -0
  633. package/src/internal/groupBy.ts +516 -0
  634. package/src/internal/keyedPool.ts +240 -0
  635. package/src/internal/layer/circular.ts +203 -0
  636. package/src/internal/layer.ts +1230 -0
  637. package/src/internal/logSpan.ts +15 -0
  638. package/src/internal/logger-circular.ts +24 -0
  639. package/src/internal/logger.ts +307 -0
  640. package/src/internal/metric/boundaries.ts +72 -0
  641. package/src/internal/metric/hook.ts +459 -0
  642. package/src/internal/metric/key.ts +173 -0
  643. package/src/internal/metric/keyType.ts +263 -0
  644. package/src/internal/metric/label.ts +44 -0
  645. package/src/internal/metric/pair.ts +48 -0
  646. package/src/internal/metric/polling.ts +143 -0
  647. package/src/internal/metric/registry.ts +188 -0
  648. package/src/internal/metric/state.ts +286 -0
  649. package/src/internal/metric.ts +522 -0
  650. package/src/internal/opCodes/cause.ts +35 -0
  651. package/src/internal/opCodes/channel.ts +83 -0
  652. package/src/internal/opCodes/channelChildExecutorDecision.ts +17 -0
  653. package/src/internal/opCodes/channelMergeDecision.ts +11 -0
  654. package/src/internal/opCodes/channelMergeState.ts +17 -0
  655. package/src/internal/opCodes/channelMergeStrategy.ts +11 -0
  656. package/src/internal/opCodes/channelState.ts +23 -0
  657. package/src/internal/opCodes/channelUpstreamPullRequest.ts +11 -0
  658. package/src/internal/opCodes/channelUpstreamPullStrategy.ts +11 -0
  659. package/src/internal/opCodes/config.ts +65 -0
  660. package/src/internal/opCodes/configError.ts +35 -0
  661. package/src/internal/opCodes/continuation.ts +11 -0
  662. package/src/internal/opCodes/deferred.ts +11 -0
  663. package/src/internal/opCodes/effect.ts +83 -0
  664. package/src/internal/opCodes/layer.ts +53 -0
  665. package/src/internal/opCodes/streamHaltStrategy.ts +23 -0
  666. package/src/internal/pool.ts +499 -0
  667. package/src/internal/pubsub.ts +1557 -0
  668. package/src/internal/query.ts +199 -0
  669. package/src/internal/queue.ts +729 -0
  670. package/src/internal/random.ts +88 -0
  671. package/src/internal/ref.ts +164 -0
  672. package/src/internal/reloadable.ts +164 -0
  673. package/src/internal/request.ts +137 -0
  674. package/src/internal/resource.ts +64 -0
  675. package/src/internal/ringBuffer.ts +68 -0
  676. package/src/internal/runtime.ts +348 -0
  677. package/src/internal/runtimeFlags.ts +176 -0
  678. package/src/internal/runtimeFlagsPatch.ts +103 -0
  679. package/src/internal/schedule/decision.ts +47 -0
  680. package/src/internal/schedule/interval.ts +101 -0
  681. package/src/internal/schedule/intervals.ts +179 -0
  682. package/src/internal/schedule.ts +2096 -0
  683. package/src/internal/scopedCache.ts +634 -0
  684. package/src/internal/scopedRef.ts +133 -0
  685. package/src/internal/singleShotGen.ts +35 -0
  686. package/src/internal/sink.ts +2118 -0
  687. package/src/internal/stm/core.ts +804 -0
  688. package/src/internal/stm/opCodes/stm.ts +71 -0
  689. package/src/internal/stm/opCodes/stmState.ts +17 -0
  690. package/src/internal/stm/opCodes/strategy.ts +17 -0
  691. package/src/internal/stm/opCodes/tExit.ts +29 -0
  692. package/src/internal/stm/opCodes/tryCommit.ts +11 -0
  693. package/src/internal/stm/stm/entry.ts +59 -0
  694. package/src/internal/stm/stm/journal.ts +123 -0
  695. package/src/internal/stm/stm/opCodes/stm.ts +71 -0
  696. package/src/internal/stm/stm/opCodes/stmState.ts +17 -0
  697. package/src/internal/stm/stm/opCodes/strategy.ts +17 -0
  698. package/src/internal/stm/stm/opCodes/tExit.ts +29 -0
  699. package/src/internal/stm/stm/opCodes/tryCommit.ts +11 -0
  700. package/src/internal/stm/stm/stmState.ts +130 -0
  701. package/src/internal/stm/stm/tExit.ts +180 -0
  702. package/src/internal/stm/stm/tryCommit.ts +34 -0
  703. package/src/internal/stm/stm/txnId.ts +14 -0
  704. package/src/internal/stm/stm/versioned.ts +4 -0
  705. package/src/internal/stm/stm.ts +1491 -0
  706. package/src/internal/stm/tArray.ts +550 -0
  707. package/src/internal/stm/tDeferred.ts +79 -0
  708. package/src/internal/stm/tMap.ts +824 -0
  709. package/src/internal/stm/tPriorityQueue.ts +259 -0
  710. package/src/internal/stm/tPubSub.ts +542 -0
  711. package/src/internal/stm/tQueue.ts +400 -0
  712. package/src/internal/stm/tRandom.ts +140 -0
  713. package/src/internal/stm/tReentrantLock.ts +352 -0
  714. package/src/internal/stm/tRef.ts +190 -0
  715. package/src/internal/stm/tSemaphore.ts +113 -0
  716. package/src/internal/stm/tSet.ts +237 -0
  717. package/src/internal/stream/debounceState.ts +57 -0
  718. package/src/internal/stream/emit.ts +46 -0
  719. package/src/internal/stream/haltStrategy.ts +85 -0
  720. package/src/internal/stream/handoff.ts +185 -0
  721. package/src/internal/stream/handoffSignal.ts +59 -0
  722. package/src/internal/stream/pull.ts +35 -0
  723. package/src/internal/stream/sinkEndReason.ts +30 -0
  724. package/src/internal/stream/zipAllState.ts +88 -0
  725. package/src/internal/stream/zipChunksState.ts +56 -0
  726. package/src/internal/stream.ts +8089 -0
  727. package/src/internal/string-utils.ts +107 -0
  728. package/src/internal/subscriptionRef.ts +133 -0
  729. package/src/internal/supervisor/patch.ts +190 -0
  730. package/src/internal/supervisor.ts +301 -0
  731. package/src/internal/synchronizedRef.ts +115 -0
  732. package/src/internal/take.ts +198 -0
  733. package/src/internal/testing/sleep.ts +27 -0
  734. package/src/internal/testing/suspendedWarningData.ts +85 -0
  735. package/src/internal/testing/warningData.ts +94 -0
  736. package/src/internal/timeout.ts +23 -0
  737. package/src/internal/tracer.ts +74 -0
  738. package/Error/dist/effect-Error.cjs.d.mts +0 -2
  739. package/Error/dist/effect-Error.cjs.d.mts.map +0 -1
  740. package/Error/dist/effect-Error.cjs.d.ts +0 -2
  741. package/Error/dist/effect-Error.cjs.d.ts.map +0 -1
  742. package/Error/dist/effect-Error.cjs.dev.js +0 -140
  743. package/Error/dist/effect-Error.cjs.js +0 -7
  744. package/Error/dist/effect-Error.cjs.mjs +0 -4
  745. package/Error/dist/effect-Error.cjs.prod.js +0 -140
  746. package/Error/dist/effect-Error.esm.js +0 -47
  747. package/Error/package.json +0 -4
  748. package/Hub/dist/effect-Hub.cjs.d.mts +0 -2
  749. package/Hub/dist/effect-Hub.cjs.d.mts.map +0 -1
  750. package/Hub/dist/effect-Hub.cjs.d.ts +0 -2
  751. package/Hub/dist/effect-Hub.cjs.d.ts.map +0 -1
  752. package/Hub/dist/effect-Hub.cjs.js +0 -7
  753. package/Hub/package.json +0 -4
  754. package/THub/dist/effect-THub.cjs.d.mts +0 -2
  755. package/THub/dist/effect-THub.cjs.d.mts.map +0 -1
  756. package/THub/dist/effect-THub.cjs.d.ts +0 -2
  757. package/THub/dist/effect-THub.cjs.d.ts.map +0 -1
  758. package/THub/dist/effect-THub.cjs.js +0 -7
  759. package/THub/dist/effect-THub.esm.js +0 -157
  760. package/THub/package.json +0 -4
  761. package/dist/declarations/src/Error.d.ts +0 -37
  762. package/dist/declarations/src/Error.d.ts.map +0 -1
  763. package/dist/declarations/src/Hub.d.ts.map +0 -1
  764. package/dist/declarations/src/THub.d.ts +0 -146
  765. package/dist/declarations/src/THub.d.ts.map +0 -1
  766. package/dist/scopedRef-1c2c9acf.cjs.prod.js +0 -55
  767. package/dist/scopedRef-ab4c58b0.cjs.dev.js +0 -55
  768. /package/dist/{FiberId-e594f6e8.cjs.prod.js → FiberId-1d7ac632.cjs.prod.js} +0 -0
  769. /package/dist/{FiberId-557db880.cjs.dev.js → FiberId-d88ddce6.cjs.dev.js} +0 -0
  770. /package/dist/{RuntimeFlagsPatch-ea268c50.cjs.dev.js → RuntimeFlagsPatch-69102b03.cjs.dev.js} +0 -0
  771. /package/dist/{RuntimeFlagsPatch-e2769b87.cjs.prod.js → RuntimeFlagsPatch-866fa259.cjs.prod.js} +0 -0
  772. /package/dist/{boundaries-20cfad9d.cjs.prod.js → boundaries-9af538e3.cjs.prod.js} +0 -0
  773. /package/dist/{boundaries-3810d885.cjs.dev.js → boundaries-f212e414.cjs.dev.js} +0 -0
  774. /package/dist/{configError-33e55472.cjs.prod.js → configError-b43723af.cjs.prod.js} +0 -0
  775. /package/dist/{configError-240e9b61.cjs.dev.js → configError-d5efe9c0.cjs.dev.js} +0 -0
  776. /package/dist/{configSecret-e34c1b14.cjs.dev.js → configSecret-3e8ae336.cjs.dev.js} +0 -0
  777. /package/dist/{configSecret-d1caca55.cjs.prod.js → configSecret-e2faa181.cjs.prod.js} +0 -0
  778. /package/dist/{take-2af6e92a.cjs.prod.js → take-85daaf79.cjs.prod.js} +0 -0
  779. /package/dist/{take-df9480a8.cjs.dev.js → take-f9ef9e2e.cjs.dev.js} +0 -0
@@ -0,0 +1,2118 @@
1
+ import * as Cause from "../Cause"
2
+ import type * as Channel from "../Channel"
3
+ import type * as MergeDecision from "../ChannelMergeDecision"
4
+ import * as Chunk from "../Chunk"
5
+ import * as Clock from "../Clock"
6
+ import type * as Context from "../Context"
7
+ import * as Duration from "../Duration"
8
+ import * as Effect from "../Effect"
9
+ import * as Either from "../Either"
10
+ import * as Exit from "../Exit"
11
+ import { constTrue, dual, identity, pipe } from "../Function"
12
+ import type { LazyArg } from "../Function"
13
+ import * as HashMap from "../HashMap"
14
+ import * as HashSet from "../HashSet"
15
+ import * as Option from "../Option"
16
+ import { pipeArguments } from "../Pipeable"
17
+ import type { Predicate, Refinement } from "../Predicate"
18
+ import * as PubSub from "../PubSub"
19
+ import * as Queue from "../Queue"
20
+ import * as ReadonlyArray from "../ReadonlyArray"
21
+ import * as Ref from "../Ref"
22
+ import type * as Scope from "../Scope"
23
+ import type * as Sink from "../Sink"
24
+ import * as channel from "./channel"
25
+ import * as mergeDecision from "./channel/mergeDecision"
26
+ import * as core from "./core-stream"
27
+
28
+ /** @internal */
29
+ export const SinkTypeId: Sink.SinkTypeId = Symbol.for("effect/Sink") as Sink.SinkTypeId
30
+
31
+ /** @internal */
32
+ const sinkVariance = {
33
+ _R: (_: never) => _,
34
+ _E: (_: never) => _,
35
+ _In: (_: unknown) => _,
36
+ _L: (_: never) => _,
37
+ _Z: (_: never) => _
38
+ }
39
+
40
+ /** @internal */
41
+ export class SinkImpl<R, E, In, L, Z> implements Sink.Sink<R, E, In, L, Z> {
42
+ readonly [SinkTypeId] = sinkVariance
43
+ constructor(
44
+ readonly channel: Channel.Channel<R, never, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<L>, Z>
45
+ ) {
46
+ }
47
+ pipe() {
48
+ return pipeArguments(this, arguments)
49
+ }
50
+ }
51
+
52
+ /** @internal */
53
+ export const isSink = (u: unknown): u is Sink.Sink<unknown, unknown, unknown, unknown, unknown> =>
54
+ typeof u === "object" && u != null && SinkTypeId in u
55
+
56
+ /** @internal */
57
+ export const suspend = <R, E, In, L, Z>(evaluate: LazyArg<Sink.Sink<R, E, In, L, Z>>): Sink.Sink<R, E, In, L, Z> =>
58
+ new SinkImpl(core.suspend(() => toChannel(evaluate())))
59
+
60
+ /** @internal */
61
+ export const as = dual<
62
+ <Z2>(z: Z2) => <R, E, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In, L, Z2>,
63
+ <R, E, In, L, Z, Z2>(self: Sink.Sink<R, E, In, L, Z>, z: Z2) => Sink.Sink<R, E, In, L, Z2>
64
+ >(
65
+ 2,
66
+ <R, E, In, L, Z, Z2>(self: Sink.Sink<R, E, In, L, Z>, z: Z2): Sink.Sink<R, E, In, L, Z2> => pipe(self, map(() => z))
67
+ )
68
+
69
+ /** @internal */
70
+ export const collectAll = <In>(): Sink.Sink<never, never, In, never, Chunk.Chunk<In>> =>
71
+ new SinkImpl(collectAllLoop(Chunk.empty()))
72
+
73
+ /** @internal */
74
+ const collectAllLoop = <In>(
75
+ acc: Chunk.Chunk<In>
76
+ ): Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, never, Chunk.Chunk<In>> =>
77
+ core.readWithCause({
78
+ onInput: (chunk: Chunk.Chunk<In>) => collectAllLoop(pipe(acc, Chunk.appendAll(chunk))),
79
+ onFailure: core.failCause,
80
+ onDone: () => core.succeed(acc)
81
+ })
82
+
83
+ /** @internal */
84
+ export const collectAllN = <In>(n: number): Sink.Sink<never, never, In, In, Chunk.Chunk<In>> =>
85
+ suspend(() => fromChannel(collectAllNLoop(n, Chunk.empty())))
86
+
87
+ /** @internal */
88
+ const collectAllNLoop = <In>(
89
+ n: number,
90
+ acc: Chunk.Chunk<In>
91
+ ): Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, Chunk.Chunk<In>, Chunk.Chunk<In>> =>
92
+ core.readWithCause({
93
+ onInput: (chunk: Chunk.Chunk<In>) => {
94
+ const [collected, leftovers] = Chunk.splitAt(chunk, n)
95
+ if (collected.length < n) {
96
+ return collectAllNLoop(n - collected.length, Chunk.appendAll(acc, collected))
97
+ }
98
+ if (Chunk.isEmpty(leftovers)) {
99
+ return core.succeed(Chunk.appendAll(acc, collected))
100
+ }
101
+ return core.flatMap(core.write(leftovers), () => core.succeed(Chunk.appendAll(acc, collected)))
102
+ },
103
+ onFailure: core.failCause,
104
+ onDone: () => core.succeed(acc)
105
+ })
106
+
107
+ /** @internal */
108
+ export const collectAllFrom = <R, E, In, L extends In, Z>(
109
+ self: Sink.Sink<R, E, In, L, Z>
110
+ ): Sink.Sink<R, E, In, L, Chunk.Chunk<Z>> =>
111
+ collectAllWhileWith(self, {
112
+ initial: Chunk.empty<Z>(),
113
+ while: constTrue,
114
+ body: (chunk, z) => pipe(chunk, Chunk.append(z))
115
+ })
116
+
117
+ /** @internal */
118
+ export const collectAllToMap = <In, K>(
119
+ key: (input: In) => K,
120
+ merge: (x: In, y: In) => In
121
+ ): Sink.Sink<never, never, In, never, HashMap.HashMap<K, In>> => {
122
+ return pipe(
123
+ foldLeftChunks(HashMap.empty<K, In>(), (map, chunk) =>
124
+ pipe(
125
+ chunk,
126
+ Chunk.reduce(map, (map, input) => {
127
+ const k: K = key(input)
128
+ const v: In = pipe(map, HashMap.has(k)) ?
129
+ merge(pipe(map, HashMap.unsafeGet(k)), input) :
130
+ input
131
+ return pipe(map, HashMap.set(k, v))
132
+ })
133
+ ))
134
+ )
135
+ }
136
+
137
+ /** @internal */
138
+ export const collectAllToMapN = <In, K>(
139
+ n: number,
140
+ key: (input: In) => K,
141
+ merge: (x: In, y: In) => In
142
+ ): Sink.Sink<never, never, In, In, HashMap.HashMap<K, In>> => {
143
+ return foldWeighted<HashMap.HashMap<K, In>, In>({
144
+ initial: HashMap.empty(),
145
+ maxCost: n,
146
+ cost: (acc, input) => pipe(acc, HashMap.has(key(input))) ? 0 : 1,
147
+ body: (acc, input) => {
148
+ const k: K = key(input)
149
+ const v: In = pipe(acc, HashMap.has(k)) ?
150
+ merge(pipe(acc, HashMap.unsafeGet(k)), input) :
151
+ input
152
+ return pipe(acc, HashMap.set(k, v))
153
+ }
154
+ })
155
+ }
156
+
157
+ /** @internal */
158
+ export const collectAllToSet = <In>(): Sink.Sink<never, never, In, never, HashSet.HashSet<In>> =>
159
+ foldLeftChunks<HashSet.HashSet<In>, In>(
160
+ HashSet.empty(),
161
+ (acc, chunk) => pipe(chunk, Chunk.reduce(acc, (acc, input) => pipe(acc, HashSet.add(input))))
162
+ )
163
+
164
+ /** @internal */
165
+ export const collectAllToSetN = <In>(n: number): Sink.Sink<never, never, In, In, HashSet.HashSet<In>> =>
166
+ foldWeighted<HashSet.HashSet<In>, In>({
167
+ initial: HashSet.empty(),
168
+ maxCost: n,
169
+ cost: (acc, input) => HashSet.has(acc, input) ? 0 : 1,
170
+ body: (acc, input) => HashSet.add(acc, input)
171
+ })
172
+
173
+ /** @internal */
174
+ export const collectAllUntil = <In>(p: Predicate<In>): Sink.Sink<never, never, In, In, Chunk.Chunk<In>> => {
175
+ return pipe(
176
+ fold<readonly [Chunk.Chunk<In>, boolean], In>(
177
+ [Chunk.empty(), true],
178
+ (tuple) => tuple[1],
179
+ ([chunk, _], input) => [pipe(chunk, Chunk.append(input)), !p(input)] as const
180
+ ),
181
+ map((tuple) => tuple[0])
182
+ )
183
+ }
184
+
185
+ /** @internal */
186
+ export const collectAllUntilEffect = <In, R, E>(p: (input: In) => Effect.Effect<R, E, boolean>) => {
187
+ return pipe(
188
+ foldEffect<readonly [Chunk.Chunk<In>, boolean], R, E, In>(
189
+ [Chunk.empty(), true],
190
+ (tuple) => tuple[1],
191
+ ([chunk, _], input) => pipe(p(input), Effect.map((bool) => [pipe(chunk, Chunk.append(input)), !bool]))
192
+ ),
193
+ map((tuple) => tuple[0])
194
+ )
195
+ }
196
+
197
+ /** @internal */
198
+ export const collectAllWhile = <In>(predicate: Predicate<In>): Sink.Sink<never, never, In, In, Chunk.Chunk<In>> =>
199
+ fromChannel(collectAllWhileReader(predicate, Chunk.empty()))
200
+
201
+ /** @internal */
202
+ const collectAllWhileReader = <In>(
203
+ predicate: Predicate<In>,
204
+ done: Chunk.Chunk<In>
205
+ ): Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, Chunk.Chunk<In>, Chunk.Chunk<In>> =>
206
+ core.readWith({
207
+ onInput: (input: Chunk.Chunk<In>) => {
208
+ const [collected, leftovers] = pipe(Chunk.toReadonlyArray(input), ReadonlyArray.span(predicate))
209
+ if (leftovers.length === 0) {
210
+ return collectAllWhileReader(
211
+ predicate,
212
+ pipe(done, Chunk.appendAll(Chunk.unsafeFromArray(collected)))
213
+ )
214
+ }
215
+ return pipe(
216
+ core.write(Chunk.unsafeFromArray(leftovers)),
217
+ channel.zipRight(core.succeed(pipe(done, Chunk.appendAll(Chunk.unsafeFromArray(collected)))))
218
+ )
219
+ },
220
+ onFailure: core.fail,
221
+ onDone: () => core.succeed(done)
222
+ })
223
+
224
+ /** @internal */
225
+ export const collectAllWhileEffect = <In, R, E>(
226
+ predicate: (input: In) => Effect.Effect<R, E, boolean>
227
+ ): Sink.Sink<R, E, In, In, Chunk.Chunk<In>> => fromChannel(collectAllWhileEffectReader(predicate, Chunk.empty()))
228
+
229
+ /** @internal */
230
+ const collectAllWhileEffectReader = <In, R, E>(
231
+ predicate: (input: In) => Effect.Effect<R, E, boolean>,
232
+ done: Chunk.Chunk<In>
233
+ ): Channel.Channel<R, never, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<In>, Chunk.Chunk<In>> =>
234
+ core.readWith({
235
+ onInput: (input: Chunk.Chunk<In>) =>
236
+ pipe(
237
+ core.fromEffect(pipe(input, Effect.takeWhile(predicate), Effect.map(Chunk.unsafeFromArray))),
238
+ core.flatMap((collected) => {
239
+ const leftovers = pipe(input, Chunk.drop(collected.length))
240
+ if (Chunk.isEmpty(leftovers)) {
241
+ return collectAllWhileEffectReader(predicate, pipe(done, Chunk.appendAll(collected)))
242
+ }
243
+ return pipe(core.write(leftovers), channel.zipRight(core.succeed(pipe(done, Chunk.appendAll(collected)))))
244
+ })
245
+ ),
246
+ onFailure: core.fail,
247
+ onDone: () => core.succeed(done)
248
+ })
249
+
250
+ /** @internal */
251
+ export const collectAllWhileWith = dual<
252
+ <Z, S>(
253
+ options: {
254
+ readonly initial: S
255
+ readonly while: Predicate<Z>
256
+ readonly body: (s: S, z: Z) => S
257
+ }
258
+ ) => <R, E, In, L extends In>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In, L, S>,
259
+ <R, E, In, L extends In, Z, S>(
260
+ self: Sink.Sink<R, E, In, L, Z>,
261
+ options: {
262
+ readonly initial: S
263
+ readonly while: Predicate<Z>
264
+ readonly body: (s: S, z: Z) => S
265
+ }
266
+ ) => Sink.Sink<R, E, In, L, S>
267
+ >(
268
+ 2,
269
+ <R, E, In, L extends In, Z, S>(
270
+ self: Sink.Sink<R, E, In, L, Z>,
271
+ options: {
272
+ readonly initial: S
273
+ readonly while: Predicate<Z>
274
+ readonly body: (s: S, z: Z) => S
275
+ }
276
+ ): Sink.Sink<R, E, In, L, S> => {
277
+ const refs = pipe(
278
+ Ref.make(Chunk.empty<In>()),
279
+ Effect.zip(Ref.make(false))
280
+ )
281
+ const newChannel = pipe(
282
+ core.fromEffect(refs),
283
+ core.flatMap(([leftoversRef, upstreamDoneRef]) => {
284
+ const upstreamMarker: Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, Chunk.Chunk<In>, unknown> =
285
+ core.readWith({
286
+ onInput: (input) => pipe(core.write(input), core.flatMap(() => upstreamMarker)),
287
+ onFailure: core.fail,
288
+ onDone: (done) => pipe(core.fromEffect(Ref.set(upstreamDoneRef, true)), channel.as(done))
289
+ })
290
+ return pipe(
291
+ upstreamMarker,
292
+ core.pipeTo(channel.bufferChunk(leftoversRef)),
293
+ core.pipeTo(
294
+ collectAllWhileWithLoop(self, leftoversRef, upstreamDoneRef, options.initial, options.while, options.body)
295
+ )
296
+ )
297
+ })
298
+ )
299
+ return new SinkImpl(newChannel)
300
+ }
301
+ )
302
+
303
+ /** @internal */
304
+ const collectAllWhileWithLoop = <R, E, In, L extends In, Z, S>(
305
+ self: Sink.Sink<R, E, In, L, Z>,
306
+ leftoversRef: Ref.Ref<Chunk.Chunk<In>>,
307
+ upstreamDoneRef: Ref.Ref<boolean>,
308
+ currentResult: S,
309
+ p: Predicate<Z>,
310
+ f: (s: S, z: Z) => S
311
+ ): Channel.Channel<R, never, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<L>, S> => {
312
+ return pipe(
313
+ toChannel(self),
314
+ channel.doneCollect,
315
+ channel.foldChannel({
316
+ onFailure: core.fail,
317
+ onSuccess: ([leftovers, doneValue]) =>
318
+ p(doneValue)
319
+ ? pipe(
320
+ core.fromEffect(
321
+ Ref.set(leftoversRef, Chunk.flatten(leftovers as Chunk.Chunk<Chunk.Chunk<In>>))
322
+ ),
323
+ core.flatMap(() =>
324
+ pipe(
325
+ core.fromEffect(Ref.get(upstreamDoneRef)),
326
+ core.flatMap((upstreamDone) => {
327
+ const accumulatedResult = f(currentResult, doneValue)
328
+ return upstreamDone
329
+ ? pipe(core.write(Chunk.flatten(leftovers)), channel.as(accumulatedResult))
330
+ : collectAllWhileWithLoop(self, leftoversRef, upstreamDoneRef, accumulatedResult, p, f)
331
+ })
332
+ )
333
+ )
334
+ )
335
+ : pipe(core.write(Chunk.flatten(leftovers)), channel.as(currentResult))
336
+ })
337
+ )
338
+ }
339
+
340
+ /** @internal */
341
+ export const collectLeftover = <R, E, In, L, Z>(
342
+ self: Sink.Sink<R, E, In, L, Z>
343
+ ): Sink.Sink<R, E, In, never, readonly [Z, Chunk.Chunk<L>]> =>
344
+ new SinkImpl(pipe(core.collectElements(toChannel(self)), channel.map(([chunks, z]) => [z, Chunk.flatten(chunks)])))
345
+
346
+ /** @internal */
347
+ export const mapInput = dual<
348
+ <In0, In>(f: (input: In0) => In) => <R, E, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In0, L, Z>,
349
+ <R, E, L, Z, In0, In>(self: Sink.Sink<R, E, In, L, Z>, f: (input: In0) => In) => Sink.Sink<R, E, In0, L, Z>
350
+ >(
351
+ 2,
352
+ <R, E, L, Z, In0, In>(self: Sink.Sink<R, E, In, L, Z>, f: (input: In0) => In): Sink.Sink<R, E, In0, L, Z> =>
353
+ pipe(self, mapInputChunks(Chunk.map(f)))
354
+ )
355
+
356
+ /** @internal */
357
+ export const mapInputEffect = dual<
358
+ <In0, R2, E2, In>(
359
+ f: (input: In0) => Effect.Effect<R2, E2, In>
360
+ ) => <R, E, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In0, L, Z>,
361
+ <R, E, L, Z, In0, R2, E2, In>(
362
+ self: Sink.Sink<R, E, In, L, Z>,
363
+ f: (input: In0) => Effect.Effect<R2, E2, In>
364
+ ) => Sink.Sink<R2 | R, E2 | E, In0, L, Z>
365
+ >(
366
+ 2,
367
+ <R, E, L, Z, In0, R2, E2, In>(
368
+ self: Sink.Sink<R, E, In, L, Z>,
369
+ f: (input: In0) => Effect.Effect<R2, E2, In>
370
+ ): Sink.Sink<R | R2, E | E2, In0, L, Z> =>
371
+ mapInputChunksEffect(
372
+ self,
373
+ (chunk) =>
374
+ Effect.map(
375
+ Effect.forEach(chunk, (v) => f(v)),
376
+ Chunk.unsafeFromArray
377
+ )
378
+ )
379
+ )
380
+
381
+ /** @internal */
382
+ export const mapInputChunks = dual<
383
+ <In0, In>(
384
+ f: (chunk: Chunk.Chunk<In0>) => Chunk.Chunk<In>
385
+ ) => <R, E, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In0, L, Z>,
386
+ <R, E, L, Z, In0, In>(
387
+ self: Sink.Sink<R, E, In, L, Z>,
388
+ f: (chunk: Chunk.Chunk<In0>) => Chunk.Chunk<In>
389
+ ) => Sink.Sink<R, E, In0, L, Z>
390
+ >(
391
+ 2,
392
+ <R, E, L, Z, In0, In>(
393
+ self: Sink.Sink<R, E, In, L, Z>,
394
+ f: (chunk: Chunk.Chunk<In0>) => Chunk.Chunk<In>
395
+ ): Sink.Sink<R, E, In0, L, Z> => {
396
+ const loop: Channel.Channel<R, never, Chunk.Chunk<In0>, unknown, never, Chunk.Chunk<In>, unknown> = core.readWith({
397
+ onInput: (chunk) => pipe(core.write(f(chunk)), core.flatMap(() => loop)),
398
+ onFailure: core.fail,
399
+ onDone: core.succeed
400
+ })
401
+ return new SinkImpl(pipe(loop, core.pipeTo(toChannel(self))))
402
+ }
403
+ )
404
+
405
+ /** @internal */
406
+ export const mapInputChunksEffect = dual<
407
+ <In0, R2, E2, In>(
408
+ f: (chunk: Chunk.Chunk<In0>) => Effect.Effect<R2, E2, Chunk.Chunk<In>>
409
+ ) => <R, E, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In0, L, Z>,
410
+ <R, E, L, Z, In0, R2, E2, In>(
411
+ self: Sink.Sink<R, E, In, L, Z>,
412
+ f: (chunk: Chunk.Chunk<In0>) => Effect.Effect<R2, E2, Chunk.Chunk<In>>
413
+ ) => Sink.Sink<R2 | R, E2 | E, In0, L, Z>
414
+ >(
415
+ 2,
416
+ <R, E, L, Z, In0, R2, E2, In>(
417
+ self: Sink.Sink<R, E, In, L, Z>,
418
+ f: (chunk: Chunk.Chunk<In0>) => Effect.Effect<R2, E2, Chunk.Chunk<In>>
419
+ ): Sink.Sink<R | R2, E | E2, In0, L, Z> => {
420
+ const loop: Channel.Channel<R | R2, never, Chunk.Chunk<In0>, unknown, E2, Chunk.Chunk<In>, unknown> = core
421
+ .readWith({
422
+ onInput: (chunk) => pipe(core.fromEffect(f(chunk)), core.flatMap(core.write), core.flatMap(() => loop)),
423
+ onFailure: core.fail,
424
+ onDone: core.succeed
425
+ })
426
+ return new SinkImpl(pipe(loop, channel.pipeToOrFail(toChannel(self))))
427
+ }
428
+ )
429
+
430
+ /** @internal */
431
+ export const die = (defect: unknown): Sink.Sink<never, never, unknown, never, never> => failCause(Cause.die(defect))
432
+
433
+ /** @internal */
434
+ export const dieMessage = (message: string): Sink.Sink<never, never, unknown, never, never> =>
435
+ failCause(Cause.die(Cause.RuntimeException(message)))
436
+
437
+ /** @internal */
438
+ export const dieSync = (evaluate: LazyArg<unknown>): Sink.Sink<never, never, unknown, never, never> =>
439
+ failCauseSync(() => Cause.die(evaluate()))
440
+
441
+ /** @internal */
442
+ export const dimap = dual<
443
+ <In0, In, Z, Z2>(
444
+ options: {
445
+ readonly onInput: (input: In0) => In
446
+ readonly onDone: (z: Z) => Z2
447
+ }
448
+ ) => <R, E, L>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In0, L, Z2>,
449
+ <R, E, L, In0, In, Z, Z2>(
450
+ self: Sink.Sink<R, E, In, L, Z>,
451
+ options: {
452
+ readonly onInput: (input: In0) => In
453
+ readonly onDone: (z: Z) => Z2
454
+ }
455
+ ) => Sink.Sink<R, E, In0, L, Z2>
456
+ >(
457
+ 2,
458
+ <R, E, L, In0, In, Z, Z2>(
459
+ self: Sink.Sink<R, E, In, L, Z>,
460
+ options: {
461
+ readonly onInput: (input: In0) => In
462
+ readonly onDone: (z: Z) => Z2
463
+ }
464
+ ): Sink.Sink<R, E, In0, L, Z2> => map(mapInput(self, options.onInput), options.onDone)
465
+ )
466
+
467
+ /** @internal */
468
+ export const dimapEffect = dual<
469
+ <In0, R2, E2, In, Z, R3, E3, Z2>(
470
+ options: {
471
+ readonly onInput: (input: In0) => Effect.Effect<R2, E2, In>
472
+ readonly onDone: (z: Z) => Effect.Effect<R3, E3, Z2>
473
+ }
474
+ ) => <R, E, L>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R3 | R, E2 | E3 | E, In0, L, Z2>,
475
+ <R, E, L, In0, R2, E2, In, Z, R3, E3, Z2>(
476
+ self: Sink.Sink<R, E, In, L, Z>,
477
+ options: {
478
+ readonly onInput: (input: In0) => Effect.Effect<R2, E2, In>
479
+ readonly onDone: (z: Z) => Effect.Effect<R3, E3, Z2>
480
+ }
481
+ ) => Sink.Sink<R2 | R3 | R, E2 | E3 | E, In0, L, Z2>
482
+ >(
483
+ 2,
484
+ <R, E, L, In0, R2, E2, In, Z, R3, E3, Z2>(
485
+ self: Sink.Sink<R, E, In, L, Z>,
486
+ options: {
487
+ readonly onInput: (input: In0) => Effect.Effect<R2, E2, In>
488
+ readonly onDone: (z: Z) => Effect.Effect<R3, E3, Z2>
489
+ }
490
+ ): Sink.Sink<R | R2 | R3, E | E2 | E3, In0, L, Z2> =>
491
+ mapEffect(
492
+ mapInputEffect(self, options.onInput),
493
+ options.onDone
494
+ )
495
+ )
496
+
497
+ /** @internal */
498
+ export const dimapChunks = dual<
499
+ <In0, In, Z, Z2>(
500
+ options: {
501
+ readonly onInput: (chunk: Chunk.Chunk<In0>) => Chunk.Chunk<In>
502
+ readonly onDone: (z: Z) => Z2
503
+ }
504
+ ) => <R, E, L>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In0, L, Z2>,
505
+ <R, E, L, In0, In, Z, Z2>(
506
+ self: Sink.Sink<R, E, In, L, Z>,
507
+ options: {
508
+ readonly onInput: (chunk: Chunk.Chunk<In0>) => Chunk.Chunk<In>
509
+ readonly onDone: (z: Z) => Z2
510
+ }
511
+ ) => Sink.Sink<R, E, In0, L, Z2>
512
+ >(
513
+ 2,
514
+ <R, E, L, In0, In, Z, Z2>(
515
+ self: Sink.Sink<R, E, In, L, Z>,
516
+ options: {
517
+ readonly onInput: (chunk: Chunk.Chunk<In0>) => Chunk.Chunk<In>
518
+ readonly onDone: (z: Z) => Z2
519
+ }
520
+ ): Sink.Sink<R, E, In0, L, Z2> =>
521
+ map(
522
+ mapInputChunks(self, options.onInput),
523
+ options.onDone
524
+ )
525
+ )
526
+
527
+ /** @internal */
528
+ export const dimapChunksEffect = dual<
529
+ <In0, R2, E2, In, Z, R3, E3, Z2>(
530
+ options: {
531
+ readonly onInput: (chunk: Chunk.Chunk<In0>) => Effect.Effect<R2, E2, Chunk.Chunk<In>>
532
+ readonly onDone: (z: Z) => Effect.Effect<R3, E3, Z2>
533
+ }
534
+ ) => <R, E, L>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R3 | R, E2 | E3 | E, In0, L, Z2>,
535
+ <R, E, L, In0, R2, E2, In, Z, R3, E3, Z2>(
536
+ self: Sink.Sink<R, E, In, L, Z>,
537
+ options: {
538
+ readonly onInput: (chunk: Chunk.Chunk<In0>) => Effect.Effect<R2, E2, Chunk.Chunk<In>>
539
+ readonly onDone: (z: Z) => Effect.Effect<R3, E3, Z2>
540
+ }
541
+ ) => Sink.Sink<R2 | R3 | R, E2 | E3 | E, In0, L, Z2>
542
+ >(
543
+ 2,
544
+ <R, E, L, In0, R2, E2, In, Z, R3, E3, Z2>(
545
+ self: Sink.Sink<R, E, In, L, Z>,
546
+ options: {
547
+ readonly onInput: (chunk: Chunk.Chunk<In0>) => Effect.Effect<R2, E2, Chunk.Chunk<In>>
548
+ readonly onDone: (z: Z) => Effect.Effect<R3, E3, Z2>
549
+ }
550
+ ): Sink.Sink<R | R2 | R3, E | E2 | E3, In0, L, Z2> =>
551
+ mapEffect(mapInputChunksEffect(self, options.onInput), options.onDone)
552
+ )
553
+
554
+ /** @internal */
555
+ export const drain: Sink.Sink<never, never, unknown, never, void> = new SinkImpl(
556
+ channel.drain(channel.identityChannel<never, unknown, unknown>())
557
+ )
558
+
559
+ /** @internal */
560
+ export const drop = <In>(n: number): Sink.Sink<never, never, In, In, unknown> =>
561
+ suspend(() => new SinkImpl(dropLoop(n)))
562
+
563
+ /** @internal */
564
+ const dropLoop = <In>(
565
+ n: number
566
+ ): Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, Chunk.Chunk<In>, unknown> =>
567
+ core.readWith({
568
+ onInput: (input: Chunk.Chunk<In>) => {
569
+ const dropped = pipe(input, Chunk.drop(n))
570
+ const leftover = Math.max(n - input.length, 0)
571
+ const more = Chunk.isEmpty(input) || leftover > 0
572
+ if (more) {
573
+ return dropLoop(leftover)
574
+ }
575
+ return pipe(
576
+ core.write(dropped),
577
+ channel.zipRight(channel.identityChannel<never, Chunk.Chunk<In>, unknown>())
578
+ )
579
+ },
580
+ onFailure: core.fail,
581
+ onDone: () => core.unit
582
+ })
583
+
584
+ /** @internal */
585
+ export const dropUntil = <In>(predicate: Predicate<In>): Sink.Sink<never, never, In, In, unknown> =>
586
+ new SinkImpl(
587
+ pipe(toChannel(dropWhile((input: In) => !predicate(input))), channel.pipeToOrFail(toChannel(drop<In>(1))))
588
+ )
589
+
590
+ /** @internal */
591
+ export const dropUntilEffect = <In, R, E>(
592
+ predicate: (input: In) => Effect.Effect<R, E, boolean>
593
+ ): Sink.Sink<R, E, In, In, unknown> => suspend(() => new SinkImpl(dropUntilEffectReader(predicate)))
594
+
595
+ /** @internal */
596
+ const dropUntilEffectReader = <In, R, E>(
597
+ predicate: (input: In) => Effect.Effect<R, E, boolean>
598
+ ): Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<In>, unknown> =>
599
+ core.readWith({
600
+ onInput: (input: Chunk.Chunk<In>) =>
601
+ pipe(
602
+ input,
603
+ Effect.dropUntil(predicate),
604
+ Effect.map((leftover) => {
605
+ const more = leftover.length === 0
606
+ return more ?
607
+ dropUntilEffectReader(predicate) :
608
+ pipe(
609
+ core.write(Chunk.unsafeFromArray(leftover)),
610
+ channel.zipRight(channel.identityChannel<E, Chunk.Chunk<In>, unknown>())
611
+ )
612
+ }),
613
+ channel.unwrap
614
+ ),
615
+ onFailure: core.fail,
616
+ onDone: () => core.unit
617
+ })
618
+
619
+ /** @internal */
620
+ export const dropWhile = <In>(predicate: Predicate<In>): Sink.Sink<never, never, In, In, unknown> =>
621
+ new SinkImpl(dropWhileReader(predicate))
622
+
623
+ /** @internal */
624
+ const dropWhileReader = <In>(
625
+ predicate: Predicate<In>
626
+ ): Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, Chunk.Chunk<In>, unknown> =>
627
+ core.readWith({
628
+ onInput: (input: Chunk.Chunk<In>) => {
629
+ const out = pipe(input, Chunk.dropWhile(predicate))
630
+ if (Chunk.isEmpty(out)) {
631
+ return dropWhileReader(predicate)
632
+ }
633
+ return pipe(core.write(out), channel.zipRight(channel.identityChannel<never, Chunk.Chunk<In>, unknown>()))
634
+ },
635
+ onFailure: core.fail,
636
+ onDone: core.succeedNow
637
+ })
638
+
639
+ /** @internal */
640
+ export const dropWhileEffect = <In, R, E>(
641
+ predicate: (input: In) => Effect.Effect<R, E, boolean>
642
+ ): Sink.Sink<R, E, In, In, unknown> => suspend(() => new SinkImpl(dropWhileEffectReader(predicate)))
643
+
644
+ /** @internal */
645
+ const dropWhileEffectReader = <In, R, E>(
646
+ predicate: (input: In) => Effect.Effect<R, E, boolean>
647
+ ): Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<In>, unknown> =>
648
+ core.readWith({
649
+ onInput: (input: Chunk.Chunk<In>) =>
650
+ pipe(
651
+ input,
652
+ Effect.dropWhile(predicate),
653
+ Effect.map((leftover) => {
654
+ const more = leftover.length === 0
655
+ return more ?
656
+ dropWhileEffectReader(predicate) :
657
+ pipe(
658
+ core.write(Chunk.unsafeFromArray(leftover)),
659
+ channel.zipRight(channel.identityChannel<E, Chunk.Chunk<In>, unknown>())
660
+ )
661
+ }),
662
+ channel.unwrap
663
+ ),
664
+ onFailure: core.fail,
665
+ onDone: () => core.unit
666
+ })
667
+
668
+ /** @internal */
669
+ export const ensuring = dual<
670
+ <R2, _>(
671
+ finalizer: Effect.Effect<R2, never, _>
672
+ ) => <R, E, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E, In, L, Z>,
673
+ <R, E, In, L, Z, R2, _>(
674
+ self: Sink.Sink<R, E, In, L, Z>,
675
+ finalizer: Effect.Effect<R2, never, _>
676
+ ) => Sink.Sink<R2 | R, E, In, L, Z>
677
+ >(
678
+ 2,
679
+ <R, E, In, L, Z, R2, _>(
680
+ self: Sink.Sink<R, E, In, L, Z>,
681
+ finalizer: Effect.Effect<R2, never, _>
682
+ ): Sink.Sink<R | R2, E, In, L, Z> => new SinkImpl(pipe(self, toChannel, channel.ensuring(finalizer)))
683
+ )
684
+
685
+ /** @internal */
686
+ export const ensuringWith = dual<
687
+ <E, Z, R2, _>(
688
+ finalizer: (exit: Exit.Exit<E, Z>) => Effect.Effect<R2, never, _>
689
+ ) => <R, In, L>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E, In, L, Z>,
690
+ <R, In, L, E, Z, R2, _>(
691
+ self: Sink.Sink<R, E, In, L, Z>,
692
+ finalizer: (exit: Exit.Exit<E, Z>) => Effect.Effect<R2, never, _>
693
+ ) => Sink.Sink<R2 | R, E, In, L, Z>
694
+ >(
695
+ 2,
696
+ <R, In, L, E, Z, R2, _>(
697
+ self: Sink.Sink<R, E, In, L, Z>,
698
+ finalizer: (exit: Exit.Exit<E, Z>) => Effect.Effect<R2, never, _>
699
+ ): Sink.Sink<R | R2, E, In, L, Z> => new SinkImpl(pipe(self, toChannel, core.ensuringWith(finalizer)))
700
+ )
701
+
702
+ /** @internal */
703
+ export const context = <R>(): Sink.Sink<R, never, unknown, never, Context.Context<R>> => fromEffect(Effect.context<R>())
704
+
705
+ /** @internal */
706
+ export const contextWith = <R, Z>(
707
+ f: (context: Context.Context<R>) => Z
708
+ ): Sink.Sink<R, never, unknown, never, Z> => pipe(context<R>(), map(f))
709
+
710
+ /** @internal */
711
+ export const contextWithEffect = <R0, R, E, Z>(
712
+ f: (context: Context.Context<R0>) => Effect.Effect<R, E, Z>
713
+ ): Sink.Sink<R0 | R, E, unknown, never, Z> => pipe(context<R0>(), mapEffect(f))
714
+
715
+ /** @internal */
716
+ export const contextWithSink = <R0, R, E, In, L, Z>(
717
+ f: (context: Context.Context<R0>) => Sink.Sink<R, E, In, L, Z>
718
+ ): Sink.Sink<R0 | R, E, In, L, Z> =>
719
+ new SinkImpl(channel.unwrap(pipe(Effect.contextWith((context) => toChannel(f(context))))))
720
+
721
+ /** @internal */
722
+ export const every = <In>(predicate: Predicate<In>): Sink.Sink<never, never, In, In, boolean> =>
723
+ fold(true, identity, (acc, input) => acc && predicate(input))
724
+
725
+ /** @internal */
726
+ export const fail = <E>(e: E): Sink.Sink<never, E, unknown, never, never> => new SinkImpl(core.fail(e))
727
+
728
+ /** @internal */
729
+ export const failSync = <E>(evaluate: LazyArg<E>): Sink.Sink<never, E, unknown, never, never> =>
730
+ new SinkImpl(core.failSync(evaluate))
731
+
732
+ /** @internal */
733
+ export const failCause = <E>(cause: Cause.Cause<E>): Sink.Sink<never, E, unknown, never, never> =>
734
+ new SinkImpl(core.failCause(cause))
735
+
736
+ /** @internal */
737
+ export const failCauseSync = <E>(evaluate: LazyArg<Cause.Cause<E>>): Sink.Sink<never, E, unknown, never, never> =>
738
+ new SinkImpl(core.failCauseSync(evaluate))
739
+
740
+ /** @internal */
741
+ export const filterInput: {
742
+ <In, In1 extends In, In2 extends In1>(
743
+ f: Refinement<In1, In2>
744
+ ): <R, E, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In2, L, Z>
745
+ <In, In1 extends In>(f: Predicate<In1>): <R, E, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In1, L, Z>
746
+ } = <In, In1 extends In>(f: Predicate<In1>) => {
747
+ return <R, E, L, Z>(self: Sink.Sink<R, E, In, L, Z>): Sink.Sink<R, E, In1, L, Z> =>
748
+ pipe(self, mapInputChunks(Chunk.filter(f)))
749
+ }
750
+
751
+ /** @internal */
752
+ export const filterInputEffect = dual<
753
+ <R2, E2, In, In1 extends In>(
754
+ f: (input: In1) => Effect.Effect<R2, E2, boolean>
755
+ ) => <R, E, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In1, L, Z>,
756
+ <R, E, L, Z, R2, E2, In, In1 extends In>(
757
+ self: Sink.Sink<R, E, In, L, Z>,
758
+ f: (input: In1) => Effect.Effect<R2, E2, boolean>
759
+ ) => Sink.Sink<R2 | R, E2 | E, In1, L, Z>
760
+ >(
761
+ 2,
762
+ <R, E, L, Z, R2, E2, In, In1 extends In>(
763
+ self: Sink.Sink<R, E, In, L, Z>,
764
+ f: (input: In1) => Effect.Effect<R2, E2, boolean>
765
+ ): Sink.Sink<R | R2, E | E2, In1, L, Z> =>
766
+ mapInputChunksEffect(
767
+ self,
768
+ (chunk) => Effect.map(Effect.filter(chunk, f), Chunk.unsafeFromArray)
769
+ )
770
+ )
771
+
772
+ /** @internal */
773
+ export const findEffect = dual<
774
+ <Z, R2, E2>(
775
+ f: (z: Z) => Effect.Effect<R2, E2, boolean>
776
+ ) => <R, E, In, L extends In>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In, L, Option.Option<Z>>,
777
+ <R, E, In, L extends In, Z, R2, E2>(
778
+ self: Sink.Sink<R, E, In, L, Z>,
779
+ f: (z: Z) => Effect.Effect<R2, E2, boolean>
780
+ ) => Sink.Sink<R2 | R, E2 | E, In, L, Option.Option<Z>>
781
+ >(
782
+ 2,
783
+ <R, E, In, L extends In, Z, R2, E2>(
784
+ self: Sink.Sink<R, E, In, L, Z>,
785
+ f: (z: Z) => Effect.Effect<R2, E2, boolean>
786
+ ): Sink.Sink<R | R2, E | E2, In, L, Option.Option<Z>> => {
787
+ const newChannel = pipe(
788
+ core.fromEffect(pipe(
789
+ Ref.make(Chunk.empty<In>()),
790
+ Effect.zip(Ref.make(false))
791
+ )),
792
+ core.flatMap(([leftoversRef, upstreamDoneRef]) => {
793
+ const upstreamMarker: Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, Chunk.Chunk<In>, unknown> =
794
+ core.readWith({
795
+ onInput: (input) => pipe(core.write(input), core.flatMap(() => upstreamMarker)),
796
+ onFailure: core.fail,
797
+ onDone: (done) => pipe(core.fromEffect(Ref.set(upstreamDoneRef, true)), channel.as(done))
798
+ })
799
+ const loop: Channel.Channel<R | R2, never, Chunk.Chunk<In>, unknown, E | E2, Chunk.Chunk<L>, Option.Option<Z>> =
800
+ channel.foldChannel(core.collectElements(toChannel(self)), {
801
+ onFailure: core.fail,
802
+ onSuccess: ([leftovers, doneValue]) =>
803
+ pipe(
804
+ core.fromEffect(f(doneValue)),
805
+ core.flatMap((satisfied) =>
806
+ pipe(
807
+ core.fromEffect(Ref.set(leftoversRef, Chunk.flatten(leftovers))),
808
+ channel.zipRight(
809
+ pipe(
810
+ core.fromEffect(Ref.get(upstreamDoneRef)),
811
+ core.flatMap((upstreamDone) => {
812
+ if (satisfied) {
813
+ return pipe(core.write(Chunk.flatten(leftovers)), channel.as(Option.some(doneValue)))
814
+ }
815
+ if (upstreamDone) {
816
+ return pipe(core.write(Chunk.flatten(leftovers)), channel.as(Option.none()))
817
+ }
818
+ return loop
819
+ })
820
+ )
821
+ )
822
+ )
823
+ )
824
+ )
825
+ })
826
+ return pipe(upstreamMarker, core.pipeTo(channel.bufferChunk(leftoversRef)), core.pipeTo(loop))
827
+ })
828
+ )
829
+ return new SinkImpl(newChannel)
830
+ }
831
+ )
832
+
833
+ /** @internal */
834
+ export const fold = <S, In>(
835
+ s: S,
836
+ contFn: Predicate<S>,
837
+ f: (z: S, input: In) => S
838
+ ): Sink.Sink<never, never, In, In, S> => suspend(() => new SinkImpl(foldReader(s, contFn, f)))
839
+
840
+ /** @internal */
841
+ const foldReader = <S, In>(
842
+ s: S,
843
+ contFn: Predicate<S>,
844
+ f: (z: S, input: In) => S
845
+ ): Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, Chunk.Chunk<In>, S> => {
846
+ if (!contFn(s)) {
847
+ return core.succeedNow(s)
848
+ }
849
+ return core.readWith({
850
+ onInput: (input: Chunk.Chunk<In>) => {
851
+ const [nextS, leftovers] = foldChunkSplit(s, input, contFn, f, 0, input.length)
852
+ if (Chunk.isNonEmpty(leftovers)) {
853
+ return pipe(core.write(leftovers), channel.as(nextS))
854
+ }
855
+ return foldReader(nextS, contFn, f)
856
+ },
857
+ onFailure: core.fail,
858
+ onDone: () => core.succeedNow(s)
859
+ })
860
+ }
861
+
862
+ /** @internal */
863
+ const foldChunkSplit = <S, In>(
864
+ s: S,
865
+ chunk: Chunk.Chunk<In>,
866
+ contFn: Predicate<S>,
867
+ f: (z: S, input: In) => S,
868
+ index: number,
869
+ length: number
870
+ ): readonly [S, Chunk.Chunk<In>] => {
871
+ if (index === length) {
872
+ return [s, Chunk.empty()]
873
+ }
874
+ const s1 = f(s, pipe(chunk, Chunk.unsafeGet(index)))
875
+ if (contFn(s1)) {
876
+ return foldChunkSplit(s1, chunk, contFn, f, index + 1, length)
877
+ }
878
+ return [s1, pipe(chunk, Chunk.drop(index + 1))] as const
879
+ }
880
+
881
+ /** @internal */
882
+ export const foldSink = dual<
883
+ <R1, R2, E, E1, E2, In, In1 extends In, In2 extends In, L, L1, L2, Z, Z1, Z2>(
884
+ options: {
885
+ readonly onFailure: (err: E) => Sink.Sink<R1, E1, In1, L1, Z1>
886
+ readonly onSuccess: (z: Z) => Sink.Sink<R2, E2, In2, L2, Z2>
887
+ }
888
+ ) => <R>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R1 | R2 | R, E1 | E2, In1 & In2, L1 | L2, Z1 | Z2>,
889
+ <R, R1, R2, E, E1, E2, In, In1 extends In, In2 extends In, L, L1, L2, Z, Z1, Z2>(
890
+ self: Sink.Sink<R, E, In, L, Z>,
891
+ options: {
892
+ readonly onFailure: (err: E) => Sink.Sink<R1, E1, In1, L1, Z1>
893
+ readonly onSuccess: (z: Z) => Sink.Sink<R2, E2, In2, L2, Z2>
894
+ }
895
+ ) => Sink.Sink<R1 | R2 | R, E1 | E2, In1 & In2, L1 | L2, Z1 | Z2>
896
+ >(
897
+ 2,
898
+ <R, R1, R2, E, E1, E2, In, In1 extends In, In2 extends In, L, L1, L2, Z, Z1, Z2>(
899
+ self: Sink.Sink<R, E, In, L, Z>,
900
+ options: {
901
+ readonly onFailure: (err: E) => Sink.Sink<R1, E1, In1, L1, Z1>
902
+ readonly onSuccess: (z: Z) => Sink.Sink<R2, E2, In2, L2, Z2>
903
+ }
904
+ ): Sink.Sink<R | R1 | R2, E1 | E2, In1 & In2, L1 | L2, Z1 | Z2> => {
905
+ const newChannel: Channel.Channel<
906
+ R | R1 | R2,
907
+ never,
908
+ Chunk.Chunk<In1 & In2>,
909
+ unknown,
910
+ E1 | E2,
911
+ Chunk.Chunk<L1 | L2>,
912
+ Z1 | Z2
913
+ > = pipe(
914
+ toChannel(self),
915
+ core.collectElements,
916
+ channel.foldChannel({
917
+ onFailure: (error) => toChannel(options.onFailure(error)),
918
+ onSuccess: ([leftovers, z]) =>
919
+ core.suspend(() => {
920
+ const leftoversRef = {
921
+ ref: pipe(leftovers, Chunk.filter(Chunk.isNonEmpty)) as Chunk.Chunk<Chunk.Chunk<L1 | L2>>
922
+ }
923
+ const refReader = pipe(
924
+ core.sync(() => {
925
+ const ref = leftoversRef.ref
926
+ leftoversRef.ref = Chunk.empty()
927
+ return ref
928
+ }),
929
+ // This cast is safe because of the L1 >: L <: In1 bound. It follows that
930
+ // L <: In1 and therefore Chunk[L] can be safely cast to Chunk[In1].
931
+ core.flatMap((chunk) => channel.writeChunk(chunk as Chunk.Chunk<Chunk.Chunk<In1 & In2>>))
932
+ )
933
+ const passthrough = channel.identityChannel<never, Chunk.Chunk<In1 & In2>, unknown>()
934
+ const continuationSink = pipe(
935
+ refReader,
936
+ channel.zipRight(passthrough),
937
+ core.pipeTo(toChannel(options.onSuccess(z)))
938
+ )
939
+ return core.flatMap(
940
+ core.collectElements(continuationSink),
941
+ ([newLeftovers, z1]) =>
942
+ pipe(
943
+ core.succeed(leftoversRef.ref),
944
+ core.flatMap(channel.writeChunk),
945
+ channel.zipRight(channel.writeChunk(newLeftovers)),
946
+ channel.as(z1)
947
+ )
948
+ )
949
+ })
950
+ })
951
+ )
952
+ return new SinkImpl(newChannel)
953
+ }
954
+ )
955
+
956
+ /** @internal */
957
+ export const foldChunks = <S, In>(
958
+ s: S,
959
+ contFn: Predicate<S>,
960
+ f: (s: S, chunk: Chunk.Chunk<In>) => S
961
+ ): Sink.Sink<never, never, In, never, S> => suspend(() => new SinkImpl(foldChunksReader(s, contFn, f)))
962
+
963
+ /** @internal */
964
+ const foldChunksReader = <S, In>(
965
+ s: S,
966
+ contFn: Predicate<S>,
967
+ f: (s: S, chunk: Chunk.Chunk<In>) => S
968
+ ): Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, never, S> => {
969
+ if (!contFn(s)) {
970
+ return core.succeedNow(s)
971
+ }
972
+ return core.readWith({
973
+ onInput: (input: Chunk.Chunk<In>) => foldChunksReader(f(s, input), contFn, f),
974
+ onFailure: core.fail,
975
+ onDone: () => core.succeedNow(s)
976
+ })
977
+ }
978
+
979
+ /** @internal */
980
+ export const foldChunksEffect = <S, R, E, In>(
981
+ s: S,
982
+ contFn: Predicate<S>,
983
+ f: (s: S, chunk: Chunk.Chunk<In>) => Effect.Effect<R, E, S>
984
+ ): Sink.Sink<R, E, In, In, S> => suspend(() => new SinkImpl(foldChunksEffectReader(s, contFn, f)))
985
+
986
+ /** @internal */
987
+ const foldChunksEffectReader = <S, R, E, In>(
988
+ s: S,
989
+ contFn: Predicate<S>,
990
+ f: (s: S, chunk: Chunk.Chunk<In>) => Effect.Effect<R, E, S>
991
+ ): Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, never, S> => {
992
+ if (!contFn(s)) {
993
+ return core.succeedNow(s)
994
+ }
995
+ return core.readWith({
996
+ onInput: (input: Chunk.Chunk<In>) =>
997
+ pipe(
998
+ core.fromEffect(f(s, input)),
999
+ core.flatMap((s) => foldChunksEffectReader(s, contFn, f))
1000
+ ),
1001
+ onFailure: core.fail,
1002
+ onDone: () => core.succeedNow(s)
1003
+ })
1004
+ }
1005
+
1006
+ /** @internal */
1007
+ export const foldEffect = <S, R, E, In>(
1008
+ s: S,
1009
+ contFn: Predicate<S>,
1010
+ f: (s: S, input: In) => Effect.Effect<R, E, S>
1011
+ ): Sink.Sink<R, E, In, In, S> => suspend(() => new SinkImpl(foldEffectReader(s, contFn, f)))
1012
+
1013
+ /** @internal */
1014
+ const foldEffectReader = <S, In, R, E>(
1015
+ s: S,
1016
+ contFn: Predicate<S>,
1017
+ f: (s: S, input: In) => Effect.Effect<R, E, S>
1018
+ ): Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<In>, S> => {
1019
+ if (!contFn(s)) {
1020
+ return core.succeedNow(s)
1021
+ }
1022
+ return core.readWith({
1023
+ onInput: (input: Chunk.Chunk<In>) =>
1024
+ pipe(
1025
+ core.fromEffect(foldChunkSplitEffect(s, input, contFn, f)),
1026
+ core.flatMap(([nextS, leftovers]) =>
1027
+ pipe(
1028
+ leftovers,
1029
+ Option.match({
1030
+ onNone: () => foldEffectReader(nextS, contFn, f),
1031
+ onSome: (leftover) => pipe(core.write(leftover), channel.as(nextS))
1032
+ })
1033
+ )
1034
+ )
1035
+ ),
1036
+ onFailure: core.fail,
1037
+ onDone: () => core.succeedNow(s)
1038
+ })
1039
+ }
1040
+
1041
+ /** @internal */
1042
+ const foldChunkSplitEffect = <S, R, E, In>(
1043
+ s: S,
1044
+ chunk: Chunk.Chunk<In>,
1045
+ contFn: Predicate<S>,
1046
+ f: (s: S, input: In) => Effect.Effect<R, E, S>
1047
+ ): Effect.Effect<R, E, readonly [S, Option.Option<Chunk.Chunk<In>>]> =>
1048
+ foldChunkSplitEffectInternal(s, chunk, 0, chunk.length, contFn, f)
1049
+
1050
+ /** @internal */
1051
+ const foldChunkSplitEffectInternal = <S, R, E, In>(
1052
+ s: S,
1053
+ chunk: Chunk.Chunk<In>,
1054
+ index: number,
1055
+ length: number,
1056
+ contFn: Predicate<S>,
1057
+ f: (s: S, input: In) => Effect.Effect<R, E, S>
1058
+ ): Effect.Effect<R, E, readonly [S, Option.Option<Chunk.Chunk<In>>]> => {
1059
+ if (index === length) {
1060
+ return Effect.succeed([s, Option.none()] as const)
1061
+ }
1062
+ return pipe(
1063
+ f(s, pipe(chunk, Chunk.unsafeGet(index))),
1064
+ Effect.flatMap((s1) =>
1065
+ contFn(s1) ?
1066
+ foldChunkSplitEffectInternal(s1, chunk, index + 1, length, contFn, f) :
1067
+ Effect.succeed([s1, Option.some(pipe(chunk, Chunk.drop(index + 1)))] as const)
1068
+ )
1069
+ )
1070
+ }
1071
+
1072
+ /** @internal */
1073
+ export const foldLeft = <S, In>(s: S, f: (s: S, input: In) => S): Sink.Sink<never, never, In, never, S> =>
1074
+ ignoreLeftover(fold(s, constTrue, f))
1075
+
1076
+ /** @internal */
1077
+ export const foldLeftChunks = <S, In>(
1078
+ s: S,
1079
+ f: (s: S, chunk: Chunk.Chunk<In>) => S
1080
+ ): Sink.Sink<never, never, In, never, S> => foldChunks(s, constTrue, f)
1081
+
1082
+ /** @internal */
1083
+ export const foldLeftChunksEffect = <S, R, E, In>(
1084
+ s: S,
1085
+ f: (s: S, chunk: Chunk.Chunk<In>) => Effect.Effect<R, E, S>
1086
+ ): Sink.Sink<R, E, In, never, S> => ignoreLeftover(foldChunksEffect(s, constTrue, f))
1087
+
1088
+ /** @internal */
1089
+ export const foldLeftEffect = <S, R, E, In>(
1090
+ s: S,
1091
+ f: (s: S, input: In) => Effect.Effect<R, E, S>
1092
+ ): Sink.Sink<R, E, In, In, S> => foldEffect(s, constTrue, f)
1093
+
1094
+ /** @internal */
1095
+ export const foldUntil = <S, In>(s: S, max: number, f: (z: S, input: In) => S): Sink.Sink<never, never, In, In, S> =>
1096
+ pipe(
1097
+ fold<readonly [S, number], In>(
1098
+ [s, 0],
1099
+ (tuple) => tuple[1] < max,
1100
+ ([output, count], input) => [f(output, input), count + 1] as const
1101
+ ),
1102
+ map((tuple) => tuple[0])
1103
+ )
1104
+
1105
+ /** @internal */
1106
+ export const foldUntilEffect = <S, R, E, In>(
1107
+ s: S,
1108
+ max: number,
1109
+ f: (s: S, input: In) => Effect.Effect<R, E, S>
1110
+ ): Sink.Sink<R, E, In, In, S> =>
1111
+ pipe(
1112
+ foldEffect(
1113
+ [s, 0 as number] as const,
1114
+ (tuple) => tuple[1] < max,
1115
+ ([output, count], input: In) => pipe(f(output, input), Effect.map((s) => [s, count + 1] as const))
1116
+ ),
1117
+ map((tuple) => tuple[0])
1118
+ )
1119
+
1120
+ /** @internal */
1121
+ export const foldWeighted = <S, In>(
1122
+ options: {
1123
+ readonly initial: S
1124
+ readonly maxCost: number
1125
+ readonly cost: (s: S, input: In) => number
1126
+ readonly body: (s: S, input: In) => S
1127
+ }
1128
+ ): Sink.Sink<never, never, In, In, S> =>
1129
+ foldWeightedDecompose({
1130
+ ...options,
1131
+ decompose: Chunk.of
1132
+ })
1133
+
1134
+ /** @internal */
1135
+ export const foldWeightedDecompose = <S, In>(
1136
+ options: {
1137
+ readonly initial: S
1138
+ readonly maxCost: number
1139
+ readonly cost: (s: S, input: In) => number
1140
+ readonly decompose: (input: In) => Chunk.Chunk<In>
1141
+ readonly body: (s: S, input: In) => S
1142
+ }
1143
+ ): Sink.Sink<never, never, In, In, S> =>
1144
+ suspend(() =>
1145
+ new SinkImpl(
1146
+ foldWeightedDecomposeLoop(
1147
+ options.initial,
1148
+ 0,
1149
+ false,
1150
+ options.maxCost,
1151
+ options.cost,
1152
+ options.decompose,
1153
+ options.body
1154
+ )
1155
+ )
1156
+ )
1157
+
1158
+ /** @internal */
1159
+ const foldWeightedDecomposeLoop = <S, In>(
1160
+ s: S,
1161
+ cost: number,
1162
+ dirty: boolean,
1163
+ max: number,
1164
+ costFn: (s: S, input: In) => number,
1165
+ decompose: (input: In) => Chunk.Chunk<In>,
1166
+ f: (s: S, input: In) => S
1167
+ ): Channel.Channel<never, never, Chunk.Chunk<In>, unknown, never, Chunk.Chunk<In>, S> =>
1168
+ core.readWith({
1169
+ onInput: (input: Chunk.Chunk<In>) => {
1170
+ const [nextS, nextCost, nextDirty, leftovers] = foldWeightedDecomposeFold(
1171
+ input,
1172
+ 0,
1173
+ s,
1174
+ cost,
1175
+ dirty,
1176
+ max,
1177
+ costFn,
1178
+ decompose,
1179
+ f
1180
+ )
1181
+ if (Chunk.isNonEmpty(leftovers)) {
1182
+ return pipe(core.write(leftovers), channel.zipRight(core.succeedNow(nextS)))
1183
+ }
1184
+ if (cost > max) {
1185
+ return core.succeedNow(nextS)
1186
+ }
1187
+ return foldWeightedDecomposeLoop(nextS, nextCost, nextDirty, max, costFn, decompose, f)
1188
+ },
1189
+ onFailure: core.fail,
1190
+ onDone: () => core.succeedNow(s)
1191
+ })
1192
+
1193
+ /** @internal */
1194
+ const foldWeightedDecomposeFold = <In, S>(
1195
+ input: Chunk.Chunk<In>,
1196
+ index: number,
1197
+ s: S,
1198
+ cost: number,
1199
+ dirty: boolean,
1200
+ max: number,
1201
+ costFn: (s: S, input: In) => number,
1202
+ decompose: (input: In) => Chunk.Chunk<In>,
1203
+ f: (s: S, input: In) => S
1204
+ ): readonly [S, number, boolean, Chunk.Chunk<In>] => {
1205
+ if (index === input.length) {
1206
+ return [s, cost, dirty, Chunk.empty<In>()] as const
1207
+ }
1208
+ const elem = pipe(input, Chunk.unsafeGet(index))
1209
+ const total = cost + costFn(s, elem)
1210
+ if (total <= max) {
1211
+ return foldWeightedDecomposeFold(input, index + 1, f(s, elem), total, true, max, costFn, decompose, f)
1212
+ }
1213
+ const decomposed = decompose(elem)
1214
+ if (decomposed.length <= 1 && !dirty) {
1215
+ // If `elem` cannot be decomposed, we need to cross the `max` threshold. To
1216
+ // minimize "injury", we only allow this when we haven't added anything else
1217
+ // to the aggregate (dirty = false).
1218
+ return [f(s, elem), total, true, pipe(input, Chunk.drop(index + 1))] as const
1219
+ }
1220
+ if (decomposed.length <= 1 && dirty) {
1221
+ // If the state is dirty and `elem` cannot be decomposed, we stop folding
1222
+ // and include `elem` in the leftovers.
1223
+ return [s, cost, dirty, pipe(input, Chunk.drop(index))] as const
1224
+ }
1225
+ // `elem` got decomposed, so we will recurse with the decomposed elements pushed
1226
+ // into the chunk we're processing and see if we can aggregate further.
1227
+ const next = pipe(decomposed, Chunk.appendAll(pipe(input, Chunk.drop(index + 1))))
1228
+ return foldWeightedDecomposeFold(next, 0, s, cost, dirty, max, costFn, decompose, f)
1229
+ }
1230
+
1231
+ /** @internal */
1232
+ export const foldWeightedDecomposeEffect = <S, In, R, E, R2, E2, R3, E3>(
1233
+ options: {
1234
+ readonly initial: S
1235
+ readonly maxCost: number
1236
+ readonly cost: (s: S, input: In) => Effect.Effect<R, E, number>
1237
+ readonly decompose: (input: In) => Effect.Effect<R2, E2, Chunk.Chunk<In>>
1238
+ readonly body: (s: S, input: In) => Effect.Effect<R3, E3, S>
1239
+ }
1240
+ ): Sink.Sink<R | R2 | R3, E | E2 | E3, In, In, S> =>
1241
+ suspend(() =>
1242
+ new SinkImpl(
1243
+ foldWeightedDecomposeEffectLoop(
1244
+ options.initial,
1245
+ options.maxCost,
1246
+ options.cost,
1247
+ options.decompose,
1248
+ options.body,
1249
+ 0,
1250
+ false
1251
+ )
1252
+ )
1253
+ )
1254
+
1255
+ /** @internal */
1256
+ export const foldWeightedEffect = <S, In, R, E, R2, E2>(
1257
+ options: {
1258
+ readonly initial: S
1259
+ readonly maxCost: number
1260
+ readonly cost: (s: S, input: In) => Effect.Effect<R, E, number>
1261
+ readonly body: (s: S, input: In) => Effect.Effect<R2, E2, S>
1262
+ }
1263
+ ): Sink.Sink<R | R2, E | E2, In, In, S> =>
1264
+ foldWeightedDecomposeEffect({
1265
+ ...options,
1266
+ decompose: (input) => Effect.succeed(Chunk.of(input))
1267
+ })
1268
+
1269
+ /** @internal */
1270
+ const foldWeightedDecomposeEffectLoop = <S, In, R, E, R2, E2, R3, E3>(
1271
+ s: S,
1272
+ max: number,
1273
+ costFn: (s: S, input: In) => Effect.Effect<R, E, number>,
1274
+ decompose: (input: In) => Effect.Effect<R2, E2, Chunk.Chunk<In>>,
1275
+ f: (s: S, input: In) => Effect.Effect<R3, E3, S>,
1276
+ cost: number,
1277
+ dirty: boolean
1278
+ ): Channel.Channel<R | R2 | R3, E | E2 | E3, Chunk.Chunk<In>, unknown, E | E2 | E3, Chunk.Chunk<In>, S> =>
1279
+ core.readWith({
1280
+ onInput: (input: Chunk.Chunk<In>) =>
1281
+ pipe(
1282
+ core.fromEffect(foldWeightedDecomposeEffectFold(s, max, costFn, decompose, f, input, dirty, cost, 0)),
1283
+ core.flatMap(([nextS, nextCost, nextDirty, leftovers]) => {
1284
+ if (Chunk.isNonEmpty(leftovers)) {
1285
+ return pipe(core.write(leftovers), channel.zipRight(core.succeedNow(nextS)))
1286
+ }
1287
+ if (cost > max) {
1288
+ return core.succeedNow(nextS)
1289
+ }
1290
+ return foldWeightedDecomposeEffectLoop(nextS, max, costFn, decompose, f, nextCost, nextDirty)
1291
+ })
1292
+ ),
1293
+ onFailure: core.fail,
1294
+ onDone: () => core.succeedNow(s)
1295
+ })
1296
+
1297
+ /** @internal */
1298
+ const foldWeightedDecomposeEffectFold = <S, In, R, E, R2, E2, R3, E3>(
1299
+ s: S,
1300
+ max: number,
1301
+ costFn: (s: S, input: In) => Effect.Effect<R, E, number>,
1302
+ decompose: (input: In) => Effect.Effect<R2, E2, Chunk.Chunk<In>>,
1303
+ f: (s: S, input: In) => Effect.Effect<R3, E3, S>,
1304
+ input: Chunk.Chunk<In>,
1305
+ dirty: boolean,
1306
+ cost: number,
1307
+ index: number
1308
+ ): Effect.Effect<R | R2 | R3, E | E2 | E3, readonly [S, number, boolean, Chunk.Chunk<In>]> => {
1309
+ if (index === input.length) {
1310
+ return Effect.succeed([s, cost, dirty, Chunk.empty<In>()] as const)
1311
+ }
1312
+ const elem = pipe(input, Chunk.unsafeGet(index))
1313
+ return pipe(
1314
+ costFn(s, elem),
1315
+ Effect.map((newCost) => cost + newCost),
1316
+ Effect.flatMap((total) => {
1317
+ if (total <= max) {
1318
+ return pipe(
1319
+ f(s, elem),
1320
+ Effect.flatMap((s) =>
1321
+ foldWeightedDecomposeEffectFold(s, max, costFn, decompose, f, input, true, total, index + 1)
1322
+ )
1323
+ )
1324
+ }
1325
+ return pipe(
1326
+ decompose(elem),
1327
+ Effect.flatMap((decomposed) => {
1328
+ if (decomposed.length <= 1 && !dirty) {
1329
+ // If `elem` cannot be decomposed, we need to cross the `max` threshold. To
1330
+ // minimize "injury", we only allow this when we haven't added anything else
1331
+ // to the aggregate (dirty = false).
1332
+ return pipe(
1333
+ f(s, elem),
1334
+ Effect.map((s) => [s, total, true, pipe(input, Chunk.drop(index + 1))] as const)
1335
+ )
1336
+ }
1337
+ if (decomposed.length <= 1 && dirty) {
1338
+ // If the state is dirty and `elem` cannot be decomposed, we stop folding
1339
+ // and include `elem` in th leftovers.
1340
+ return Effect.succeed([s, cost, dirty, pipe(input, Chunk.drop(index))] as const)
1341
+ }
1342
+ // `elem` got decomposed, so we will recurse with the decomposed elements pushed
1343
+ // into the chunk we're processing and see if we can aggregate further.
1344
+ const next = pipe(decomposed, Chunk.appendAll(pipe(input, Chunk.drop(index + 1))))
1345
+ return foldWeightedDecomposeEffectFold(s, max, costFn, decompose, f, next, dirty, cost, 0)
1346
+ })
1347
+ )
1348
+ })
1349
+ )
1350
+ }
1351
+
1352
+ /** @internal */
1353
+ export const flatMap = dual<
1354
+ <R1, E1, In, In1 extends In, L, L1, Z, Z1>(
1355
+ f: (z: Z) => Sink.Sink<R1, E1, In1, L1, Z1>
1356
+ ) => <R, E>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R1 | R, E1 | E, In & In1, L | L1, Z1>,
1357
+ <R, E, R1, E1, In, In1 extends In, L, L1, Z, Z1>(
1358
+ self: Sink.Sink<R, E, In, L, Z>,
1359
+ f: (z: Z) => Sink.Sink<R1, E1, In1, L1, Z1>
1360
+ ) => Sink.Sink<R1 | R, E1 | E, In & In1, L | L1, Z1>
1361
+ >(
1362
+ 2,
1363
+ <R, E, R1, E1, In, In1 extends In, L, L1, Z, Z1>(
1364
+ self: Sink.Sink<R, E, In, L, Z>,
1365
+ f: (z: Z) => Sink.Sink<R1, E1, In1, L1, Z1>
1366
+ ): Sink.Sink<R | R1, E | E1, In & In1, L | L1, Z1> => foldSink(self, { onFailure: fail, onSuccess: f })
1367
+ )
1368
+
1369
+ /** @internal */
1370
+ export const forEach = <In, R, E, _>(f: (input: In) => Effect.Effect<R, E, _>): Sink.Sink<R, E, In, never, void> => {
1371
+ const process: Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, never, void> = core.readWithCause({
1372
+ onInput: (input: Chunk.Chunk<In>) =>
1373
+ pipe(core.fromEffect(Effect.forEach(input, (v) => f(v), { discard: true })), core.flatMap(() => process)),
1374
+ onFailure: core.failCause,
1375
+ onDone: () => core.unit
1376
+ })
1377
+ return new SinkImpl(process)
1378
+ }
1379
+
1380
+ /** @internal */
1381
+ export const forEachChunk = <In, R, E, _>(
1382
+ f: (input: Chunk.Chunk<In>) => Effect.Effect<R, E, _>
1383
+ ): Sink.Sink<R, E, In, never, void> => {
1384
+ const process: Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, never, void> = core.readWithCause({
1385
+ onInput: (input: Chunk.Chunk<In>) => pipe(core.fromEffect(f(input)), core.flatMap(() => process)),
1386
+ onFailure: core.failCause,
1387
+ onDone: () => core.unit
1388
+ })
1389
+ return new SinkImpl(process)
1390
+ }
1391
+
1392
+ /** @internal */
1393
+ export const forEachWhile = <In, R, E>(
1394
+ f: (input: In) => Effect.Effect<R, E, boolean>
1395
+ ): Sink.Sink<R, E, In, In, void> => {
1396
+ const process: Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<In>, void> = core.readWithCause({
1397
+ onInput: (input: Chunk.Chunk<In>) => forEachWhileReader(f, input, 0, input.length, process),
1398
+ onFailure: core.failCause,
1399
+ onDone: () => core.unit
1400
+ })
1401
+ return new SinkImpl(process)
1402
+ }
1403
+
1404
+ /** @internal */
1405
+ const forEachWhileReader = <In, R, E>(
1406
+ f: (input: In) => Effect.Effect<R, E, boolean>,
1407
+ input: Chunk.Chunk<In>,
1408
+ index: number,
1409
+ length: number,
1410
+ cont: Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<In>, void>
1411
+ ): Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<In>, void> => {
1412
+ if (index === length) {
1413
+ return cont
1414
+ }
1415
+ return pipe(
1416
+ core.fromEffect(f(pipe(input, Chunk.unsafeGet(index)))),
1417
+ core.flatMap((bool) =>
1418
+ bool ?
1419
+ forEachWhileReader(f, input, index + 1, length, cont) :
1420
+ core.write(pipe(input, Chunk.drop(index)))
1421
+ ),
1422
+ channel.catchAll((error) => pipe(core.write(pipe(input, Chunk.drop(index))), channel.zipRight(core.fail(error))))
1423
+ )
1424
+ }
1425
+
1426
+ /** @internal */
1427
+ export const forEachChunkWhile = <In, R, E>(
1428
+ f: (input: Chunk.Chunk<In>) => Effect.Effect<R, E, boolean>
1429
+ ): Sink.Sink<R, E, In, In, void> => {
1430
+ const reader: Channel.Channel<R, E, Chunk.Chunk<In>, unknown, E, never, void> = core.readWith({
1431
+ onInput: (input: Chunk.Chunk<In>) =>
1432
+ pipe(
1433
+ core.fromEffect(f(input)),
1434
+ core.flatMap((cont) => cont ? reader : core.unit)
1435
+ ),
1436
+ onFailure: core.fail,
1437
+ onDone: () => core.unit
1438
+ })
1439
+ return new SinkImpl(reader)
1440
+ }
1441
+
1442
+ /** @internal */
1443
+ export const fromChannel = <R, E, In, L, Z>(
1444
+ channel: Channel.Channel<R, never, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<L>, Z>
1445
+ ): Sink.Sink<R, E, In, L, Z> => new SinkImpl(channel)
1446
+
1447
+ /** @internal */
1448
+ export const fromEffect = <R, E, Z>(effect: Effect.Effect<R, E, Z>): Sink.Sink<R, E, unknown, never, Z> =>
1449
+ new SinkImpl(core.fromEffect(effect))
1450
+
1451
+ /** @internal */
1452
+ export const fromPubSub = <In>(
1453
+ pubsub: PubSub.PubSub<In>,
1454
+ options?: { readonly shutdown?: boolean }
1455
+ ): Sink.Sink<never, never, In, never, void> => fromQueue(pubsub, options)
1456
+
1457
+ /** @internal */
1458
+ export const fromPush = <R, E, In, L, Z>(
1459
+ push: Effect.Effect<
1460
+ R,
1461
+ never,
1462
+ (_: Option.Option<Chunk.Chunk<In>>) => Effect.Effect<R, readonly [Either.Either<E, Z>, Chunk.Chunk<L>], void>
1463
+ >
1464
+ ): Sink.Sink<Exclude<R, Scope.Scope>, E, In, L, Z> =>
1465
+ new SinkImpl(channel.unwrapScoped(pipe(push, Effect.map(fromPushPull))))
1466
+
1467
+ const fromPushPull = <R, E, In, L, Z>(
1468
+ push: (
1469
+ option: Option.Option<Chunk.Chunk<In>>
1470
+ ) => Effect.Effect<R, readonly [Either.Either<E, Z>, Chunk.Chunk<L>], void>
1471
+ ): Channel.Channel<R, never, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<L>, Z> =>
1472
+ core.readWith({
1473
+ onInput: (input: Chunk.Chunk<In>) =>
1474
+ channel.foldChannel(core.fromEffect(push(Option.some(input))), {
1475
+ onFailure: ([either, leftovers]) =>
1476
+ Either.match(either, {
1477
+ onLeft: (error) => pipe(core.write(leftovers), channel.zipRight(core.fail(error))),
1478
+ onRight: (z) => pipe(core.write(leftovers), channel.zipRight(core.succeedNow(z)))
1479
+ }),
1480
+ onSuccess: () => fromPushPull(push)
1481
+ }),
1482
+ onFailure: core.fail,
1483
+ onDone: () =>
1484
+ channel.foldChannel(core.fromEffect(push(Option.none())), {
1485
+ onFailure: ([either, leftovers]) =>
1486
+ Either.match(either, {
1487
+ onLeft: (error) => pipe(core.write(leftovers), channel.zipRight(core.fail(error))),
1488
+ onRight: (z) => pipe(core.write(leftovers), channel.zipRight(core.succeedNow(z)))
1489
+ }),
1490
+ onSuccess: () =>
1491
+ core.fromEffect(
1492
+ Effect.dieMessage(
1493
+ "BUG: Sink.fromPush - please report an issue at https://github.com/Effect-TS/stream/issues"
1494
+ )
1495
+ )
1496
+ })
1497
+ })
1498
+
1499
+ /** @internal */
1500
+ export const fromQueue = <In>(
1501
+ queue: Queue.Enqueue<In>,
1502
+ options?: { readonly shutdown?: boolean }
1503
+ ): Sink.Sink<never, never, In, never, void> =>
1504
+ options?.shutdown ?
1505
+ unwrapScoped(
1506
+ Effect.map(
1507
+ Effect.acquireRelease(Effect.succeed(queue), Queue.shutdown),
1508
+ fromQueue
1509
+ )
1510
+ ) :
1511
+ forEachChunk((input: Chunk.Chunk<In>) => pipe(Queue.offerAll(queue, input)))
1512
+
1513
+ /** @internal */
1514
+ export const head = <In>(): Sink.Sink<never, never, In, In, Option.Option<In>> =>
1515
+ fold(
1516
+ Option.none() as Option.Option<In>,
1517
+ Option.isNone,
1518
+ (option, input) =>
1519
+ Option.match(option, {
1520
+ onNone: () => Option.some(input),
1521
+ onSome: () => option
1522
+ })
1523
+ )
1524
+
1525
+ /** @internal */
1526
+ export const ignoreLeftover = <R, E, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>): Sink.Sink<R, E, In, never, Z> =>
1527
+ new SinkImpl(channel.drain(toChannel(self)))
1528
+
1529
+ /** @internal */
1530
+ export const last = <In>(): Sink.Sink<never, never, In, In, Option.Option<In>> =>
1531
+ foldLeftChunks(Option.none<In>(), (s, input) => Option.orElse(Chunk.last(input), () => s))
1532
+
1533
+ /** @internal */
1534
+ export const leftover = <L>(chunk: Chunk.Chunk<L>): Sink.Sink<never, never, unknown, L, void> =>
1535
+ new SinkImpl(core.suspend(() => core.write(chunk)))
1536
+
1537
+ /** @internal */
1538
+ export const map = dual<
1539
+ <Z, Z2>(f: (z: Z) => Z2) => <R, E, In, L>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In, L, Z2>,
1540
+ <R, E, In, L, Z, Z2>(self: Sink.Sink<R, E, In, L, Z>, f: (z: Z) => Z2) => Sink.Sink<R, E, In, L, Z2>
1541
+ >(2, <R, E, In, L, Z, Z2>(self: Sink.Sink<R, E, In, L, Z>, f: (z: Z) => Z2): Sink.Sink<R, E, In, L, Z2> => {
1542
+ return new SinkImpl(pipe(toChannel(self), channel.map(f)))
1543
+ })
1544
+
1545
+ /** @internal */
1546
+ export const mapEffect = dual<
1547
+ <Z, R2, E2, Z2>(
1548
+ f: (z: Z) => Effect.Effect<R2, E2, Z2>
1549
+ ) => <R, E, In, L>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In, L, Z2>,
1550
+ <R, E, In, L, Z, R2, E2, Z2>(
1551
+ self: Sink.Sink<R, E, In, L, Z>,
1552
+ f: (z: Z) => Effect.Effect<R2, E2, Z2>
1553
+ ) => Sink.Sink<R2 | R, E2 | E, In, L, Z2>
1554
+ >(
1555
+ 2,
1556
+ <R, E, In, L, Z, R2, E2, Z2>(
1557
+ self: Sink.Sink<R, E, In, L, Z>,
1558
+ f: (z: Z) => Effect.Effect<R2, E2, Z2>
1559
+ ): Sink.Sink<R | R2, E | E2, In, L, Z2> => new SinkImpl(pipe(toChannel(self), channel.mapEffect(f)))
1560
+ )
1561
+
1562
+ /** @internal */
1563
+ export const mapError = dual<
1564
+ <E, E2>(f: (error: E) => E2) => <R, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E2, In, L, Z>,
1565
+ <R, In, L, Z, E, E2>(self: Sink.Sink<R, E, In, L, Z>, f: (error: E) => E2) => Sink.Sink<R, E2, In, L, Z>
1566
+ >(
1567
+ 2,
1568
+ <R, In, L, Z, E, E2>(self: Sink.Sink<R, E, In, L, Z>, f: (error: E) => E2): Sink.Sink<R, E2, In, L, Z> =>
1569
+ new SinkImpl(pipe(toChannel(self), channel.mapError(f)))
1570
+ )
1571
+
1572
+ /** @internal */
1573
+ export const mapLeftover = dual<
1574
+ <L, L2>(f: (leftover: L) => L2) => <R, E, In, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In, L2, Z>,
1575
+ <R, E, In, Z, L, L2>(self: Sink.Sink<R, E, In, L, Z>, f: (leftover: L) => L2) => Sink.Sink<R, E, In, L2, Z>
1576
+ >(
1577
+ 2,
1578
+ <R, E, In, Z, L, L2>(self: Sink.Sink<R, E, In, L, Z>, f: (leftover: L) => L2): Sink.Sink<R, E, In, L2, Z> =>
1579
+ new SinkImpl(pipe(toChannel(self), channel.mapOut(Chunk.map(f))))
1580
+ )
1581
+
1582
+ /** @internal */
1583
+ export const never: Sink.Sink<never, never, unknown, never, never> = fromEffect(Effect.never)
1584
+
1585
+ /** @internal */
1586
+ export const orElse = dual<
1587
+ <R2, E2, In2, L2, Z2>(
1588
+ that: LazyArg<Sink.Sink<R2, E2, In2, L2, Z2>>
1589
+ ) => <R, E, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In & In2, L2 | L, Z2 | Z>,
1590
+ <R, E, In, L, Z, R2, E2, In2, L2, Z2>(
1591
+ self: Sink.Sink<R, E, In, L, Z>,
1592
+ that: LazyArg<Sink.Sink<R2, E2, In2, L2, Z2>>
1593
+ ) => Sink.Sink<R2 | R, E2 | E, In & In2, L2 | L, Z2 | Z>
1594
+ >(
1595
+ 2,
1596
+ <R, E, In, L, Z, R2, E2, In2, L2, Z2>(
1597
+ self: Sink.Sink<R, E, In, L, Z>,
1598
+ that: LazyArg<Sink.Sink<R2, E2, In2, L2, Z2>>
1599
+ ): Sink.Sink<R | R2, E | E2, In & In2, L | L2, Z | Z2> =>
1600
+ new SinkImpl<R | R2, E | E2, In & In2, L | L2, Z | Z2>(
1601
+ pipe(toChannel(self), channel.orElse(() => toChannel(that())))
1602
+ )
1603
+ )
1604
+
1605
+ /** @internal */
1606
+ export const provideContext = dual<
1607
+ <R>(context: Context.Context<R>) => <E, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<never, E, In, L, Z>,
1608
+ <E, In, L, Z, R>(self: Sink.Sink<R, E, In, L, Z>, context: Context.Context<R>) => Sink.Sink<never, E, In, L, Z>
1609
+ >(
1610
+ 2,
1611
+ <E, In, L, Z, R>(self: Sink.Sink<R, E, In, L, Z>, context: Context.Context<R>): Sink.Sink<never, E, In, L, Z> =>
1612
+ new SinkImpl(pipe(toChannel(self), core.provideContext(context)))
1613
+ )
1614
+
1615
+ /** @internal */
1616
+ export const race = dual<
1617
+ <R1, E1, In1, L1, Z1>(
1618
+ that: Sink.Sink<R1, E1, In1, L1, Z1>
1619
+ ) => <R, E, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R1 | R, E1 | E, In & In1, L1 | L, Z1 | Z>,
1620
+ <R, E, In, L, Z, R1, E1, In1, L1, Z1>(
1621
+ self: Sink.Sink<R, E, In, L, Z>,
1622
+ that: Sink.Sink<R1, E1, In1, L1, Z1>
1623
+ ) => Sink.Sink<R1 | R, E1 | E, In & In1, L1 | L, Z1 | Z>
1624
+ >(
1625
+ 2,
1626
+ <R, E, In, L, Z, R1, E1, In1, L1, Z1>(
1627
+ self: Sink.Sink<R, E, In, L, Z>,
1628
+ that: Sink.Sink<R1, E1, In1, L1, Z1>
1629
+ ): Sink.Sink<R | R1, E | E1, In & In1, L | L1, Z | Z1> => pipe(self, raceBoth(that), map(Either.merge))
1630
+ )
1631
+
1632
+ /** @internal */
1633
+ export const raceBoth = dual<
1634
+ <R1, E1, In1, L1, Z1>(
1635
+ that: Sink.Sink<R1, E1, In1, L1, Z1>,
1636
+ options?: { readonly capacity?: number }
1637
+ ) => <R, E, In, L, Z>(
1638
+ self: Sink.Sink<R, E, In, L, Z>
1639
+ ) => Sink.Sink<R1 | R, E1 | E, In & In1, L1 | L, Either.Either<Z, Z1>>,
1640
+ <R, E, In, L, Z, R1, E1, In1, L1, Z1>(
1641
+ self: Sink.Sink<R, E, In, L, Z>,
1642
+ that: Sink.Sink<R1, E1, In1, L1, Z1>,
1643
+ options?: { readonly capacity?: number }
1644
+ ) => Sink.Sink<R1 | R, E1 | E, In & In1, L1 | L, Either.Either<Z, Z1>>
1645
+ >(
1646
+ (args) => isSink(args[1]),
1647
+ <R, E, In, L, Z, R1, E1, In1, L1, Z1>(
1648
+ self: Sink.Sink<R, E, In, L, Z>,
1649
+ that: Sink.Sink<R1, E1, In1, L1, Z1>,
1650
+ options?: { readonly capacity?: number }
1651
+ ): Sink.Sink<R | R1, E | E1, In & In1, L | L1, Either.Either<Z, Z1>> =>
1652
+ raceWith(self, {
1653
+ other: that,
1654
+ onSelfDone: (selfDone) => mergeDecision.Done(Effect.map(selfDone, Either.left)),
1655
+ onOtherDone: (thatDone) => mergeDecision.Done(Effect.map(thatDone, Either.right)),
1656
+ capacity: options?.capacity ?? 16
1657
+ })
1658
+ )
1659
+
1660
+ /** @internal */
1661
+ export const raceWith = dual<
1662
+ <R2, E2, In2, L2, Z2, E, Z, Z3, Z4>(
1663
+ options: {
1664
+ readonly other: Sink.Sink<R2, E2, In2, L2, Z2>
1665
+ readonly onSelfDone: (exit: Exit.Exit<E, Z>) => MergeDecision.MergeDecision<R2, E2, Z2, E2 | E, Z3>
1666
+ readonly onOtherDone: (exit: Exit.Exit<E2, Z2>) => MergeDecision.MergeDecision<R2, E, Z, E2 | E, Z4>
1667
+ readonly capacity?: number
1668
+ }
1669
+ ) => <R, In, L>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In & In2, L2 | L, Z3 | Z4>,
1670
+ <R, In, L, R2, E2, In2, L2, Z2, E, Z, Z3, Z4>(
1671
+ self: Sink.Sink<R, E, In, L, Z>,
1672
+ options: {
1673
+ readonly other: Sink.Sink<R2, E2, In2, L2, Z2>
1674
+ readonly onSelfDone: (exit: Exit.Exit<E, Z>) => MergeDecision.MergeDecision<R2, E2, Z2, E2 | E, Z3>
1675
+ readonly onOtherDone: (exit: Exit.Exit<E2, Z2>) => MergeDecision.MergeDecision<R2, E, Z, E2 | E, Z4>
1676
+ readonly capacity?: number
1677
+ }
1678
+ ) => Sink.Sink<R2 | R, E2 | E, In & In2, L2 | L, Z3 | Z4>
1679
+ >(
1680
+ 2,
1681
+ <R, In, L, R2, E2, In2, L2, Z2, E, Z, Z3, Z4>(
1682
+ self: Sink.Sink<R, E, In, L, Z>,
1683
+ options: {
1684
+ readonly other: Sink.Sink<R2, E2, In2, L2, Z2>
1685
+ readonly onSelfDone: (exit: Exit.Exit<E, Z>) => MergeDecision.MergeDecision<R2, E2, Z2, E2 | E, Z3>
1686
+ readonly onOtherDone: (exit: Exit.Exit<E2, Z2>) => MergeDecision.MergeDecision<R2, E, Z, E2 | E, Z4>
1687
+ readonly capacity?: number
1688
+ }
1689
+ ): Sink.Sink<R | R2, E | E2, In & In2, L | L2, Z3 | Z4> => {
1690
+ const scoped = Effect.gen(function*($) {
1691
+ const pubsub = yield* $(
1692
+ PubSub.bounded<Either.Either<Exit.Exit<never, unknown>, Chunk.Chunk<In & In2>>>(options?.capacity ?? 16)
1693
+ )
1694
+ const channel1 = yield* $(channel.fromPubSubScoped(pubsub))
1695
+ const channel2 = yield* $(channel.fromPubSubScoped(pubsub))
1696
+ const reader = channel.toPubSub(pubsub)
1697
+ const writer = pipe(
1698
+ channel1,
1699
+ core.pipeTo(toChannel(self)),
1700
+ channel.mergeWith({
1701
+ other: pipe(channel2, core.pipeTo(toChannel(options.other))),
1702
+ onSelfDone: options.onSelfDone,
1703
+ onOtherDone: options.onOtherDone
1704
+ })
1705
+ )
1706
+ const racedChannel: Channel.Channel<
1707
+ R | R2,
1708
+ never,
1709
+ Chunk.Chunk<In & In2>,
1710
+ unknown,
1711
+ E | E2,
1712
+ Chunk.Chunk<L | L2>,
1713
+ Z3 | Z4
1714
+ > = channel.mergeWith(reader, {
1715
+ other: writer,
1716
+ onSelfDone: (_) => mergeDecision.Await((exit) => Effect.suspend(() => exit)),
1717
+ onOtherDone: (done) => mergeDecision.Done(Effect.suspend(() => done))
1718
+ })
1719
+ return new SinkImpl(racedChannel)
1720
+ })
1721
+ return unwrapScoped(scoped)
1722
+ }
1723
+ )
1724
+
1725
+ /** @internal */
1726
+ export const refineOrDie = dual<
1727
+ <E, E2>(
1728
+ pf: (error: E) => Option.Option<E2>
1729
+ ) => <R, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E2, In, L, Z>,
1730
+ <R, In, L, Z, E, E2>(
1731
+ self: Sink.Sink<R, E, In, L, Z>,
1732
+ pf: (error: E) => Option.Option<E2>
1733
+ ) => Sink.Sink<R, E2, In, L, Z>
1734
+ >(
1735
+ 2,
1736
+ <R, In, L, Z, E, E2>(
1737
+ self: Sink.Sink<R, E, In, L, Z>,
1738
+ pf: (error: E) => Option.Option<E2>
1739
+ ): Sink.Sink<R, E2, In, L, Z> => pipe(self, refineOrDieWith(pf, identity))
1740
+ )
1741
+
1742
+ /** @internal */
1743
+ export const refineOrDieWith = dual<
1744
+ <E, E2>(
1745
+ pf: (error: E) => Option.Option<E2>,
1746
+ f: (error: E) => unknown
1747
+ ) => <R, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E2, In, L, Z>,
1748
+ <R, In, L, Z, E, E2>(
1749
+ self: Sink.Sink<R, E, In, L, Z>,
1750
+ pf: (error: E) => Option.Option<E2>,
1751
+ f: (error: E) => unknown
1752
+ ) => Sink.Sink<R, E2, In, L, Z>
1753
+ >(
1754
+ 3,
1755
+ <R, In, L, Z, E, E2>(
1756
+ self: Sink.Sink<R, E, In, L, Z>,
1757
+ pf: (error: E) => Option.Option<E2>,
1758
+ f: (error: E) => unknown
1759
+ ): Sink.Sink<R, E2, In, L, Z> => {
1760
+ const newChannel = pipe(
1761
+ self,
1762
+ toChannel,
1763
+ channel.catchAll((error) =>
1764
+ Option.match(pf(error), {
1765
+ onNone: () => core.failCauseSync(() => Cause.die(f(error))),
1766
+ onSome: core.fail
1767
+ })
1768
+ )
1769
+ )
1770
+ return new SinkImpl(newChannel)
1771
+ }
1772
+ )
1773
+
1774
+ /** @internal */
1775
+ export const service = <T extends Context.Tag<any, any>>(
1776
+ tag: T
1777
+ ): Sink.Sink<Context.Tag.Identifier<T>, never, unknown, never, Context.Tag.Service<T>> => serviceWith(tag, identity)
1778
+
1779
+ /** @internal */
1780
+ export const serviceWith = <T extends Context.Tag<any, any>, Z>(
1781
+ tag: T,
1782
+ f: (service: Context.Tag.Service<T>) => Z
1783
+ ): Sink.Sink<Context.Tag.Identifier<T>, never, unknown, never, Z> => fromEffect(Effect.map(tag, f))
1784
+
1785
+ /** @internal */
1786
+ export const serviceWithEffect = <T extends Context.Tag<any, any>, R, E, Z>(
1787
+ tag: T,
1788
+ f: (service: Context.Tag.Service<T>) => Effect.Effect<R, E, Z>
1789
+ ): Sink.Sink<R | Context.Tag.Identifier<T>, E, unknown, never, Z> => fromEffect(Effect.flatMap(tag, f))
1790
+
1791
+ /** @internal */
1792
+ export const serviceWithSink = <T extends Context.Tag<any, any>, R, E, In, L, Z>(
1793
+ tag: T,
1794
+ f: (service: Context.Tag.Service<T>) => Sink.Sink<R, E, In, L, Z>
1795
+ ): Sink.Sink<R | Context.Tag.Identifier<T>, E, In, L, Z> =>
1796
+ new SinkImpl(pipe(Effect.map(tag, (service) => toChannel(f(service))), channel.unwrap))
1797
+
1798
+ /** @internal */
1799
+ export const some = <In>(predicate: Predicate<In>): Sink.Sink<never, never, In, In, boolean> =>
1800
+ fold(false, (bool) => !bool, (acc, input) => acc || predicate(input))
1801
+
1802
+ /** @internal */
1803
+ export const splitWhere = dual<
1804
+ <In>(f: Predicate<In>) => <R, E, L extends In, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R, E, In, In, Z>,
1805
+ <R, E, L extends In, Z, In>(self: Sink.Sink<R, E, In, L, Z>, f: Predicate<In>) => Sink.Sink<R, E, In, In, Z>
1806
+ >(2, <R, E, L extends In, Z, In>(self: Sink.Sink<R, E, In, L, Z>, f: Predicate<In>): Sink.Sink<R, E, In, In, Z> => {
1807
+ const newChannel = pipe(
1808
+ core.fromEffect(Ref.make(Chunk.empty<In>())),
1809
+ core.flatMap((ref) =>
1810
+ pipe(
1811
+ splitWhereSplitter<E, In>(false, ref, f),
1812
+ channel.pipeToOrFail(toChannel(self)),
1813
+ core.collectElements,
1814
+ core.flatMap(([leftovers, z]) =>
1815
+ pipe(
1816
+ core.fromEffect(Ref.get(ref)),
1817
+ core.flatMap((leftover) =>
1818
+ pipe(
1819
+ core.write<Chunk.Chunk<In>>(pipe(leftover, Chunk.appendAll(Chunk.flatten(leftovers)))),
1820
+ channel.zipRight(core.succeed(z))
1821
+ )
1822
+ )
1823
+ )
1824
+ )
1825
+ )
1826
+ )
1827
+ )
1828
+ return new SinkImpl(newChannel)
1829
+ })
1830
+
1831
+ /** @internal */
1832
+ const splitWhereSplitter = <E, A>(
1833
+ written: boolean,
1834
+ leftovers: Ref.Ref<Chunk.Chunk<A>>,
1835
+ f: Predicate<A>
1836
+ ): Channel.Channel<never, never, Chunk.Chunk<A>, unknown, E, Chunk.Chunk<A>, unknown> =>
1837
+ core.readWithCause({
1838
+ onInput: (input) => {
1839
+ if (Chunk.isEmpty(input)) {
1840
+ return splitWhereSplitter<E, A>(written, leftovers, f)
1841
+ }
1842
+ if (written) {
1843
+ const index = indexWhere(input, f)
1844
+ if (index === -1) {
1845
+ return channel.zipRight(
1846
+ core.write(input),
1847
+ splitWhereSplitter<E, A>(true, leftovers, f)
1848
+ )
1849
+ }
1850
+ const [left, right] = Chunk.splitAt(input, index)
1851
+ return channel.zipRight(
1852
+ core.write(left),
1853
+ core.fromEffect(Ref.set(leftovers, right))
1854
+ )
1855
+ }
1856
+ const index = indexWhere(input, f, 1)
1857
+ if (index === -1) {
1858
+ return channel.zipRight(
1859
+ core.write(input),
1860
+ splitWhereSplitter<E, A>(true, leftovers, f)
1861
+ )
1862
+ }
1863
+ const [left, right] = pipe(input, Chunk.splitAt(Math.max(index, 1)))
1864
+ return channel.zipRight(core.write(left), core.fromEffect(Ref.set(leftovers, right)))
1865
+ },
1866
+ onFailure: core.failCause,
1867
+ onDone: core.succeed
1868
+ })
1869
+
1870
+ /** @internal */
1871
+ const indexWhere = <A>(self: Chunk.Chunk<A>, predicate: Predicate<A>, from = 0): number => {
1872
+ const iterator = self[Symbol.iterator]()
1873
+ let index = 0
1874
+ let result = -1
1875
+ let next: IteratorResult<A, any>
1876
+ while (result < 0 && (next = iterator.next()) && !next.done) {
1877
+ const a = next.value
1878
+ if (index >= from && predicate(a)) {
1879
+ result = index
1880
+ }
1881
+ index = index + 1
1882
+ }
1883
+ return result
1884
+ }
1885
+
1886
+ /** @internal */
1887
+ export const succeed = <Z>(z: Z): Sink.Sink<never, never, unknown, never, Z> => new SinkImpl(core.succeed(z))
1888
+
1889
+ /** @internal */
1890
+ export const sum: Sink.Sink<never, never, number, never, number> = foldLeftChunks(
1891
+ 0,
1892
+ (acc, chunk) => acc + Chunk.reduce(chunk, 0, (s, a) => s + a)
1893
+ )
1894
+
1895
+ /** @internal */
1896
+ export const summarized = dual<
1897
+ <R2, E2, Z2, Z3>(
1898
+ summary: Effect.Effect<R2, E2, Z2>,
1899
+ f: (start: Z2, end: Z2) => Z3
1900
+ ) => <R, E, In, L, Z>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In, L, readonly [Z, Z3]>,
1901
+ <R, E, In, L, Z, R2, E2, Z2, Z3>(
1902
+ self: Sink.Sink<R, E, In, L, Z>,
1903
+ summary: Effect.Effect<R2, E2, Z2>,
1904
+ f: (start: Z2, end: Z2) => Z3
1905
+ ) => Sink.Sink<R2 | R, E2 | E, In, L, readonly [Z, Z3]>
1906
+ >(
1907
+ 3,
1908
+ <R, E, In, L, Z, R2, E2, Z2, Z3>(
1909
+ self: Sink.Sink<R, E, In, L, Z>,
1910
+ summary: Effect.Effect<R2, E2, Z2>,
1911
+ f: (start: Z2, end: Z2) => Z3
1912
+ ): Sink.Sink<R | R2, E | E2, In, L, readonly [Z, Z3]> => {
1913
+ const newChannel = pipe(
1914
+ core.fromEffect(summary),
1915
+ core.flatMap((start) =>
1916
+ pipe(
1917
+ self,
1918
+ toChannel,
1919
+ core.flatMap((done) =>
1920
+ pipe(
1921
+ core.fromEffect(summary),
1922
+ channel.map((end) => [done, f(start, end)] as const)
1923
+ )
1924
+ )
1925
+ )
1926
+ )
1927
+ )
1928
+ return new SinkImpl(newChannel)
1929
+ }
1930
+ )
1931
+
1932
+ /** @internal */
1933
+ export const sync = <Z>(evaluate: LazyArg<Z>): Sink.Sink<never, never, unknown, never, Z> =>
1934
+ new SinkImpl(core.sync(evaluate))
1935
+
1936
+ /** @internal */
1937
+ export const take = <In>(n: number): Sink.Sink<never, never, In, In, Chunk.Chunk<In>> =>
1938
+ pipe(
1939
+ foldChunks<Chunk.Chunk<In>, In>(
1940
+ Chunk.empty(),
1941
+ (chunk) => chunk.length < n,
1942
+ (acc, chunk) => pipe(acc, Chunk.appendAll(chunk))
1943
+ ),
1944
+ flatMap((acc) => {
1945
+ const [taken, leftover] = pipe(acc, Chunk.splitAt(n))
1946
+ return new SinkImpl(pipe(core.write(leftover), channel.zipRight(core.succeedNow(taken))))
1947
+ })
1948
+ )
1949
+
1950
+ /** @internal */
1951
+ export const toChannel = <R, E, In, L, Z>(
1952
+ self: Sink.Sink<R, E, In, L, Z>
1953
+ ): Channel.Channel<R, never, Chunk.Chunk<In>, unknown, E, Chunk.Chunk<L>, Z> =>
1954
+ Effect.isEffect(self) ?
1955
+ toChannel(fromEffect(self as Effect.Effect<R, E, Z>)) :
1956
+ (self as SinkImpl<R, E, In, L, Z>).channel
1957
+
1958
+ /** @internal */
1959
+ export const unwrap = <R, E, R2, E2, In, L, Z>(
1960
+ effect: Effect.Effect<R, E, Sink.Sink<R2, E2, In, L, Z>>
1961
+ ): Sink.Sink<R | R2, E | E2, In, L, Z> =>
1962
+ new SinkImpl(
1963
+ channel.unwrap(pipe(effect, Effect.map((sink) => toChannel(sink))))
1964
+ )
1965
+
1966
+ /** @internal */
1967
+ export const unwrapScoped = <R, E, In, L, Z>(
1968
+ effect: Effect.Effect<R, E, Sink.Sink<R, E, In, L, Z>>
1969
+ ): Sink.Sink<Exclude<R, Scope.Scope>, E, In, L, Z> => {
1970
+ return new SinkImpl(channel.unwrapScoped(pipe(effect, Effect.map((sink) => toChannel(sink)))))
1971
+ }
1972
+
1973
+ /** @internal */
1974
+ export const withDuration = <R, E, In, L, Z>(
1975
+ self: Sink.Sink<R, E, In, L, Z>
1976
+ ): Sink.Sink<R, E, In, L, readonly [Z, Duration.Duration]> =>
1977
+ pipe(self, summarized(Clock.currentTimeMillis, (start, end) => Duration.millis(end - start)))
1978
+
1979
+ /** @internal */
1980
+ export const zip = dual<
1981
+ <R2, E2, In, In2 extends In, L, L2, Z, Z2>(
1982
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
1983
+ options?: { readonly concurrent?: boolean }
1984
+ ) => <R, E>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In & In2, L | L2, readonly [Z, Z2]>,
1985
+ <R, E, R2, E2, In, In2 extends In, L, L2, Z, Z2>(
1986
+ self: Sink.Sink<R, E, In, L, Z>,
1987
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
1988
+ options?: { readonly concurrent?: boolean }
1989
+ ) => Sink.Sink<R2 | R, E2 | E, In & In2, L | L2, readonly [Z, Z2]>
1990
+ >(
1991
+ (args) => isSink(args[1]),
1992
+ <R, E, R2, E2, In, In2 extends In, L, L2, Z, Z2>(
1993
+ self: Sink.Sink<R, E, In, L, Z>,
1994
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
1995
+ options?: { readonly concurrent?: boolean }
1996
+ ): Sink.Sink<R | R2, E | E2, In & In2, L | L2, readonly [Z, Z2]> => zipWith(self, that, (z, z2) => [z, z2], options)
1997
+ )
1998
+
1999
+ /** @internal */
2000
+ export const zipLeft = dual<
2001
+ <R2, E2, In, In2 extends In, L, L2, Z, Z2>(
2002
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2003
+ options?: { readonly concurrent?: boolean }
2004
+ ) => <R, E>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In & In2, L | L2, Z>,
2005
+ <R, E, R2, E2, In, In2 extends In, L, L2, Z, Z2>(
2006
+ self: Sink.Sink<R, E, In, L, Z>,
2007
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2008
+ options?: { readonly concurrent?: boolean }
2009
+ ) => Sink.Sink<R2 | R, E2 | E, In & In2, L | L2, Z>
2010
+ >(
2011
+ (args) => isSink(args[1]),
2012
+ <R, E, R2, E2, In, In2 extends In, L, L2, Z, Z2>(
2013
+ self: Sink.Sink<R, E, In, L, Z>,
2014
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2015
+ options?: { readonly concurrent?: boolean }
2016
+ ): Sink.Sink<R | R2, E | E2, In & In2, L | L2, Z> => zipWith(self, that, (z, _) => z, options)
2017
+ )
2018
+
2019
+ /** @internal */
2020
+ export const zipRight = dual<
2021
+ <R2, E2, In, In2 extends In, L, L2, Z, Z2>(
2022
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2023
+ options?: { readonly concurrent?: boolean }
2024
+ ) => <R, E>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In & In2, L | L2, Z2>,
2025
+ <R, E, R2, E2, In, In2 extends In, L, L2, Z, Z2>(
2026
+ self: Sink.Sink<R, E, In, L, Z>,
2027
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2028
+ options?: { readonly concurrent?: boolean }
2029
+ ) => Sink.Sink<R2 | R, E2 | E, In & In2, L | L2, Z2>
2030
+ >(
2031
+ (args) => isSink(args[1]),
2032
+ <R, E, R2, E2, In, In2 extends In, L, L2, Z, Z2>(
2033
+ self: Sink.Sink<R, E, In, L, Z>,
2034
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2035
+ options?: { readonly concurrent?: boolean }
2036
+ ): Sink.Sink<R | R2, E | E2, In & In2, L | L2, Z2> => zipWith(self, that, (_, z2) => z2, options)
2037
+ )
2038
+
2039
+ /** @internal */
2040
+ export const zipWith = dual<
2041
+ <R2, E2, In, In2 extends In, L, L2, Z, Z2, Z3>(
2042
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2043
+ f: (z: Z, z1: Z2) => Z3,
2044
+ options?: { readonly concurrent?: boolean }
2045
+ ) => <R, E>(self: Sink.Sink<R, E, In, L, Z>) => Sink.Sink<R2 | R, E2 | E, In & In2, L | L2, Z3>,
2046
+ <R, E, R2, E2, In, In2 extends In, L, L2, Z, Z2, Z3>(
2047
+ self: Sink.Sink<R, E, In, L, Z>,
2048
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2049
+ f: (z: Z, z1: Z2) => Z3,
2050
+ options?: { readonly concurrent?: boolean }
2051
+ ) => Sink.Sink<R2 | R, E2 | E, In & In2, L | L2, Z3>
2052
+ >(
2053
+ (args) => isSink(args[1]),
2054
+ <R, E, R2, E2, In, In2 extends In, L, L2, Z, Z2, Z3>(
2055
+ self: Sink.Sink<R, E, In, L, Z>,
2056
+ that: Sink.Sink<R2, E2, In2, L2, Z2>,
2057
+ f: (z: Z, z1: Z2) => Z3,
2058
+ options?: { readonly concurrent?: boolean }
2059
+ ): Sink.Sink<R | R2, E | E2, In & In2, L | L2, Z3> =>
2060
+ options?.concurrent ?
2061
+ raceWith(self, {
2062
+ other: that,
2063
+ onSelfDone: Exit.match({
2064
+ onFailure: (cause) => mergeDecision.Done(Effect.failCause(cause)),
2065
+ onSuccess: (leftZ) =>
2066
+ mergeDecision.Await<R | R2, E2, Z2, E | E2, Z3>(
2067
+ Exit.match({
2068
+ onFailure: Effect.failCause,
2069
+ onSuccess: (rightZ) => Effect.succeed(f(leftZ, rightZ))
2070
+ })
2071
+ )
2072
+ }),
2073
+ onOtherDone: Exit.match({
2074
+ onFailure: (cause) => mergeDecision.Done(Effect.failCause(cause)),
2075
+ onSuccess: (rightZ) =>
2076
+ mergeDecision.Await<R | R2, E, Z, E | E2, Z3>(
2077
+ Exit.match({
2078
+ onFailure: Effect.failCause,
2079
+ onSuccess: (leftZ) => Effect.succeed(f(leftZ, rightZ))
2080
+ })
2081
+ )
2082
+ })
2083
+ }) :
2084
+ flatMap(self, (z) => map(that, (z2) => f(z, z2)))
2085
+ )
2086
+
2087
+ // Circular with Channel
2088
+
2089
+ /** @internal */
2090
+ export const channelToSink = <Env, InErr, InElem, OutErr, OutElem, OutDone>(
2091
+ self: Channel.Channel<Env, InErr, Chunk.Chunk<InElem>, unknown, OutErr, Chunk.Chunk<OutElem>, OutDone>
2092
+ ): Sink.Sink<Env, OutErr, InElem, OutElem, OutDone> => new SinkImpl(self)
2093
+
2094
+ // Constants
2095
+
2096
+ /** @internal */
2097
+ export const count: Sink.Sink<never, never, unknown, never, number> = foldLeftChunks(
2098
+ 0,
2099
+ (acc, chunk) => acc + chunk.length
2100
+ )
2101
+
2102
+ /** @internal */
2103
+ export const mkString: Sink.Sink<never, never, unknown, never, string> = suspend(() => {
2104
+ const strings: Array<string> = []
2105
+ return pipe(
2106
+ foldLeftChunks<void, unknown>(void 0, (_, elems) =>
2107
+ Chunk.map(elems, (elem) => {
2108
+ strings.push(String(elem))
2109
+ })),
2110
+ map(() => strings.join(""))
2111
+ )
2112
+ })
2113
+
2114
+ /** @internal */
2115
+ export const timed: Sink.Sink<never, never, unknown, never, Duration.Duration> = pipe(
2116
+ withDuration(drain),
2117
+ map((tuple) => tuple[1])
2118
+ )