@typed/fx 1.18.4 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (423) hide show
  1. package/AsyncData/package.json +6 -0
  2. package/Emitter/package.json +6 -0
  3. package/Form/package.json +6 -0
  4. package/FormEntry/package.json +6 -0
  5. package/Fx/package.json +6 -0
  6. package/Guard/package.json +6 -0
  7. package/Idle/package.json +6 -0
  8. package/Match/package.json +6 -0
  9. package/Pull/package.json +6 -0
  10. package/Push/package.json +6 -0
  11. package/RefArray/package.json +6 -0
  12. package/RefChunk/package.json +6 -0
  13. package/RefHashMap/package.json +6 -0
  14. package/RefHashSet/package.json +6 -0
  15. package/RefSubject/package.json +6 -0
  16. package/Sink/package.json +6 -0
  17. package/Stream/package.json +6 -0
  18. package/Subject/package.json +6 -0
  19. package/TypeId/package.json +6 -0
  20. package/Typeclass/package.json +6 -0
  21. package/Versioned/package.json +6 -0
  22. package/dist/cjs/AsyncData.js +177 -0
  23. package/dist/cjs/AsyncData.js.map +1 -0
  24. package/dist/cjs/Emitter.js +24 -21
  25. package/dist/cjs/Emitter.js.map +1 -1
  26. package/dist/cjs/Form.js +78 -21
  27. package/dist/cjs/Form.js.map +1 -1
  28. package/dist/cjs/FormEntry.js +75 -48
  29. package/dist/cjs/FormEntry.js.map +1 -1
  30. package/dist/cjs/Fx.js +517 -872
  31. package/dist/cjs/Fx.js.map +1 -1
  32. package/dist/cjs/Guard.js +21 -13
  33. package/dist/cjs/Guard.js.map +1 -1
  34. package/dist/cjs/Idle.js +49 -37
  35. package/dist/cjs/Idle.js.map +1 -1
  36. package/dist/cjs/Match.js +99 -61
  37. package/dist/cjs/Match.js.map +1 -1
  38. package/dist/cjs/Pull.js.map +1 -1
  39. package/dist/cjs/Push.js +168 -0
  40. package/dist/cjs/Push.js.map +1 -0
  41. package/dist/cjs/RefArray.js +32 -30
  42. package/dist/cjs/RefArray.js.map +1 -1
  43. package/dist/cjs/RefChunk.js +26 -24
  44. package/dist/cjs/RefChunk.js.map +1 -1
  45. package/dist/cjs/RefHashMap.js +20 -20
  46. package/dist/cjs/RefHashMap.js.map +1 -1
  47. package/dist/cjs/RefHashSet.js +11 -8
  48. package/dist/cjs/RefHashSet.js.map +1 -1
  49. package/dist/cjs/RefSubject.js +899 -158
  50. package/dist/cjs/RefSubject.js.map +1 -1
  51. package/dist/cjs/Sink.js +588 -62
  52. package/dist/cjs/Sink.js.map +1 -1
  53. package/dist/cjs/Stream.js +15 -10
  54. package/dist/cjs/Stream.js.map +1 -1
  55. package/dist/cjs/Subject.js +153 -55
  56. package/dist/cjs/Subject.js.map +1 -1
  57. package/dist/cjs/TypeId.js +10 -5
  58. package/dist/cjs/TypeId.js.map +1 -1
  59. package/dist/cjs/Typeclass.js +28 -31
  60. package/dist/cjs/Typeclass.js.map +1 -1
  61. package/dist/cjs/Versioned.js +118 -57
  62. package/dist/cjs/Versioned.js.map +1 -1
  63. package/dist/cjs/index.js +44 -8
  64. package/dist/cjs/index.js.map +1 -1
  65. package/dist/cjs/internal/{deferred-ref.js → DeferredRef.js} +45 -13
  66. package/dist/cjs/internal/DeferredRef.js.map +1 -0
  67. package/dist/cjs/internal/UnionToTuple.js +6 -0
  68. package/dist/cjs/internal/UnionToTuple.js.map +1 -0
  69. package/dist/cjs/internal/core.js +1590 -779
  70. package/dist/cjs/internal/core.js.map +1 -1
  71. package/dist/cjs/internal/diff.js +114 -0
  72. package/dist/cjs/internal/diff.js.map +1 -0
  73. package/dist/cjs/internal/effect-loop-operator.js +288 -0
  74. package/dist/cjs/internal/effect-loop-operator.js.map +1 -0
  75. package/dist/cjs/internal/effect-operator.js +46 -37
  76. package/dist/cjs/internal/effect-operator.js.map +1 -1
  77. package/dist/cjs/internal/effect-producer.js +74 -0
  78. package/dist/cjs/internal/effect-producer.js.map +1 -0
  79. package/dist/cjs/internal/helpers.js +158 -128
  80. package/dist/cjs/internal/helpers.js.map +1 -1
  81. package/dist/cjs/internal/keyed.js +136 -173
  82. package/dist/cjs/internal/keyed.js.map +1 -1
  83. package/dist/cjs/internal/loop-operator.js +213 -0
  84. package/dist/cjs/internal/loop-operator.js.map +1 -0
  85. package/dist/cjs/internal/operator.js +79 -0
  86. package/dist/cjs/internal/operator.js.map +1 -0
  87. package/dist/cjs/internal/protos.js +19 -81
  88. package/dist/cjs/internal/protos.js.map +1 -1
  89. package/dist/cjs/internal/provide.js +47 -25
  90. package/dist/cjs/internal/provide.js.map +1 -1
  91. package/dist/cjs/internal/requestIdleCallback.js +5 -5
  92. package/dist/cjs/internal/requestIdleCallback.js.map +1 -1
  93. package/dist/cjs/internal/share.js +12 -15
  94. package/dist/cjs/internal/share.js.map +1 -1
  95. package/dist/cjs/internal/sync-operator.js +50 -22
  96. package/dist/cjs/internal/sync-operator.js.map +1 -1
  97. package/dist/cjs/internal/sync-producer.js +114 -0
  98. package/dist/cjs/internal/sync-producer.js.map +1 -0
  99. package/dist/cjs/internal/withKey.js +45 -51
  100. package/dist/cjs/internal/withKey.js.map +1 -1
  101. package/dist/dts/AsyncData.d.ts +185 -0
  102. package/dist/dts/AsyncData.d.ts.map +1 -0
  103. package/dist/dts/Emitter.d.ts +13 -20
  104. package/dist/dts/Emitter.d.ts.map +1 -1
  105. package/dist/dts/Form.d.ts +45 -28
  106. package/dist/dts/Form.d.ts.map +1 -1
  107. package/dist/dts/FormEntry.d.ts +25 -13
  108. package/dist/dts/FormEntry.d.ts.map +1 -1
  109. package/dist/dts/Fx.d.ts +983 -1387
  110. package/dist/dts/Fx.d.ts.map +1 -1
  111. package/dist/dts/Guard.d.ts +8 -1
  112. package/dist/dts/Guard.d.ts.map +1 -1
  113. package/dist/dts/Idle.d.ts +3 -3
  114. package/dist/dts/Idle.d.ts.map +1 -1
  115. package/dist/dts/Match.d.ts +8 -8
  116. package/dist/dts/Match.d.ts.map +1 -1
  117. package/dist/dts/Pull.d.ts +5 -5
  118. package/dist/dts/Pull.d.ts.map +1 -1
  119. package/dist/dts/Push.d.ts +170 -0
  120. package/dist/dts/Push.d.ts.map +1 -0
  121. package/dist/dts/RefArray.d.ts +21 -23
  122. package/dist/dts/RefArray.d.ts.map +1 -1
  123. package/dist/dts/RefChunk.d.ts +17 -19
  124. package/dist/dts/RefChunk.d.ts.map +1 -1
  125. package/dist/dts/RefHashMap.d.ts +19 -20
  126. package/dist/dts/RefHashMap.d.ts.map +1 -1
  127. package/dist/dts/RefHashSet.d.ts +12 -16
  128. package/dist/dts/RefHashSet.d.ts.map +1 -1
  129. package/dist/dts/RefSubject.d.ts +396 -187
  130. package/dist/dts/RefSubject.d.ts.map +1 -1
  131. package/dist/dts/Sink.d.ts +193 -93
  132. package/dist/dts/Sink.d.ts.map +1 -1
  133. package/dist/dts/Stream.d.ts +7 -1
  134. package/dist/dts/Stream.d.ts.map +1 -1
  135. package/dist/dts/Subject.d.ts +27 -36
  136. package/dist/dts/Subject.d.ts.map +1 -1
  137. package/dist/dts/TypeId.d.ts +10 -0
  138. package/dist/dts/TypeId.d.ts.map +1 -1
  139. package/dist/dts/Typeclass.d.ts +2 -2
  140. package/dist/dts/Typeclass.d.ts.map +1 -1
  141. package/dist/dts/Versioned.d.ts +50 -78
  142. package/dist/dts/Versioned.d.ts.map +1 -1
  143. package/dist/dts/index.d.ts +66 -6
  144. package/dist/dts/index.d.ts.map +1 -1
  145. package/dist/dts/internal/DeferredRef.d.ts +20 -0
  146. package/dist/dts/internal/DeferredRef.d.ts.map +1 -0
  147. package/dist/dts/internal/UnionToTuple.d.ts +6 -0
  148. package/dist/dts/internal/UnionToTuple.d.ts.map +1 -0
  149. package/dist/dts/internal/core.d.ts +218 -450
  150. package/dist/dts/internal/core.d.ts.map +1 -1
  151. package/dist/dts/internal/diff.d.ts +38 -0
  152. package/dist/dts/internal/diff.d.ts.map +1 -0
  153. package/dist/dts/internal/effect-loop-operator.d.ts +34 -0
  154. package/dist/dts/internal/effect-loop-operator.d.ts.map +1 -0
  155. package/dist/dts/internal/effect-operator.d.ts +8 -5
  156. package/dist/dts/internal/effect-operator.d.ts.map +1 -1
  157. package/dist/dts/internal/effect-producer.d.ts +25 -0
  158. package/dist/dts/internal/effect-producer.d.ts.map +1 -0
  159. package/dist/dts/internal/helpers.d.ts +33 -24
  160. package/dist/dts/internal/helpers.d.ts.map +1 -1
  161. package/dist/dts/internal/keyed.d.ts +3 -3
  162. package/dist/dts/internal/keyed.d.ts.map +1 -1
  163. package/dist/dts/internal/loop-operator.d.ts +40 -0
  164. package/dist/dts/internal/loop-operator.d.ts.map +1 -0
  165. package/dist/dts/internal/operator.d.ts +16 -0
  166. package/dist/dts/internal/operator.d.ts.map +1 -0
  167. package/dist/dts/internal/protos.d.ts +16 -43
  168. package/dist/dts/internal/protos.d.ts.map +1 -1
  169. package/dist/dts/internal/provide.d.ts +7 -1
  170. package/dist/dts/internal/provide.d.ts.map +1 -1
  171. package/dist/dts/internal/share.d.ts +12 -9
  172. package/dist/dts/internal/share.d.ts.map +1 -1
  173. package/dist/dts/internal/sync-operator.d.ts +7 -3
  174. package/dist/dts/internal/sync-operator.d.ts.map +1 -1
  175. package/dist/dts/internal/sync-producer.d.ts +36 -0
  176. package/dist/dts/internal/sync-producer.d.ts.map +1 -0
  177. package/dist/dts/internal/withKey.d.ts +3 -3
  178. package/dist/dts/internal/withKey.d.ts.map +1 -1
  179. package/dist/esm/AsyncData.js +151 -0
  180. package/dist/esm/AsyncData.js.map +1 -0
  181. package/dist/esm/Emitter.js +24 -21
  182. package/dist/esm/Emitter.js.map +1 -1
  183. package/dist/esm/Form.js +69 -14
  184. package/dist/esm/Form.js.map +1 -1
  185. package/dist/esm/FormEntry.js +77 -52
  186. package/dist/esm/FormEntry.js.map +1 -1
  187. package/dist/esm/Fx.js +509 -874
  188. package/dist/esm/Fx.js.map +1 -1
  189. package/dist/esm/Guard.js +5 -1
  190. package/dist/esm/Guard.js.map +1 -1
  191. package/dist/esm/Idle.js +49 -39
  192. package/dist/esm/Idle.js.map +1 -1
  193. package/dist/esm/Match.js +103 -63
  194. package/dist/esm/Match.js.map +1 -1
  195. package/dist/esm/Pull.js.map +1 -1
  196. package/dist/esm/Push.js +159 -0
  197. package/dist/esm/Push.js.map +1 -0
  198. package/dist/esm/RefArray.js +32 -30
  199. package/dist/esm/RefArray.js.map +1 -1
  200. package/dist/esm/RefChunk.js +26 -24
  201. package/dist/esm/RefChunk.js.map +1 -1
  202. package/dist/esm/RefHashMap.js +20 -20
  203. package/dist/esm/RefHashMap.js.map +1 -1
  204. package/dist/esm/RefHashSet.js +11 -8
  205. package/dist/esm/RefHashSet.js.map +1 -1
  206. package/dist/esm/RefSubject.js +873 -150
  207. package/dist/esm/RefSubject.js.map +1 -1
  208. package/dist/esm/Sink.js +608 -57
  209. package/dist/esm/Sink.js.map +1 -1
  210. package/dist/esm/Stream.js +13 -9
  211. package/dist/esm/Stream.js.map +1 -1
  212. package/dist/esm/Subject.js +151 -56
  213. package/dist/esm/Subject.js.map +1 -1
  214. package/dist/esm/TypeId.js +9 -4
  215. package/dist/esm/TypeId.js.map +1 -1
  216. package/dist/esm/Typeclass.js +29 -29
  217. package/dist/esm/Typeclass.js.map +1 -1
  218. package/dist/esm/Versioned.js +110 -53
  219. package/dist/esm/Versioned.js.map +1 -1
  220. package/dist/esm/index.js +66 -6
  221. package/dist/esm/index.js.map +1 -1
  222. package/dist/esm/internal/DeferredRef.js +54 -0
  223. package/dist/esm/internal/DeferredRef.js.map +1 -0
  224. package/dist/esm/internal/UnionToTuple.js +2 -0
  225. package/dist/esm/internal/UnionToTuple.js.map +1 -0
  226. package/dist/esm/internal/core.js +1439 -719
  227. package/dist/esm/internal/core.js.map +1 -1
  228. package/dist/esm/internal/diff.js +82 -0
  229. package/dist/esm/internal/diff.js.map +1 -0
  230. package/dist/esm/internal/effect-loop-operator.js +269 -0
  231. package/dist/esm/internal/effect-loop-operator.js.map +1 -0
  232. package/dist/esm/internal/effect-operator.js +44 -37
  233. package/dist/esm/internal/effect-operator.js.map +1 -1
  234. package/dist/esm/internal/effect-producer.js +47 -0
  235. package/dist/esm/internal/effect-producer.js.map +1 -0
  236. package/dist/esm/internal/helpers.js +157 -129
  237. package/dist/esm/internal/helpers.js.map +1 -1
  238. package/dist/esm/internal/keyed.js +128 -139
  239. package/dist/esm/internal/keyed.js.map +1 -1
  240. package/dist/esm/internal/loop-operator.js +186 -0
  241. package/dist/esm/internal/loop-operator.js.map +1 -0
  242. package/dist/esm/internal/operator.js +68 -0
  243. package/dist/esm/internal/operator.js.map +1 -0
  244. package/dist/esm/internal/protos.js +16 -75
  245. package/dist/esm/internal/protos.js.map +1 -1
  246. package/dist/esm/internal/provide.js +33 -25
  247. package/dist/esm/internal/provide.js.map +1 -1
  248. package/dist/esm/internal/requestIdleCallback.js +5 -5
  249. package/dist/esm/internal/requestIdleCallback.js.map +1 -1
  250. package/dist/esm/internal/share.js +12 -12
  251. package/dist/esm/internal/share.js.map +1 -1
  252. package/dist/esm/internal/sync-operator.js +49 -21
  253. package/dist/esm/internal/sync-operator.js.map +1 -1
  254. package/dist/esm/internal/sync-producer.js +88 -0
  255. package/dist/esm/internal/sync-producer.js.map +1 -0
  256. package/dist/esm/internal/withKey.js +46 -47
  257. package/dist/esm/internal/withKey.js.map +1 -1
  258. package/package.json +22 -62
  259. package/src/AsyncData.ts +447 -0
  260. package/src/Emitter.ts +47 -38
  261. package/src/Form.ts +185 -65
  262. package/src/FormEntry.ts +142 -109
  263. package/src/Fx.ts +1685 -1851
  264. package/src/Guard.ts +12 -1
  265. package/src/Idle.ts +76 -62
  266. package/src/Match.ts +149 -93
  267. package/src/Pull.ts +8 -8
  268. package/src/Push.ts +472 -0
  269. package/src/RefArray.ts +53 -51
  270. package/src/RefChunk.ts +44 -41
  271. package/src/RefHashMap.ts +57 -43
  272. package/src/RefHashSet.ts +21 -31
  273. package/src/RefSubject.ts +1984 -457
  274. package/src/Sink.ts +922 -171
  275. package/src/Stream.ts +32 -20
  276. package/src/Subject.ts +230 -87
  277. package/src/TypeId.ts +16 -4
  278. package/src/Typeclass.ts +31 -32
  279. package/src/Versioned.ts +220 -168
  280. package/src/index.ts +78 -6
  281. package/src/internal/DeferredRef.ts +62 -0
  282. package/src/internal/UnionToTuple.ts +11 -0
  283. package/src/internal/core.ts +2491 -1950
  284. package/src/internal/diff.ts +157 -0
  285. package/src/internal/effect-loop-operator.ts +466 -0
  286. package/src/internal/effect-operator.ts +89 -54
  287. package/src/internal/effect-producer.ts +125 -0
  288. package/src/internal/helpers.ts +275 -205
  289. package/src/internal/keyed.ts +192 -241
  290. package/src/internal/loop-operator.ts +266 -0
  291. package/src/internal/operator.ts +87 -0
  292. package/src/internal/protos.ts +29 -104
  293. package/src/internal/provide.ts +48 -40
  294. package/src/internal/requestIdleCallback.ts +5 -6
  295. package/src/internal/share.ts +26 -24
  296. package/src/internal/sync-operator.ts +68 -27
  297. package/src/internal/sync-producer.ts +146 -0
  298. package/src/internal/withKey.ts +64 -74
  299. package/dist/cjs/Computed.js +0 -115
  300. package/dist/cjs/Computed.js.map +0 -1
  301. package/dist/cjs/Filtered.js +0 -95
  302. package/dist/cjs/Filtered.js.map +0 -1
  303. package/dist/cjs/Model.js +0 -119
  304. package/dist/cjs/Model.js.map +0 -1
  305. package/dist/cjs/RefAsyncData.js +0 -187
  306. package/dist/cjs/RefAsyncData.js.map +0 -1
  307. package/dist/cjs/RefAsyncDataArray.js +0 -38
  308. package/dist/cjs/RefAsyncDataArray.js.map +0 -1
  309. package/dist/cjs/RefBoolean.js +0 -45
  310. package/dist/cjs/RefBoolean.js.map +0 -1
  311. package/dist/cjs/RefNumber.js +0 -49
  312. package/dist/cjs/RefNumber.js.map +0 -1
  313. package/dist/cjs/internal/core-ref-subject.js +0 -254
  314. package/dist/cjs/internal/core-ref-subject.js.map +0 -1
  315. package/dist/cjs/internal/core-subject.js +0 -108
  316. package/dist/cjs/internal/core-subject.js.map +0 -1
  317. package/dist/cjs/internal/deferred-ref.js.map +0 -1
  318. package/dist/cjs/internal/effect-primitive.js +0 -47
  319. package/dist/cjs/internal/effect-primitive.js.map +0 -1
  320. package/dist/cjs/internal/fx-effect-proto.js +0 -58
  321. package/dist/cjs/internal/fx-effect-proto.js.map +0 -1
  322. package/dist/cjs/internal/fx-primitive.js +0 -193
  323. package/dist/cjs/internal/fx-primitive.js.map +0 -1
  324. package/dist/cjs/internal/fx.js +0 -240
  325. package/dist/cjs/internal/fx.js.map +0 -1
  326. package/dist/cjs/internal/matchers.js +0 -34
  327. package/dist/cjs/internal/matchers.js.map +0 -1
  328. package/dist/cjs/internal/run.js +0 -54
  329. package/dist/cjs/internal/run.js.map +0 -1
  330. package/dist/cjs/internal/schema-ref-subject.js +0 -132
  331. package/dist/cjs/internal/schema-ref-subject.js.map +0 -1
  332. package/dist/cjs/internal/versioned-transform.js +0 -46
  333. package/dist/cjs/internal/versioned-transform.js.map +0 -1
  334. package/dist/dts/Computed.d.ts +0 -106
  335. package/dist/dts/Computed.d.ts.map +0 -1
  336. package/dist/dts/Filtered.d.ts +0 -97
  337. package/dist/dts/Filtered.d.ts.map +0 -1
  338. package/dist/dts/Model.d.ts +0 -200
  339. package/dist/dts/Model.d.ts.map +0 -1
  340. package/dist/dts/RefAsyncData.d.ts +0 -236
  341. package/dist/dts/RefAsyncData.d.ts.map +0 -1
  342. package/dist/dts/RefAsyncDataArray.d.ts +0 -56
  343. package/dist/dts/RefAsyncDataArray.d.ts.map +0 -1
  344. package/dist/dts/RefBoolean.d.ts +0 -47
  345. package/dist/dts/RefBoolean.d.ts.map +0 -1
  346. package/dist/dts/RefNumber.d.ts +0 -48
  347. package/dist/dts/RefNumber.d.ts.map +0 -1
  348. package/dist/dts/internal/core-ref-subject.d.ts +0 -100
  349. package/dist/dts/internal/core-ref-subject.d.ts.map +0 -1
  350. package/dist/dts/internal/core-subject.d.ts +0 -5
  351. package/dist/dts/internal/core-subject.d.ts.map +0 -1
  352. package/dist/dts/internal/deferred-ref.d.ts +0 -12
  353. package/dist/dts/internal/deferred-ref.d.ts.map +0 -1
  354. package/dist/dts/internal/effect-primitive.d.ts +0 -6
  355. package/dist/dts/internal/effect-primitive.d.ts.map +0 -1
  356. package/dist/dts/internal/fx-effect-proto.d.ts +0 -30
  357. package/dist/dts/internal/fx-effect-proto.d.ts.map +0 -1
  358. package/dist/dts/internal/fx-primitive.d.ts +0 -109
  359. package/dist/dts/internal/fx-primitive.d.ts.map +0 -1
  360. package/dist/dts/internal/fx.d.ts +0 -245
  361. package/dist/dts/internal/fx.d.ts.map +0 -1
  362. package/dist/dts/internal/matchers.d.ts +0 -33
  363. package/dist/dts/internal/matchers.d.ts.map +0 -1
  364. package/dist/dts/internal/run.d.ts +0 -8
  365. package/dist/dts/internal/run.d.ts.map +0 -1
  366. package/dist/dts/internal/schema-ref-subject.d.ts +0 -5
  367. package/dist/dts/internal/schema-ref-subject.d.ts.map +0 -1
  368. package/dist/dts/internal/versioned-transform.d.ts +0 -17
  369. package/dist/dts/internal/versioned-transform.d.ts.map +0 -1
  370. package/dist/esm/Computed.js +0 -103
  371. package/dist/esm/Computed.js.map +0 -1
  372. package/dist/esm/Filtered.js +0 -83
  373. package/dist/esm/Filtered.js.map +0 -1
  374. package/dist/esm/Model.js +0 -100
  375. package/dist/esm/Model.js.map +0 -1
  376. package/dist/esm/RefAsyncData.js +0 -163
  377. package/dist/esm/RefAsyncData.js.map +0 -1
  378. package/dist/esm/RefAsyncDataArray.js +0 -27
  379. package/dist/esm/RefAsyncDataArray.js.map +0 -1
  380. package/dist/esm/RefBoolean.js +0 -31
  381. package/dist/esm/RefBoolean.js.map +0 -1
  382. package/dist/esm/RefNumber.js +0 -35
  383. package/dist/esm/RefNumber.js.map +0 -1
  384. package/dist/esm/internal/core-ref-subject.js +0 -242
  385. package/dist/esm/internal/core-ref-subject.js.map +0 -1
  386. package/dist/esm/internal/core-subject.js +0 -90
  387. package/dist/esm/internal/core-subject.js.map +0 -1
  388. package/dist/esm/internal/deferred-ref.js +0 -23
  389. package/dist/esm/internal/deferred-ref.js.map +0 -1
  390. package/dist/esm/internal/effect-primitive.js +0 -41
  391. package/dist/esm/internal/effect-primitive.js.map +0 -1
  392. package/dist/esm/internal/fx-effect-proto.js +0 -43
  393. package/dist/esm/internal/fx-effect-proto.js.map +0 -1
  394. package/dist/esm/internal/fx-primitive.js +0 -175
  395. package/dist/esm/internal/fx-primitive.js.map +0 -1
  396. package/dist/esm/internal/fx.js +0 -216
  397. package/dist/esm/internal/fx.js.map +0 -1
  398. package/dist/esm/internal/matchers.js +0 -38
  399. package/dist/esm/internal/matchers.js.map +0 -1
  400. package/dist/esm/internal/run.js +0 -32
  401. package/dist/esm/internal/run.js.map +0 -1
  402. package/dist/esm/internal/schema-ref-subject.js +0 -121
  403. package/dist/esm/internal/schema-ref-subject.js.map +0 -1
  404. package/dist/esm/internal/versioned-transform.js +0 -37
  405. package/dist/esm/internal/versioned-transform.js.map +0 -1
  406. package/src/Computed.ts +0 -289
  407. package/src/Filtered.ts +0 -274
  408. package/src/Model.ts +0 -483
  409. package/src/RefAsyncData.ts +0 -547
  410. package/src/RefAsyncDataArray.ts +0 -135
  411. package/src/RefBoolean.ts +0 -71
  412. package/src/RefNumber.ts +0 -77
  413. package/src/internal/core-ref-subject.ts +0 -528
  414. package/src/internal/core-subject.ts +0 -143
  415. package/src/internal/deferred-ref.ts +0 -26
  416. package/src/internal/effect-primitive.ts +0 -230
  417. package/src/internal/fx-effect-proto.ts +0 -56
  418. package/src/internal/fx-primitive.ts +0 -223
  419. package/src/internal/fx.ts +0 -619
  420. package/src/internal/matchers.ts +0 -83
  421. package/src/internal/run.ts +0 -51
  422. package/src/internal/schema-ref-subject.ts +0 -163
  423. package/src/internal/versioned-transform.ts +0 -48
@@ -3,922 +3,1733 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.acquireUseRelease = void 0;
7
- exports.combine = combine;
8
- exports.continueWith = exports.concatMap = exports.compact = void 0;
9
- exports.drain = drain;
10
- exports.flatten = exports.flatMapWithStrategy = exports.flatMapErrorWithStrategy = exports.flatMapErrorConcurrently = exports.flatMapError = exports.flatMapConcurrently = exports.flatMapCauseWithStrategy = exports.flatMapCauseConcurrently = exports.flatMapCause = exports.flatMap = exports.filterMapErrorEffect = exports.filterMapError = exports.filterMapEffect = exports.filterMapCause = exports.filterMap = exports.filterError = exports.filterEffect = exports.filterCause = exports.filter = exports.failCause = exports.fail = exports.exhaustMatchCause = exports.exhaustMatch = exports.exhaustMapLatestError = exports.exhaustMapLatestCause = exports.exhaustMapLatest = exports.exhaustMapError = exports.exhaustMapCause = exports.exhaustMap = exports.exhaustLatestMatchCause = exports.exhaustLatestMatch = exports.exhaustLatest = exports.exhaust = exports.endWith = exports.empty = exports.during = exports.dropWhile = exports.dropUntil = exports.dropAfter = exports.drop = void 0;
11
- exports.from = from;
12
- exports.fromEffect = fromEffect;
13
- exports.fromEmitter = fromEmitter;
14
- exports.fromIterable = fromIterable;
15
- exports.fromSink = exports.fromScheduled = void 0;
16
- exports.fromStream = fromStream;
17
- exports.matchErrorWithStrategy = exports.matchErrorConcurrently = exports.matchCauseWithStrategy = exports.matchCauseConcurrently = exports.matchCause = exports.match = exports.mapErrorCause = exports.mapError = exports.mapEffect = exports.mapBoth = exports.map = exports.loopEffect = exports.loop = void 0;
6
+ exports.acquireUseRelease = acquireUseRelease;
7
+ exports.all = all;
8
+ exports.annotateLogs = annotateLogs;
9
+ exports.annotateSpans = annotateSpans;
10
+ exports.append = append;
11
+ exports.appendAll = appendAll;
12
+ exports.concatMap = concatMap;
13
+ exports.continueWith = continueWith;
14
+ exports.debounce = debounce;
15
+ exports.drop = exports.drain = exports.die = void 0;
16
+ exports.dropAfter = dropAfter;
17
+ exports.dropAfterEffect = dropAfterEffect;
18
+ exports.dropUntil = dropUntil;
19
+ exports.dropUntilEffect = dropUntilEffect;
20
+ exports.dropWhile = dropWhile;
21
+ exports.dropWhileEffect = dropWhileEffect;
22
+ exports.during = during;
23
+ exports.either = either;
24
+ exports.empty = void 0;
25
+ exports.exhaustFilterMapLatestEffect = exhaustFilterMapLatestEffect;
26
+ exports.exhaustMap = exhaustMap;
27
+ exports.exhaustMapCause = exhaustMapCause;
28
+ exports.exhaustMapEffect = exhaustMapEffect;
29
+ exports.exhaustMapError = exhaustMapError;
30
+ exports.exhaustMapLatest = exhaustMapLatest;
31
+ exports.exhaustMapLatestCause = exhaustMapLatestCause;
32
+ exports.exhaustMapLatestEffect = exhaustMapLatestEffect;
33
+ exports.exhaustMapLatestError = exhaustMapLatestError;
34
+ exports.exhaustMatchCause = exhaustMatchCause;
35
+ exports.exhaustMatchError = exhaustMatchError;
36
+ exports.exhaustMatchLatestCause = exhaustMatchLatestCause;
37
+ exports.exhaustMatchLatestError = exhaustMatchLatestError;
38
+ exports.exit = exit;
39
+ exports.filter = exports.failCause = exports.fail = void 0;
40
+ exports.filterCause = filterCause;
41
+ exports.filterCauseEffect = filterCauseEffect;
42
+ exports.filterEffect = void 0;
43
+ exports.filterError = filterError;
44
+ exports.filterErrorEffect = filterErrorEffect;
45
+ exports.filterMap = void 0;
46
+ exports.filterMapCause = filterMapCause;
47
+ exports.filterMapCauseEffect = filterMapCauseEffect;
48
+ exports.filterMapEffect = void 0;
49
+ exports.filterMapError = filterMapError;
50
+ exports.filterMapErrorEffect = filterMapErrorEffect;
51
+ exports.filterMapLoop = void 0;
52
+ exports.filterMapLoopCause = filterMapLoopCause;
53
+ exports.filterMapLoopCauseEffect = filterMapLoopCauseEffect;
54
+ exports.filterMapLoopEffect = void 0;
55
+ exports.filterMapLoopError = filterMapLoopError;
56
+ exports.filterMapLoopErrorEffect = filterMapLoopErrorEffect;
57
+ exports.findFirst = findFirst;
58
+ exports.first = first;
59
+ exports.flatMap = flatMap;
60
+ exports.flatMapCause = flatMapCause;
61
+ exports.flatMapCauseConcurrently = flatMapCauseConcurrently;
62
+ exports.flatMapCauseWithStrategy = flatMapCauseWithStrategy;
63
+ exports.flatMapConcurrently = flatMapConcurrently;
64
+ exports.flatMapConcurrentlyEffect = flatMapConcurrentlyEffect;
65
+ exports.flatMapEffect = flatMapEffect;
66
+ exports.flatMapError = flatMapError;
67
+ exports.flatMapErrorConcurrently = flatMapErrorConcurrently;
68
+ exports.flatMapErrorWithStrategy = flatMapErrorWithStrategy;
69
+ exports.flatMapWithStrategy = flatMapWithStrategy;
70
+ exports.fromArray = void 0;
71
+ exports.fromAsyncIterable = fromAsyncIterable;
72
+ exports.fromEffect = void 0;
73
+ exports.fromFxEffect = fromFxEffect;
74
+ exports.fromSync = exports.fromScheduled = exports.fromIterable = void 0;
75
+ exports.gen = gen;
76
+ exports.genScoped = genScoped;
77
+ exports.if = if_;
78
+ exports.interruptible = void 0;
79
+ exports.isEmpty = isEmpty;
80
+ exports.isFailCause = isFailCause;
81
+ exports.isNever = isNever;
82
+ exports.isPadWith = isPadWith;
83
+ exports.isProducer = isProducer;
84
+ exports.isProducerEffect = isProducerEffect;
85
+ exports.isProducerEffectTransformer = isProducerEffectTransformer;
86
+ exports.isProducerSyncTransformer = isProducerSyncTransformer;
87
+ exports.isSlice = isSlice;
88
+ exports.isTransformer = isTransformer;
89
+ exports.locally = locally;
90
+ exports.locallyWith = locallyWith;
91
+ exports.loop = void 0;
92
+ exports.loopCause = loopCause;
93
+ exports.loopCauseEffect = loopCauseEffect;
94
+ exports.loopEffect = void 0;
95
+ exports.loopError = loopError;
96
+ exports.loopErrorEffect = loopErrorEffect;
97
+ exports.make = make;
98
+ exports.map = void 0;
99
+ exports.mapBoth = mapBoth;
100
+ exports.mapCause = mapCause;
101
+ exports.mapCauseEffect = mapCauseEffect;
102
+ exports.mapEffect = void 0;
103
+ exports.mapError = mapError;
104
+ exports.mapErrorEffect = mapErrorEffect;
105
+ exports.matchCause = matchCause;
106
+ exports.matchCauseConcurrently = matchCauseConcurrently;
107
+ exports.matchCauseWithStrategy = matchCauseWithStrategy;
108
+ exports.matchError = matchError;
109
+ exports.matchErrorConcurrently = matchErrorConcurrently;
110
+ exports.matchErrorWithStrategy = matchErrorWithStrategy;
18
111
  exports.merge = merge;
19
- exports.mergeBuffer = mergeBuffer;
20
- exports.never = exports.middleware = exports.mergeSwitch = exports.mergeConcurrently = exports.mergeBufferConcurrently = void 0;
21
- exports.observe = observe;
22
- exports.provideServiceEffect = exports.provideService = exports.provide = exports.periodic = void 0;
112
+ exports.mergeAll = mergeAll;
113
+ exports.mergeFirst = mergeFirst;
114
+ exports.mergeOrdered = mergeOrdered;
115
+ exports.mergeOrderedConcurrently = mergeOrderedConcurrently;
116
+ exports.mergeRace = mergeRace;
117
+ exports.mergeSwitch = mergeSwitch;
118
+ exports.mergeWithStrategy = mergeWithStrategy;
119
+ exports.middleware = middleware;
120
+ exports.observe = exports.never = void 0;
121
+ exports.onError = onError;
122
+ exports.onExit = onExit;
123
+ exports.onInterrupt = onInterrupt;
124
+ exports.orElse = orElse;
125
+ exports.orElseCause = orElseCause;
126
+ exports.padWith = padWith;
127
+ exports.prepend = prepend;
128
+ exports.prependAll = prependAll;
129
+ exports.provide = provide;
130
+ exports.provideContext = provideContext;
131
+ exports.provideLayer = provideLayer;
132
+ exports.provideRuntime = provideRuntime;
133
+ exports.provideService = provideService;
134
+ exports.provideServiceEffect = provideServiceEffect;
23
135
  exports.race = race;
24
- exports.startWith = exports.snapshot = exports.slice = exports.skipRepeatsWith = exports.skipRepeats = exports.since = exports.scanEffect = exports.scan = exports.reduce = exports.recoverWith = void 0;
136
+ exports.raceAll = raceAll;
137
+ exports.reduce = void 0;
138
+ exports.sample = sample;
139
+ exports.scan = scan;
140
+ exports.scoped = exports.schedule = void 0;
141
+ exports.since = since;
142
+ exports.skipRepeats = skipRepeats;
143
+ exports.skipRepeatsWith = skipRepeatsWith;
144
+ exports.slice = void 0;
145
+ exports.snapshot = snapshot;
146
+ exports.snapshotEffect = snapshotEffect;
25
147
  exports.struct = struct;
26
- exports.succeed = succeed;
27
- exports.takeUntil = exports.take = exports.sync = exports.switchMatchCause = exports.switchMatch = exports.switchMapError = exports.switchMapCause = exports.switchMap = exports.suspend = void 0;
28
- exports.tap = exports.takeWhile = void 0;
29
- exports.toArray = toArray;
30
- exports.toChunk = toChunk;
31
- exports.toReadonlyArray = toReadonlyArray;
32
- exports.withScopedFork = exports.withFlattenStrategy = exports.withEarlyExit = exports.until = void 0;
33
- var _effect = /*#__PURE__*/require("effect");
148
+ exports.succeed = void 0;
149
+ exports.suspend = suspend;
150
+ exports.switchMap = switchMap;
151
+ exports.switchMapCause = switchMapCause;
152
+ exports.switchMapEffect = switchMapEffect;
153
+ exports.switchMapError = switchMapError;
154
+ exports.switchMatchCause = switchMatchCause;
155
+ exports.switchMatchError = switchMatchError;
156
+ exports.take = void 0;
157
+ exports.takeUntil = takeUntil;
158
+ exports.takeUntilEffect = takeUntilEffect;
159
+ exports.takeWhile = takeWhile;
160
+ exports.takeWhileEffect = takeWhileEffect;
161
+ exports.tapEffect = void 0;
162
+ exports.throttle = throttle;
163
+ exports.throttleLatest = throttleLatest;
164
+ exports.toEnqueue = toEnqueue;
165
+ exports.toReadonlyArray = void 0;
166
+ exports.tuple = tuple;
167
+ exports.uninterruptible = void 0;
168
+ exports.until = until;
169
+ exports.when = when;
170
+ exports.withConcurrency = withConcurrency;
171
+ exports.withConfigProvider = withConfigProvider;
172
+ exports.withLogSpan = withLogSpan;
173
+ exports.withMaxOpsBeforeYield = withMaxOpsBeforeYield;
174
+ exports.withParentSpan = withParentSpan;
175
+ exports.withPrevious = void 0;
176
+ exports.withRequestBatching = withRequestBatching;
177
+ exports.withRequestCache = withRequestCache;
178
+ exports.withRequestCaching = withRequestCaching;
179
+ exports.withScheduler = withScheduler;
180
+ exports.withSpan = withSpan;
181
+ exports.withTracer = withTracer;
182
+ exports.withTracerTiming = withTracerTiming;
183
+ var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/context"));
184
+ var Boolean = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Boolean"));
185
+ var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Cause"));
186
+ var Clock = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Clock"));
187
+ var Deferred = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Deferred"));
188
+ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
189
+ var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Either"));
190
+ var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Equal"));
191
+ var ExecutionStrategy = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/ExecutionStrategy"));
192
+ var Exit = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Exit"));
193
+ var Fiber = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Fiber"));
34
194
  var _Function = /*#__PURE__*/require("effect/Function");
35
- var _context = /*#__PURE__*/require("@typed/context");
36
- var Schedule = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Schedule"));
37
- var _effectOperator = /*#__PURE__*/require("./effect-operator.js");
38
- var _helpers = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./helpers.js"));
39
- var helpers = _helpers;
40
- var Provide = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./provide.js"));
41
- var strategies = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./strategies.js"));
42
- var _syncOperator = /*#__PURE__*/require("./sync-operator.js");
43
- var Emitter = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Emitter.js"));
195
+ var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
196
+ var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option"));
197
+ var Predicate = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Predicate"));
198
+ var Ref = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Ref"));
199
+ var Scope = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Scope"));
200
+ var Tracer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Tracer"));
44
201
  var Sink = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Sink.js"));
45
202
  var _bounds = /*#__PURE__*/require("./bounds.js");
46
- var _effectPrimitive = /*#__PURE__*/require("./effect-primitive.js");
47
- var _fxPrimitive = /*#__PURE__*/require("./fx-primitive.js");
48
- var _matchers = /*#__PURE__*/require("./matchers.js");
203
+ var EffectLoopOp = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./effect-loop-operator.js"));
204
+ var EffectOp = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./effect-operator.js"));
205
+ var EffectProducer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./effect-producer.js"));
206
+ var _helpers = /*#__PURE__*/require("./helpers.js");
207
+ var SyncLoopOp = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./loop-operator.js"));
208
+ var Op = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./operator.js"));
49
209
  var _protos = /*#__PURE__*/require("./protos.js");
50
- var _run = /*#__PURE__*/require("./run.js");
210
+ var Provide = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./provide.js"));
211
+ var _strategies = /*#__PURE__*/require("./strategies.js");
212
+ var SyncOp = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./sync-operator.js"));
213
+ var SyncProducer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./sync-producer.js"));
51
214
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
52
215
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
53
- const constUnit = () => _effect.Effect.unit;
54
- class Merge extends _fxPrimitive.ToFx {
216
+ const DISCARD = {
217
+ discard: true
218
+ };
219
+ const UNBOUNDED = {
220
+ concurrency: "unbounded"
221
+ };
222
+ function make(run) {
223
+ return new Make(run);
224
+ }
225
+ class Make extends _protos.FxBase {
226
+ _run;
227
+ constructor(_run) {
228
+ super();
229
+ this._run = _run;
230
+ }
231
+ run(sink) {
232
+ return Effect.contextWithEffect(ctx => this._run(Sink.provide(sink, ctx)));
233
+ }
234
+ }
235
+ class Producer extends _protos.FxBase {
236
+ i0;
237
+ constructor(i0) {
238
+ super();
239
+ this.i0 = i0;
240
+ }
241
+ run(sink) {
242
+ return SyncProducer.runSink(this.i0, sink);
243
+ }
244
+ }
245
+ /**
246
+ * @internal
247
+ */
248
+ function isProducer(fx) {
249
+ return fx.constructor === Producer;
250
+ }
251
+ const succeed = value => new Producer(SyncProducer.Success(value));
252
+ exports.succeed = succeed;
253
+ const fromSync = f => new Producer(SyncProducer.FromSync(f));
254
+ exports.fromSync = fromSync;
255
+ const fromArray = array => new Producer(SyncProducer.FromArray(array));
256
+ exports.fromArray = fromArray;
257
+ const fromIterable = iterable => new Producer(SyncProducer.FromIterable(iterable));
258
+ exports.fromIterable = fromIterable;
259
+ class ProducerEffect extends _protos.FxBase {
260
+ i0;
261
+ constructor(i0) {
262
+ super();
263
+ this.i0 = i0;
264
+ }
265
+ run(sink) {
266
+ return EffectProducer.runSink(this.i0, sink);
267
+ }
268
+ }
269
+ /**
270
+ * @internal
271
+ */
272
+ function isProducerEffect(fx) {
273
+ return fx.constructor === ProducerEffect;
274
+ }
275
+ const fromEffect = effect => (0, _helpers.matchEffectPrimitive)(effect, {
276
+ // Match over Effect primitives and return Fx primitives to allow fusion to take place
277
+ Success: succeed,
278
+ Failure: failCause,
279
+ Sync: fromSync,
280
+ Left: fail,
281
+ Right: succeed,
282
+ Some: succeed,
283
+ None: fail,
284
+ Otherwise: effect => new ProducerEffect(EffectProducer.FromEffect(effect))
285
+ });
286
+ exports.fromEffect = fromEffect;
287
+ const fromScheduled = (input, schedule) => new ProducerEffect(EffectProducer.FromScheduled(input, schedule));
288
+ exports.fromScheduled = fromScheduled;
289
+ const schedule = (input, schedule) => new ProducerEffect(EffectProducer.Scheduled(input, schedule));
290
+ exports.schedule = schedule;
291
+ class FailCause extends _protos.FxBase {
292
+ i0;
293
+ constructor(i0) {
294
+ super();
295
+ this.i0 = i0;
296
+ }
297
+ run(sink) {
298
+ return sink.onFailure(this.i0);
299
+ }
300
+ }
301
+ /**
302
+ * @internal
303
+ */
304
+ function isFailCause(fx) {
305
+ return fx.constructor === FailCause;
306
+ }
307
+ const failCause = cause => new FailCause(cause);
308
+ exports.failCause = failCause;
309
+ const fail = error => failCause(Cause.fail(error));
310
+ exports.fail = fail;
311
+ const die = error => failCause(Cause.die(error));
312
+ exports.die = die;
313
+ class Transformer extends _protos.FxBase {
55
314
  i0;
56
315
  i1;
57
316
  constructor(i0, i1) {
58
- super(i0, i1);
317
+ super();
59
318
  this.i0 = i0;
60
319
  this.i1 = i1;
61
320
  }
62
- static make(fx, strategy) {
63
- // TODO: Flatten nested Merges
64
- if (fx.length === 0) return empty;
65
- const nonEmptyFx = fx.filter(fx => !(fx instanceof _fxPrimitive.Empty));
66
- if (nonEmptyFx.length === 0) return empty;
67
- if (nonEmptyFx.length === 1) return nonEmptyFx[0];
68
- const neverIndex = nonEmptyFx.findIndex(fx => fx instanceof _fxPrimitive.Never);
69
- if (neverIndex === -1) return new Merge(nonEmptyFx, strategy);
70
- switch (strategy._tag) {
71
- case "Switch":
72
- case "Ordered":
73
- // Will only emit up to the first Never
74
- return new Merge(nonEmptyFx.slice(0, neverIndex + 1), strategy);
75
- // No use creating fibers for Fx that don't emit
76
- case "Unordered":
77
- return new Merge(nonEmptyFx, strategy);
78
- }
321
+ run(sink) {
322
+ return this.i0.run(Op.compileOperatorSink(this.i1, sink));
79
323
  }
80
- toFx() {
81
- const {
82
- i0,
83
- i1
84
- } = this;
85
- switch (i1._tag) {
86
- case "Ordered":
87
- {
88
- const concurrency = i1.concurrency === Infinity ? "unbounded" : i1.concurrency;
89
- return fromSink(sink => _effect.Effect.flatMap(helpers.withBuffers(i0.length, sink), buffers => _effect.Effect.all(i0.map((fx, i) => _effect.Effect.flatMap((0, _run.run)(fx, Sink.WithContext(cause => _effect.Cause.isInterruptedOnly(cause) ? _effect.Effect.unit : sink.onFailure(cause), a => buffers.onSuccess(i, a))), () => buffers.onEnd(i))), {
90
- concurrency
91
- })));
92
- }
93
- case "Switch":
94
- return fromSink(sink => _effect.Effect.all(i0.map(fx => (0, _run.run)(fx, sink)), {
95
- concurrency: 1
96
- }));
97
- case "Unordered":
98
- return fromSink(sink => _effect.Effect.all(i0.map(fx => (0, _run.run)(fx, sink)), {
99
- concurrency: i1.concurrency === Infinity ? "unbounded" : i1.concurrency
100
- }));
324
+ static make(fx, operator) {
325
+ if (isEmpty(fx) || isNever(fx)) return fx;else if (isProducer(fx)) {
326
+ return new ProducerSyncTransformer(fx.i0, operator);
327
+ } else if (isTransformer(fx)) {
328
+ return new Transformer(fx.i0, Op.fuseOperators(fx.i1, operator));
329
+ } else if (isProducerSyncTransformer(fx)) {
330
+ return new ProducerSyncTransformer(fx.i0, Op.fuseOperators(fx.i1, operator));
331
+ } else if (isProducerEffect(fx)) {
332
+ return new ProducerEffectTransformer(fx.i0, operator);
333
+ } else if (isProducerEffectTransformer(fx)) {
334
+ return new ProducerEffectTransformer(fx.i0, Op.fuseOperators(fx.i1, operator));
335
+ } else if (isSuspend(fx)) {
336
+ return new SuspendedTransformer(fx.i0, operator);
337
+ } else if (isSuspendedTransformer(fx)) {
338
+ return new SuspendedTransformer(fx.i0, Op.fuseOperators(fx.i1, operator));
339
+ } else if (isFailCause(fx)) {
340
+ return fx;
341
+ } else {
342
+ return new Transformer(fx, operator);
101
343
  }
102
344
  }
103
345
  }
104
- class Slice extends _fxPrimitive.ToFx {
346
+ /**
347
+ * @internal
348
+ */
349
+ function isTransformer(fx) {
350
+ return fx.constructor === Transformer;
351
+ }
352
+ class ProducerSyncTransformer extends _protos.FxBase {
105
353
  i0;
106
354
  i1;
107
355
  constructor(i0, i1) {
108
- super(i0, i1);
356
+ super();
109
357
  this.i0 = i0;
110
358
  this.i1 = i1;
111
359
  }
112
- static make(fx, bounds) {
113
- if (fx instanceof Slice) {
114
- return new Slice(fx.i0, (0, _bounds.mergeBounds)(fx.i1, bounds));
115
- } else if (fx instanceof _fxPrimitive.Transformer && fx.i1._tag === "Map") {
116
- return new _fxPrimitive.Transformer(Slice.make(fx.i0, bounds), fx.i1);
360
+ run(sink) {
361
+ return SyncProducer.runSink(this.i0, Op.compileOperatorSink(this.i1, sink));
362
+ }
363
+ }
364
+ /**
365
+ * @internal
366
+ */
367
+ function isProducerSyncTransformer(fx) {
368
+ return fx.constructor === ProducerSyncTransformer;
369
+ }
370
+ const map = (fx, f) => Transformer.make(fx, SyncOp.Map(f));
371
+ exports.map = map;
372
+ const filter = (fx, f) => Transformer.make(fx, SyncOp.Filter(f));
373
+ exports.filter = filter;
374
+ const filterMap = (fx, f) => Transformer.make(fx, SyncOp.FilterMap(f));
375
+ exports.filterMap = filterMap;
376
+ const mapEffect = (fx, f) => Transformer.make(fx, EffectOp.MapEffect(f));
377
+ exports.mapEffect = mapEffect;
378
+ const filterMapEffect = (fx, f) => Transformer.make(fx, EffectOp.FilterMapEffect(f));
379
+ exports.filterMapEffect = filterMapEffect;
380
+ const filterEffect = (fx, f) => Transformer.make(fx, EffectOp.FilterEffect(f));
381
+ exports.filterEffect = filterEffect;
382
+ const tapEffect = (fx, f) => Transformer.make(fx, EffectOp.TapEffect(f));
383
+ exports.tapEffect = tapEffect;
384
+ const loop = (fx, seed, f) => Transformer.make(fx, SyncLoopOp.LoopOperator(seed, f));
385
+ exports.loop = loop;
386
+ const withPrevious = fx => loop(fx, Option.none(), (acc, a) => [[acc, a], Option.some(a)]);
387
+ exports.withPrevious = withPrevious;
388
+ const filterMapLoop = (fx, seed, f) => Transformer.make(fx, SyncLoopOp.FilterMapLoopOperator(seed, f));
389
+ exports.filterMapLoop = filterMapLoop;
390
+ const loopEffect = (fx, seed, f) => Transformer.make(fx, EffectLoopOp.LoopEffectOperator(seed, f));
391
+ exports.loopEffect = loopEffect;
392
+ const filterMapLoopEffect = (fx, seed, f) => Transformer.make(fx, EffectLoopOp.FilterMapLoopEffectOperator(seed, f));
393
+ exports.filterMapLoopEffect = filterMapLoopEffect;
394
+ const observe = (fx, f) => Observe.make(fx, f);
395
+ exports.observe = observe;
396
+ const constUnit = () => Effect.unit;
397
+ const drain = fx => Observe.make(fx, constUnit);
398
+ exports.drain = drain;
399
+ class Observe extends _protos.EffectBase {
400
+ i0;
401
+ i1;
402
+ constructor(i0, i1) {
403
+ super();
404
+ this.i0 = i0;
405
+ this.i1 = i1;
406
+ }
407
+ toEffect() {
408
+ return Effect.asyncEffect(resume => {
409
+ const {
410
+ i0: fx,
411
+ i1: f
412
+ } = this;
413
+ const onFailure = cause => Effect.sync(() => resume(Effect.failCause(cause)));
414
+ return Effect.zipRight(fx.run(Sink.make(onFailure, a => Effect.catchAllCause(f(a), onFailure))), Effect.sync(() => resume(Effect.unit)));
415
+ });
416
+ }
417
+ static make(fx, f) {
418
+ if (isEmpty(fx)) {
419
+ return Effect.unit;
420
+ } else if (isNever(fx)) {
421
+ return Effect.never;
422
+ } else if (isProducer(fx)) {
423
+ return SyncProducer.runEffect(fx.i0, f);
424
+ } else if (isProducerSyncTransformer(fx)) {
425
+ return Op.matchOperator(fx.i1, {
426
+ SyncOperator: op => SyncOp.matchSyncOperator(op, {
427
+ Map: op => SyncProducer.effectOnce(() => SyncProducer.runEffect(fx.i0, a => f(op.f(a)))),
428
+ Filter: op => SyncProducer.effectOnce(() => SyncProducer.runEffect(fx.i0, Effect.unifiedFn(a => op.f(a) ? f(a) : Effect.unit))),
429
+ FilterMap: op => SyncProducer.effectOnce(() => SyncProducer.runEffect(fx.i0, Effect.unifiedFn(a => Option.match(op.f(a), {
430
+ onNone: () => Effect.unit,
431
+ onSome: f
432
+ }))))
433
+ }),
434
+ EffectOperator: op => EffectOp.matchEffectOperator(op, {
435
+ MapEffect: op => SyncProducer.runEffect(fx.i0, a => Effect.flatMap(op.f(a), f)),
436
+ FilterMapEffect: op => SyncProducer.runEffect(fx.i0, a => Effect.flatMap(op.f(a), Effect.unifiedFn(Option.match({
437
+ onNone: () => Effect.unit,
438
+ onSome: f
439
+ })))),
440
+ FilterEffect: op => SyncProducer.runEffect(fx.i0, Effect.unifiedFn(a => Effect.flatMap(op.f(a), Effect.unifiedFn(b => b ? f(a) : Effect.unit)))),
441
+ TapEffect: op => SyncProducer.runEffect(fx.i0, a => Effect.flatMap(op.f(a), () => f(a)))
442
+ }),
443
+ SyncLoopOperator: op => SyncLoopOp.matchSyncLoopOperator(op, {
444
+ Loop: op => SyncProducer.effectOnce(() => SyncProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => {
445
+ const [c, b] = op.f(acc, a);
446
+ return Effect.as(f(c), b);
447
+ })),
448
+ FilterMapLoop: op => SyncProducer.effectOnce(() => SyncProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => {
449
+ const [c, b] = op.f(acc, a);
450
+ return Option.match(c, {
451
+ onNone: () => Effect.succeed(acc),
452
+ onSome: c => Effect.as(f(c), b)
453
+ });
454
+ }))
455
+ }),
456
+ EffectLoopOperator: op => EffectLoopOp.matchEffectLoopOperator(op, {
457
+ LoopEffect: op => SyncProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => Effect.flatMap(op.f(acc, a), ([c, b]) => Effect.as(f(c), b))),
458
+ FilterMapLoopEffect: op => SyncProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => Effect.flatMap(op.f(acc, a), ([c, b]) => Option.match(c, {
459
+ onNone: () => Effect.succeed(b),
460
+ onSome: c => Effect.as(f(c), b)
461
+ })))
462
+ })
463
+ });
464
+ } else if (isProducerEffect(fx)) {
465
+ return EffectProducer.runEffect(fx.i0, f);
466
+ } else if (isProducerEffectTransformer(fx)) {
467
+ return Op.matchOperator(fx.i1, {
468
+ SyncOperator: op => SyncOp.matchSyncOperator(op, {
469
+ Map: op => SyncProducer.effectOnce(() => EffectProducer.runEffect(fx.i0, a => f(op.f(a)))),
470
+ Filter: op => SyncProducer.effectOnce(() => EffectProducer.runEffect(fx.i0, Effect.unifiedFn(a => op.f(a) ? f(a) : Effect.unit))),
471
+ FilterMap: op => SyncProducer.effectOnce(() => EffectProducer.runEffect(fx.i0, Effect.unifiedFn(a => Option.match(op.f(a), {
472
+ onNone: () => Effect.unit,
473
+ onSome: f
474
+ }))))
475
+ }),
476
+ EffectOperator: op => EffectOp.matchEffectOperator(op, {
477
+ MapEffect: op => EffectProducer.runEffect(fx.i0, a => Effect.flatMap(op.f(a), f)),
478
+ FilterMapEffect: op => EffectProducer.runEffect(fx.i0, a => Effect.flatMap(op.f(a), Effect.unifiedFn(Option.match({
479
+ onNone: () => Effect.unit,
480
+ onSome: f
481
+ })))),
482
+ FilterEffect: op => EffectProducer.runEffect(fx.i0, Effect.unifiedFn(a => Effect.flatMap(op.f(a), Effect.unifiedFn(b => b ? f(a) : Effect.unit)))),
483
+ TapEffect: op => EffectProducer.runEffect(fx.i0, a => Effect.flatMap(op.f(a), () => f(a)))
484
+ }),
485
+ SyncLoopOperator: op => SyncLoopOp.matchSyncLoopOperator(op, {
486
+ Loop: op => SyncProducer.effectOnce(() => EffectProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => {
487
+ const [c, b] = op.f(acc, a);
488
+ return Effect.as(f(c), b);
489
+ })),
490
+ FilterMapLoop: op => SyncProducer.effectOnce(() => EffectProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => {
491
+ const [c, b] = op.f(acc, a);
492
+ return Option.match(c, {
493
+ onNone: () => Effect.succeed(acc),
494
+ onSome: c => Effect.as(f(c), b)
495
+ });
496
+ }))
497
+ }),
498
+ EffectLoopOperator: op => EffectLoopOp.matchEffectLoopOperator(op, {
499
+ LoopEffect: op => EffectProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => Effect.flatMap(op.f(acc, a), ([c, b]) => Effect.as(f(c), b))),
500
+ FilterMapLoopEffect: op => EffectProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => Effect.flatMap(op.f(acc, a), ([c, b]) => Option.match(c, {
501
+ onNone: () => Effect.succeed(b),
502
+ onSome: c => Effect.as(f(c), b)
503
+ })))
504
+ })
505
+ });
506
+ } else if (isFailCause(fx)) {
507
+ return Effect.failCause(fx.i0);
117
508
  } else {
118
- return new Slice(fx, bounds);
509
+ return new Observe(fx, f);
119
510
  }
120
511
  }
121
- toFx() {
122
- const fx = this.i0;
123
- const {
124
- max,
125
- min
126
- } = this.i1;
127
- return withEarlyExit(({
128
- sink
129
- }) => _effect.Effect.suspend(() => {
130
- let toSkip = min;
131
- let toTake = max;
132
- return (0, _run.run)(fx, Sink.WithContext(sink.onFailure, a => _effect.Effect.suspend(() => {
133
- if (toSkip > 0) {
134
- toSkip -= 1;
135
- return _effect.Effect.unit;
136
- } else if (toTake > 0) {
137
- toTake -= 1;
138
- return _effect.Effect.flatMap(sink.onSuccess(a), () => toTake <= 0 ? sink.earlyExit : _effect.Effect.unit);
139
- } else {
140
- return sink.earlyExit;
141
- }
142
- })));
143
- }));
144
- }
145
- }
146
- class Loop extends _fxPrimitive.ToFx {
512
+ }
513
+ const reduce = (fx, seed, f) => Reduce.make(fx, seed, f);
514
+ exports.reduce = reduce;
515
+ class Reduce extends _protos.EffectBase {
147
516
  i0;
148
517
  i1;
149
518
  i2;
150
519
  constructor(i0, i1, i2) {
151
- super(i0, i1, i2);
520
+ super();
152
521
  this.i0 = i0;
153
522
  this.i1 = i1;
154
523
  this.i2 = i2;
155
524
  }
156
- static make(fx, b, f) {
157
- if (fx instanceof _fxPrimitive.Transformer) {
158
- return FilterMapLoop.make(fx.i0, b, (0, _syncOperator.compileSyncReducer)(fx.i1, f));
159
- } else if (fx instanceof _fxPrimitive.TransformerEffect) {
160
- return new FilterMapLoopEffect(fx.i0, b, (0, _effectOperator.compileEffectLoop)(fx.i1, (b, a) => _effect.Effect.sync(() => f(b, a))));
525
+ toEffect() {
526
+ return Effect.suspend(() => {
527
+ let acc = this.i1;
528
+ return Effect.map(observe(this.i0, a => Effect.sync(() => acc = this.i2(acc, a))), () => acc);
529
+ });
530
+ }
531
+ static make(fx, seed, f) {
532
+ // TODO: optimize Effect trasformers
533
+ if (isEmpty(fx)) return Effect.succeed(seed);else if (isProducer(fx)) {
534
+ return SyncProducer.runReduce(fx.i0, seed, f);
535
+ } else if (isProducerSyncTransformer(fx)) {
536
+ return Op.matchOperator(fx.i1, {
537
+ SyncOperator: op => SyncProducer.syncOnce(() => SyncOp.runSyncReduce(fx.i0, op, seed, f)),
538
+ EffectOperator: op => EffectOp.runSyncReduce(fx.i0, op, seed, f),
539
+ SyncLoopOperator: op => SyncLoopOp.matchSyncLoopOperator(op, {
540
+ Loop: op => Effect.map(SyncProducer.runReduce(fx.i0, [op.seed, seed], ([opAcc, acc], a) => {
541
+ const [c, b] = op.f(opAcc, a);
542
+ const newAcc = f(acc, c);
543
+ return [b, newAcc];
544
+ }), x => x[1]),
545
+ FilterMapLoop: op => Effect.map(SyncProducer.runReduce(fx.i0, [op.seed, seed], ([opAcc, acc], a) => {
546
+ const [c, b] = op.f(opAcc, a);
547
+ const newAcc = Option.match(c, {
548
+ onNone: () => acc,
549
+ onSome: c => f(acc, c)
550
+ });
551
+ return [b, newAcc];
552
+ }), x => x[1])
553
+ }),
554
+ EffectLoopOperator: op => EffectLoopOp.matchEffectLoopOperator(op, {
555
+ LoopEffect: op => Effect.map(SyncProducer.runReduceEffect(fx.i0, [op.seed, seed], ([opAcc, acc], a) => {
556
+ return Effect.flatMap(op.f(opAcc, a), ([c, b]) => {
557
+ const newAcc = f(acc, c);
558
+ return Effect.succeed([b, newAcc]);
559
+ });
560
+ }), x => x[1]),
561
+ FilterMapLoopEffect: op => Effect.map(SyncProducer.runReduceEffect(fx.i0, [op.seed, seed], ([opAcc, acc], a) => {
562
+ return Effect.map(op.f(opAcc, a), ([c, b]) => {
563
+ const newAcc = Option.match(c, {
564
+ onNone: () => acc,
565
+ onSome: () => f(acc, b)
566
+ });
567
+ return [b, newAcc];
568
+ });
569
+ }), x => x[1])
570
+ })
571
+ });
572
+ } else if (isProducerEffect(fx)) {
573
+ return EffectProducer.runReduceEffect(fx.i0, seed, (b, a) => Effect.succeed(f(b, a)));
574
+ } else if (isFailCause(fx)) {
575
+ return Effect.failCause(fx.i0);
161
576
  } else {
162
- return new Loop(fx, f, b);
577
+ return new Reduce(fx, seed, f);
163
578
  }
164
579
  }
165
- toFx() {
166
- return fromSink(sink => _effect.Effect.suspend(() => {
167
- let acc = this.i2;
168
- return (0, _run.run)(this.i0, Sink.WithContext(sink.onFailure, a => _effect.Effect.suspend(() => {
169
- const [c, b] = this.i1(acc, a);
170
- acc = b;
171
- return sink.onSuccess(c);
172
- })));
173
- }));
580
+ }
581
+ const toReadonlyArray = fx => Effect.suspend(() => {
582
+ const init = [];
583
+ return Reduce.make(fx, init, (acc, a) => {
584
+ acc.push(a);
585
+ return acc;
586
+ });
587
+ });
588
+ exports.toReadonlyArray = toReadonlyArray;
589
+ const slice = (fx, drop, take) => Slice.make(fx, (0, _bounds.boundsFrom)(drop, take));
590
+ exports.slice = slice;
591
+ const take = (fx, n) => slice(fx, 0, n);
592
+ exports.take = take;
593
+ const drop = (fx, n) => slice(fx, n, Infinity);
594
+ exports.drop = drop;
595
+ class Slice extends _protos.FxBase {
596
+ i0;
597
+ i1;
598
+ constructor(i0, i1) {
599
+ super();
600
+ this.i0 = i0;
601
+ this.i1 = i1;
602
+ }
603
+ run(sink) {
604
+ return Sink.slice(sink, this.i1, s => this.i0.run(s));
605
+ }
606
+ static make(fx, bounds) {
607
+ if ((0, _bounds.isNilBounds)(bounds)) return empty;
608
+ if ((0, _bounds.isInfiniteBounds)(bounds)) return fx;
609
+ if (isSlice(fx)) {
610
+ return Slice.make(fx.i0, (0, _bounds.mergeBounds)(fx.i1, bounds));
611
+ } else if (isTransformer(fx) && fx.i1._tag === "Map") {
612
+ // Commute map and slice
613
+ return map(Slice.make(fx.i0, bounds), fx.i1.f);
614
+ } else {
615
+ return new Slice(fx, bounds);
616
+ }
174
617
  }
175
618
  }
176
- class FilterMapLoop extends _fxPrimitive.ToFx {
619
+ /**
620
+ * @internal
621
+ */
622
+ function isSlice(fx) {
623
+ return fx.constructor === Slice;
624
+ }
625
+ function skipRepeatsWith(fx, eq) {
626
+ return filterMapLoop(fx, Option.none(), (previous, a) => {
627
+ if (Option.isSome(previous) && eq(a, previous.value)) {
628
+ return [Option.none(), Option.some(a)];
629
+ } else {
630
+ return [Option.some(a), Option.some(a)];
631
+ }
632
+ });
633
+ }
634
+ function skipRepeats(fx) {
635
+ return skipRepeatsWith(fx, Equal.equals);
636
+ }
637
+ class ProducerEffectTransformer extends _protos.FxBase {
177
638
  i0;
178
639
  i1;
179
- i2;
180
- constructor(i0, i1, i2) {
181
- super(i0, i1, i2);
640
+ constructor(i0, i1) {
641
+ super();
182
642
  this.i0 = i0;
183
643
  this.i1 = i1;
184
- this.i2 = i2;
185
644
  }
186
- static make(fx, b, f) {
187
- return new FilterMapLoop(fx, b, f);
645
+ run(sink) {
646
+ return EffectProducer.runSink(this.i0, Op.compileOperatorSink(this.i1, sink));
188
647
  }
189
- toFx() {
190
- return fromSink(sink => _effect.Effect.suspend(() => {
191
- let acc = this.i1;
192
- return (0, _run.run)(this.i0, Sink.WithContext(sink.onFailure, a => _effect.Effect.suspend(() => {
193
- const optionCB = this.i2(acc, a);
194
- if (_effect.Option.isNone(optionCB)) return _effect.Effect.unit;
195
- const [c, b] = optionCB.value;
196
- acc = b;
197
- return sink.onSuccess(c);
198
- })));
199
- }));
648
+ }
649
+ /**
650
+ * @internal
651
+ */
652
+ function isProducerEffectTransformer(fx) {
653
+ return fx.constructor === ProducerEffectTransformer;
654
+ }
655
+ class Empty extends _protos.FxBase {
656
+ run() {
657
+ return Effect.unit;
200
658
  }
201
659
  }
202
- class LoopEffect extends _fxPrimitive.ToFx {
660
+ /**
661
+ * @internal
662
+ */
663
+ function isEmpty(fx) {
664
+ return fx.constructor === Empty;
665
+ }
666
+ const empty = exports.empty = /*#__PURE__*/new Empty();
667
+ class Never extends _protos.FxBase {
668
+ run() {
669
+ return Effect.never;
670
+ }
671
+ }
672
+ /**
673
+ * @internal
674
+ */
675
+ function isNever(fx) {
676
+ return fx.constructor === Never;
677
+ }
678
+ const never = exports.never = /*#__PURE__*/new Never();
679
+ function padWith(fx, start, end) {
680
+ return new PadWith(fx, start, end);
681
+ }
682
+ function prependAll(fx, start) {
683
+ return new PadWith(fx, start, []);
684
+ }
685
+ function appendAll(fx, end) {
686
+ return new PadWith(fx, [], end);
687
+ }
688
+ function prepend(fx, start) {
689
+ return new PadWith(fx, [start], []);
690
+ }
691
+ function append(fx, end) {
692
+ return new PadWith(fx, [], [end]);
693
+ }
694
+ function scan(fx, seed, f) {
695
+ return prepend(loop(fx, seed, (b, a) => {
696
+ const b2 = f(b, a);
697
+ return [b2, b2];
698
+ }), seed);
699
+ }
700
+ class PadWith extends _protos.FxBase {
203
701
  i0;
204
702
  i1;
205
703
  i2;
206
704
  constructor(i0, i1, i2) {
207
- super(i0, i1, i2);
705
+ super();
208
706
  this.i0 = i0;
209
707
  this.i1 = i1;
210
708
  this.i2 = i2;
211
709
  }
212
- static make(fx, f, b) {
213
- if (fx instanceof _fxPrimitive.TransformerEffect) {
214
- return new FilterMapLoopEffect(fx.i0, b, (0, _effectOperator.compileEffectLoop)(fx.i1, f));
215
- } else if (fx instanceof _fxPrimitive.Transformer) {
216
- return new FilterMapLoopEffect(fx.i0, b, (0, _effectOperator.compileEffectLoop)((0, _effectOperator.liftSyncOperator)(fx.i1), f));
710
+ run(sink) {
711
+ const onSuccess = a => sink.onSuccess(a);
712
+ return Effect.forEach(this.i1, onSuccess, DISCARD).pipe(Effect.zipRight(this.i0.run(sink)), Effect.zipRight(Effect.forEach(this.i2, onSuccess, DISCARD)));
713
+ }
714
+ static make(fx, start, end) {
715
+ if (isEmpty(fx) || isNever(fx)) return fx;else if (isPadWith(fx)) {
716
+ return new PadWith(fx.i0, concat(start, fx.i1), concat(fx.i2, end));
217
717
  } else {
218
- return new LoopEffect(fx, f, b);
718
+ return new PadWith(fx, start, end);
219
719
  }
220
720
  }
221
- toFx() {
222
- const {
223
- i0,
224
- i1,
225
- i2
226
- } = this;
227
- return fromSink(sink => _effect.Effect.flatMap(_effect.SynchronizedRef.make(i2), ref => (0, _run.run)(i0, Sink.WithContext(sink.onFailure, a => _effect.SynchronizedRef.updateEffect(ref, b => _effect.Effect.matchCauseEffect(i1(b, a), {
228
- onFailure: cause => _effect.Effect.as(sink.onFailure(cause), b),
229
- onSuccess: ([c, b2]) => _effect.Effect.as(sink.onSuccess(c), b2)
230
- }))))));
231
- }
232
721
  }
233
- class FilterMapLoopEffect extends _fxPrimitive.ToFx {
722
+ function concat(a, b) {
723
+ return {
724
+ *[Symbol.iterator]() {
725
+ yield* a;
726
+ yield* b;
727
+ }
728
+ };
729
+ }
730
+ /**
731
+ * @internal
732
+ */
733
+ function isPadWith(fx) {
734
+ return fx.constructor === PadWith;
735
+ }
736
+ function flatMapWithStrategy(fx, f, strategy, executionStrategy = ExecutionStrategy.sequential) {
737
+ return FlatMapWithStrategy.make(fx, f, strategy, executionStrategy);
738
+ }
739
+ function switchMap(fx, f, executionStrategy) {
740
+ return flatMapWithStrategy(fx, f, _strategies.Switch, executionStrategy);
741
+ }
742
+ function switchMapEffect(fx, f, executionStrategy) {
743
+ return switchMap(fx, a => fromEffect(f(a)), executionStrategy);
744
+ }
745
+ function exhaustMap(fx, f, executionStrategy) {
746
+ return flatMapWithStrategy(fx, f, _strategies.Exhaust, executionStrategy);
747
+ }
748
+ function exhaustMapEffect(fx, f, executionStrategy) {
749
+ return exhaustMap(fx, a => fromEffect(f(a)), executionStrategy);
750
+ }
751
+ function exhaustMapLatest(fx, f, executionStrategy) {
752
+ return flatMapWithStrategy(fx, f, _strategies.ExhaustLatest, executionStrategy);
753
+ }
754
+ function exhaustMapLatestEffect(fx, f, executionStrategy) {
755
+ return exhaustMapLatest(fx, a => fromEffect(f(a)), executionStrategy);
756
+ }
757
+ function exhaustFilterMapLatestEffect(fx, f, executionStrategy) {
758
+ return exhaustMapLatest(fx, a => fromFxEffect(Effect.map(f(a), Option.match({
759
+ onNone: () => empty,
760
+ onSome: succeed
761
+ }))), executionStrategy);
762
+ }
763
+ function flatMapConcurrently(fx, f, capacity, executionStrategy) {
764
+ return flatMapWithStrategy(fx, f, (0, _strategies.Bounded)(capacity), executionStrategy);
765
+ }
766
+ function concatMap(fx, f, executionStrategy) {
767
+ return flatMapConcurrently(fx, f, 1, executionStrategy);
768
+ }
769
+ function flatMapConcurrentlyEffect(fx, f, capacity, executionStrategy) {
770
+ return flatMapConcurrently(fx, a => fromEffect(f(a)), capacity, executionStrategy);
771
+ }
772
+ function flatMap(fx, f, executionStrategy) {
773
+ return flatMapWithStrategy(fx, f, _strategies.Unbounded, executionStrategy);
774
+ }
775
+ function flatMapEffect(fx, f, executionStrategy) {
776
+ return flatMap(fx, a => fromEffect(f(a)), executionStrategy);
777
+ }
778
+ class FlatMapWithStrategy extends _protos.FxBase {
234
779
  i0;
235
780
  i1;
236
781
  i2;
237
- constructor(i0, i1, i2) {
238
- super(i0, i1, i2);
782
+ i3;
783
+ withFork;
784
+ constructor(i0, i1, i2, i3) {
785
+ super();
239
786
  this.i0 = i0;
240
787
  this.i1 = i1;
241
788
  this.i2 = i2;
789
+ this.i3 = i3;
790
+ this.withFork = (0, _helpers.withFlattenStrategy)(i2);
242
791
  }
243
- toFx() {
244
- return fromSink(sink => _effect.Effect.suspend(() => {
245
- let acc = this.i1;
246
- return (0, _run.run)(this.i0, Sink.WithContext(sink.onFailure, a => this.i2(acc, a).pipe(_effect.Effect.matchCauseEffect({
247
- onFailure: sink.onFailure,
248
- onSuccess: optionCB => _effect.Effect.suspend(() => {
249
- if (_effect.Option.isNone(optionCB)) return _effect.Effect.unit;
250
- const [c, b] = optionCB.value;
251
- acc = b;
252
- return sink.onSuccess(c);
253
- })
254
- }))));
255
- }));
792
+ run(sink) {
793
+ return this.withFork(fork => Sink.withEarlyExit(sink, sink => this.i0.run(Sink.make(cause => Cause.isInterruptedOnly(cause) ? sink.earlyExit : sink.onFailure(cause), a => fork(this.i1(a).run(sink))))), this.i3);
794
+ }
795
+ static make(fx, f, strategy, executionStrategy) {
796
+ if (isEmpty(fx) || isNever(fx)) return fx;else if (isProducer(fx)) {
797
+ if (fx.i0._tag === "Success") return f(fx.i0.source);
798
+ if (fx.i0._tag === "FromSync") {
799
+ const producer = fx.i0;
800
+ return suspend(() => f(producer.source()));
801
+ }
802
+ const arr = Array.isArray(fx.i0.source) ? fx.i0.source : Array.from(fx.i0.source);
803
+ if (arr.length === 0) return empty;
804
+ if (arr.length === 1) return f(arr[0]);
805
+ switch (strategy._tag) {
806
+ case "Switch":
807
+ return f(arr[arr.length - 1]);
808
+ case "Exhaust":
809
+ return f(arr[0]);
810
+ case "ExhaustLatest":
811
+ return arr.length > 1 ? continueWith(f(arr[0]), () => f(arr[arr.length - 1])) : f(arr[0]);
812
+ default:
813
+ return new FlatMapWithStrategy(fx, f, strategy, executionStrategy);
814
+ }
815
+ } else if (isProducerEffect(fx) && fx.i0._tag === "FromEffect") {
816
+ return fromFxEffect(Effect.map(fx.i0.source, f));
817
+ } else if (isTransformer(fx) && fx.i1._tag === "Map") {
818
+ const {
819
+ f: op
820
+ } = fx.i1;
821
+ return new FlatMapWithStrategy(fx.i0, a => f(op(a)), strategy, executionStrategy);
822
+ } else {
823
+ return new FlatMapWithStrategy(fx, f, strategy, executionStrategy);
824
+ }
825
+ }
826
+ }
827
+ function fromFxEffect(effect) {
828
+ return new FromFxEffect(effect);
829
+ }
830
+ class FromFxEffect extends _protos.FxBase {
831
+ i0;
832
+ constructor(i0) {
833
+ super();
834
+ this.i0 = i0;
835
+ }
836
+ run(sink) {
837
+ return Effect.matchCauseEffect(this.i0, {
838
+ onFailure: cause => sink.onFailure(cause),
839
+ onSuccess: fx => fx.run(sink)
840
+ });
256
841
  }
257
842
  }
258
- class FxProvide extends _fxPrimitive.ToFx {
843
+ function gen(f) {
844
+ return fromFxEffect(Effect.gen(f));
845
+ }
846
+ function genScoped(f) {
847
+ return scoped(fromFxEffect(Effect.gen(f)));
848
+ }
849
+ function continueWith(fx, f) {
850
+ return ContinueWith.make(fx, f);
851
+ }
852
+ class ContinueWith extends _protos.FxBase {
259
853
  i0;
260
854
  i1;
261
855
  constructor(i0, i1) {
262
- super(i0, i1);
856
+ super();
263
857
  this.i0 = i0;
264
858
  this.i1 = i1;
265
859
  }
266
- static make(fx, provide) {
267
- if (fx instanceof FxProvide) {
268
- return new FxProvide(fx.i0, Provide.merge(fx.i1, provide));
860
+ run(sink) {
861
+ return Effect.flatMap(this.i0.run(sink), () => this.i1().run(sink));
862
+ }
863
+ static make(fx, f) {
864
+ if (isEmpty(fx)) return f();else if (isNever(fx)) return fx;else if (isProducer(fx)) {
865
+ return SyncProducer.matchSyncProducer(fx.i0, {
866
+ Success: source => prependAll(f(), [source]),
867
+ FromSync: source => suspend(() => prependAll(f(), [source()])),
868
+ FromArray: source => prependAll(f(), source),
869
+ FromIterable: source => prependAll(f(), source)
870
+ });
269
871
  } else {
270
- return new FxProvide(fx, provide);
872
+ return new ContinueWith(fx, f);
271
873
  }
272
874
  }
273
- toFx() {
274
- return fromSink(sink => _effect.Effect.catchAllCause(Provide.provideToEffect((0, _run.run)(this.i0, sink), this.i1), sink.onFailure));
275
- }
276
875
  }
277
- class Snapshot extends _fxPrimitive.ToFx {
876
+ function orElseCause(fx, f) {
877
+ return OrElseCause.make(fx, f);
878
+ }
879
+ class OrElseCause extends _protos.FxBase {
278
880
  i0;
279
881
  i1;
280
- i2;
281
- constructor(i0, i1, i2) {
282
- super(i0, i1, i2);
882
+ constructor(i0, i1) {
883
+ super();
283
884
  this.i0 = i0;
284
885
  this.i1 = i1;
285
- this.i2 = i2;
286
886
  }
287
- toFx() {
288
- return (0, _matchers.matchFxInput)(this.i1, {
289
- RefSubject: fx2 => this.runScoped(this.i0, fx2, this.i2),
290
- Fx: fx2 => this.runScoped(this.i0, fx2, this.i2),
291
- Effect: effect2 => mapEffect(this.i0, a => _effect.Effect.flatMap(effect2, b => this.i2(a, b))),
292
- Cause: cause2 => matchCause(this.i0, {
293
- onFailure: cause1 => _effect.Effect.failCause(_effect.Cause.sequential(cause1, cause2)),
294
- onSuccess: () => _effect.Effect.failCause(cause2)
295
- }),
296
- Iterable: iterable => withEarlyExit(({
297
- sink
298
- }) => {
299
- const iterator = iterable[Symbol.iterator]();
300
- return (0, _run.run)(this.i0, Sink.WithContext(sink.onFailure, a => {
301
- const result = iterator.next();
302
- if (result.done) {
303
- return sink.earlyExit;
304
- } else {
305
- return _effect.Effect.matchCauseEffect(this.i2(a, result.value), sink);
306
- }
307
- }));
308
- }),
309
- Otherwise: b => mapEffect(this.i0, a => this.i2(a, b))
310
- });
887
+ run(sink) {
888
+ return Effect.catchAllCause(observe(this.i0, sink.onSuccess), cause => this.i1(cause).run(sink));
311
889
  }
312
- runScoped(fx, fx2, f) {
313
- return withScopedFork(({
314
- fork,
315
- sink
316
- }) => _effect.Effect.flatMap(_effect.Ref.make(_effect.Option.none()), ref => _effect.Effect.flatMap(fork((0, _run.run)(fx2, Sink.WithContext(sink.onFailure, b => _effect.Ref.set(ref, _effect.Option.some(b))))), () => (0, _helpers.adjustTime)(1).pipe(_effect.Effect.zipRight((0, _run.run)(fx, Sink.WithContext(sink.onFailure, a => _effect.Effect.flatten(_effect.Ref.get(ref)).pipe(_effect.Effect.flatMap(b => _effect.Effect.matchCauseEffect(f(a, b), sink)), _effect.Effect.optionFromOptional, _effect.Effect.asUnit))))))));
890
+ static make(fx, f) {
891
+ if (isEmpty(fx)) return fx;else if (isNever(fx)) return fx;else {
892
+ return new OrElseCause(fx, f);
893
+ }
317
894
  }
318
895
  }
319
- class Middleware extends _fxPrimitive.ToFx {
896
+ function orElse(fx, f) {
897
+ return OrElse.make(fx, f);
898
+ }
899
+ class OrElse extends _protos.FxBase {
320
900
  i0;
321
901
  i1;
322
- i2;
323
- constructor(i0, i1, i2) {
324
- super(i0, i1);
902
+ constructor(i0, i1) {
903
+ super();
325
904
  this.i0 = i0;
326
905
  this.i1 = i1;
327
- this.i2 = i2;
328
906
  }
329
- static make(fx, middleware, mapSink) {
330
- if (fx instanceof Middleware) {
331
- return new Middleware(fx.i0, effect => middleware(fx.i1(effect)), s => fx.i2(mapSink(s)));
332
- } else {
333
- return new Middleware(fx, middleware, mapSink);
907
+ run(sink) {
908
+ return Effect.catchAll(Effect.asyncEffect(resume => Effect.zipRight(this.i0.run(Sink.make(cause => Either.match(Cause.failureOrCause(cause), {
909
+ onLeft: e => Effect.succeed(resume(Effect.fail(e))),
910
+ onRight: cause => sink.onFailure(cause)
911
+ }), sink.onSuccess)), Effect.sync(() => resume(Effect.unit)))), error => this.i1(error).run(sink));
912
+ }
913
+ static make(fx, f) {
914
+ if (isEmpty(fx)) return fx;else if (isNever(fx)) return fx;else {
915
+ return new OrElse(fx, f);
334
916
  }
335
917
  }
336
- toFx() {
337
- return fromSink(sink => this.i1((0, _run.run)(this.i0, this.i2(sink))));
918
+ }
919
+ function suspend(f) {
920
+ return new Suspend(f);
921
+ }
922
+ class Suspend extends _protos.FxBase {
923
+ i0;
924
+ constructor(i0) {
925
+ super();
926
+ this.i0 = i0;
927
+ }
928
+ run(sink) {
929
+ return this.i0().run(sink);
930
+ }
931
+ }
932
+ function isSuspend(fx) {
933
+ return fx.constructor === Suspend;
934
+ }
935
+ class SuspendedTransformer extends _protos.FxBase {
936
+ i0;
937
+ i1;
938
+ constructor(i0, i1) {
939
+ super();
940
+ this.i0 = i0;
941
+ this.i1 = i1;
942
+ }
943
+ run(sink) {
944
+ return this.i0().run(Op.compileOperatorSink(this.i1, sink));
338
945
  }
339
946
  }
340
- function succeed(value) {
341
- return new _fxPrimitive.Succeed(value);
947
+ function isSuspendedTransformer(fx) {
948
+ return fx.constructor === SuspendedTransformer;
342
949
  }
343
- function fromIterable(iterable) {
344
- return new _fxPrimitive.FromIterable(iterable);
950
+ function mergeWithStrategy(fx, stategy) {
951
+ return MergeWithStrategy.make(fx, stategy);
345
952
  }
346
- const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
347
- return _fxPrimitive.Transformer.make(fx, (0, _syncOperator.Map)(f));
348
- });
349
- const mapBoth = exports.mapBoth = /*#__PURE__*/(0, _Function.dual)(2, function mapBoth(fx, options) {
350
- return map(mapError(fx, options.onFailure), options.onSuccess);
351
- });
352
- const filter = exports.filter = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
353
- return _fxPrimitive.Transformer.make(fx, (0, _syncOperator.Filter)(f));
354
- });
355
- const filterMap = exports.filterMap = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
356
- return _fxPrimitive.Transformer.make(fx, (0, _syncOperator.FilterMap)(f));
357
- });
358
- const compact = fx => filterMap(fx, _Function.identity);
359
- exports.compact = compact;
360
- const mapErrorCause = exports.mapErrorCause = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
361
- return _fxPrimitive.TransformerCause.make(fx, (0, _syncOperator.Map)(f));
362
- });
363
- const mapError = exports.mapError = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
364
- return _fxPrimitive.TransformerCause.make(fx, (0, _syncOperator.Map)(_effect.Cause.map(f)));
365
- });
366
- const filterCause = exports.filterCause = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
367
- return _fxPrimitive.TransformerCause.make(fx, (0, _syncOperator.Filter)(f));
368
- });
369
- const filterMapCause = exports.filterMapCause = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
370
- return _fxPrimitive.TransformerCause.make(fx, (0, _syncOperator.FilterMap)(f));
371
- });
372
- const filterError = exports.filterError = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
373
- return filterMapCause(fx, cause => _effect.Cause.failureOrCause(cause).pipe(_effect.Either.match({
374
- onLeft: e => f(e) ? _effect.Option.some(_effect.Cause.fail(e)) : _effect.Option.none(),
375
- onRight: _effect.Option.some
376
- })));
377
- });
378
- const filterMapError = exports.filterMapError = /*#__PURE__*/(0, _Function.dual)(2, function map(fx, f) {
379
- return filterMapCause(fx, cause => _effect.Cause.failureOrCause(cause).pipe(_effect.Either.match({
380
- onLeft: e => _effect.Option.map(f(e), _effect.Cause.fail),
381
- onRight: _effect.Option.some
382
- })));
383
- });
384
- const filterMapErrorEffect = exports.filterMapErrorEffect = /*#__PURE__*/(0, _Function.dual)(2, (fx, f) => {
385
- return fromSink(sink => (0, _run.run)(fx, Sink.WithContext(cause => _effect.Either.match(_effect.Cause.failureOrCause(cause), {
386
- onLeft: e => _effect.Effect.matchCauseEffect(f(e), {
387
- onFailure: sink.onFailure,
388
- onSuccess: _effect.Option.match({
389
- onNone: () => _effect.Effect.unit,
390
- onSome: b => sink.onFailure(_effect.Cause.fail(b))
391
- })
392
- }),
393
- onRight: sink.onFailure
394
- }), sink.onSuccess)));
395
- });
396
- function observe(fx, onSuccees) {
397
- return helpers.withScopedFork(fork => _effect.Effect.flatMap(_effect.Deferred.make(), deferred => (0, _run.run)(fx, Sink.WithContext(cause => _effect.Deferred.failCause(deferred, cause), a => _effect.Effect.catchAllCause(onSuccees(a), cause => _effect.Deferred.failCause(deferred, cause)))).pipe(_effect.Effect.intoDeferred(deferred), fork, _effect.Effect.flatMap(() => _effect.Deferred.await(deferred)))));
953
+ function merge(fx, other) {
954
+ return mergeWithStrategy([fx, other], (0, _strategies.Unordered)(2));
398
955
  }
399
- function drain(fx) {
400
- return observe(fx, constUnit);
956
+ function mergeAll(fx) {
957
+ return mergeWithStrategy(fx, (0, _strategies.Unordered)(Infinity));
401
958
  }
402
- function toArray(fx) {
403
- return _effect.Effect.suspend(() => {
404
- const array = [];
405
- return _effect.Effect.as(observe(fx, a => _effect.Effect.sync(() => array.push(a))), array);
406
- });
959
+ function mergeOrdered(fx) {
960
+ return mergeOrderedConcurrently(fx, Infinity);
407
961
  }
408
- function toReadonlyArray(fx) {
409
- return toArray(fx);
962
+ function mergeOrderedConcurrently(fx, concurrency) {
963
+ return mergeWithStrategy(fx, (0, _strategies.Ordered)(concurrency));
410
964
  }
411
- const flatMapWithStrategy = exports.flatMapWithStrategy = /*#__PURE__*/(0, _Function.dual)(3, function flatMapWithStrategy(fx, f, strategy) {
412
- return new _fxPrimitive.WithFlattenStrategy(({
413
- fork,
414
- sink
415
- }) => (0, _run.run)(fx, Sink.WithContext(sink.onFailure, a => fork((0, _run.run)(from(f(a)), sink)))), strategy);
416
- });
417
- const switchMap = exports.switchMap = /*#__PURE__*/(0, _Function.dual)(2, function switchMap(fx, f) {
418
- return flatMapWithStrategy(fx, f, strategies.Switch);
419
- });
420
- const exhaustMap = exports.exhaustMap = /*#__PURE__*/(0, _Function.dual)(2, function exhaustmap(fx, f) {
421
- return flatMapWithStrategy(fx, f, strategies.Exhaust);
422
- });
423
- const exhaust = fx => exhaustMap(fx, _Function.identity);
424
- exports.exhaust = exhaust;
425
- const exhaustMapLatest = exports.exhaustMapLatest = /*#__PURE__*/(0, _Function.dual)(2, function exhaustMapLatest(fx, f) {
426
- return flatMapWithStrategy(fx, f, strategies.ExhaustLatest);
427
- });
428
- const exhaustLatest = fx => exhaustMapLatest(fx, _Function.identity);
429
- exports.exhaustLatest = exhaustLatest;
430
- const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, function flatMap(fx, f) {
431
- return flatMapWithStrategy(fx, f, strategies.Unbounded);
432
- });
433
- const flatten = fx => flatMap(fx, _Function.identity);
434
- exports.flatten = flatten;
435
- const flatMapConcurrently = exports.flatMapConcurrently = /*#__PURE__*/(0, _Function.dual)(3, function flatMapConcurrently(fx, f, concurrency) {
436
- return flatMapWithStrategy(fx, f, strategies.Bounded(concurrency));
437
- });
438
- const concatMap = exports.concatMap = /*#__PURE__*/(0, _Function.dual)(2, function concatMap(fx, f) {
439
- return flatMapConcurrently(fx, f, 1);
440
- });
441
- const acquireUseRelease = exports.acquireUseRelease = /*#__PURE__*/(0, _Function.dual)(3, function acquireUseRelease(acquire, use, release) {
442
- return fromSink(sink => _effect.Effect.catchAllCause(_effect.Effect.acquireUseRelease(acquire, a => (0, _run.run)(from(use(a)), sink), (a, exit) => _effect.Effect.catchAllCause(release(a, exit), sink.onFailure)), sink.onFailure));
443
- });
444
- function combine(fxs) {
445
- return fromSink(sink => _effect.Effect.suspend(() => {
446
- const total = fxs.length;
447
- if (total === 0) return _effect.Effect.unit;
448
- const values = new globalThis.Map();
449
- const sample = () => Array.from({
450
- length: total
451
- }, (_, i) => values.get(i));
452
- const emitIfReady = (value, index) => _effect.Effect.suspend(() => {
453
- values.set(index, value);
454
- if (values.size === total) {
455
- return sink.onSuccess(sample());
456
- } else {
457
- return _effect.Effect.unit;
458
- }
459
- });
460
- return _effect.Effect.all(fxs.map((fx, index) => (0, _run.run)(fx, Sink.WithContext(sink.onFailure, a => emitIfReady(a, index)))), {
461
- concurrency: "unbounded"
965
+ function mergeSwitch(fx) {
966
+ return mergeWithStrategy(fx, _strategies.Switch);
967
+ }
968
+ class MergeWithStrategy extends _protos.FxBase {
969
+ i0;
970
+ i1;
971
+ constructor(i0, i1) {
972
+ super();
973
+ this.i0 = i0;
974
+ this.i1 = i1;
975
+ }
976
+ run(sink) {
977
+ switch (this.i1._tag) {
978
+ case "Unordered":
979
+ return runUnordered(this.i0, sink, this.i1.concurrency === Infinity ? "unbounded" : this.i1.concurrency);
980
+ case "Ordered":
981
+ return runOrdered(this.i0, sink, this.i1.concurrency === Infinity ? "unbounded" : this.i1.concurrency);
982
+ case "Switch":
983
+ return runSwitch(this.i0, sink);
984
+ }
985
+ }
986
+ static make(fx, strategy) {
987
+ if (fx.length === 0) return empty;else if (fx.length === 1) return fx[0];else return new MergeWithStrategy(fx.filter(Predicate.not(isEmpty)), strategy);
988
+ }
989
+ }
990
+ function runUnordered(fx, sink, concurrency) {
991
+ return Effect.forEach(fx, fx => fx.run(sink), {
992
+ concurrency,
993
+ discard: true
994
+ });
995
+ }
996
+ function runOrdered(fx, sink, concurrency) {
997
+ return Effect.suspend(() => {
998
+ const buffers = (0, _helpers.withBuffers)(fx.length, sink);
999
+ return Effect.all(fx.map((fx, i) => Effect.flatMap(fx.run(Sink.make(cause => Cause.isInterruptedOnly(cause) ? Effect.unit : sink.onFailure(cause), a => buffers.onSuccess(i, a))), () => buffers.onEnd(i))), {
1000
+ concurrency
462
1001
  });
463
- }));
1002
+ });
464
1003
  }
465
- function struct(fxs) {
466
- return map(combine(Reflect.ownKeys(fxs).map(k => map(fxs[k], a => [k, a]))), Object.fromEntries);
1004
+ function runSwitch(fx, sink) {
1005
+ return Effect.forEach(fx, fx => fx.run(sink), {
1006
+ concurrency: 1,
1007
+ discard: true
1008
+ });
467
1009
  }
468
- function merge(fxs) {
469
- return Merge.make(fxs, strategies.Unordered(Infinity));
1010
+ function takeWhile(fx, f) {
1011
+ return TakeWhile.make(fx, f);
470
1012
  }
471
- const mergeConcurrently = exports.mergeConcurrently = /*#__PURE__*/(0, _Function.dual)(2, function mergeConcurrently(fxs, concurrency) {
472
- return Merge.make(fxs, strategies.Unordered(concurrency));
473
- });
474
- function mergeBuffer(fxs) {
475
- return Merge.make(fxs, strategies.Ordered(Infinity));
1013
+ function takeUntil(fx, f) {
1014
+ return TakeWhile.make(fx, Predicate.not(f));
476
1015
  }
477
- const mergeBufferConcurrently = exports.mergeBufferConcurrently = /*#__PURE__*/(0, _Function.dual)(2, function mergeConcurrently(fxs, concurrency) {
478
- return Merge.make(fxs, strategies.Ordered(concurrency));
479
- });
480
- const mergeSwitch = fxs => Merge.make(fxs, strategies.Switch);
481
- exports.mergeSwitch = mergeSwitch;
482
- function race(fxs) {
483
- if (fxs.length === 0) return empty;
484
- if (fxs.length === 1) return fxs[0];
485
- return withScopedFork(({
486
- fork,
487
- sink
488
- }) => _effect.Effect.asyncEffect(resume => _effect.Effect.gen(function* (_) {
489
- let winningIndex = -1;
490
- const fibers = yield* _(_effect.Effect.forEach(fxs, (fx, i) => fork((0, _run.run)(fx, Sink.Sink(cause => _effect.Effect.suspend(() => pickWinner(i) ? sink.onFailure(cause) : _effect.Effect.unit), a => _effect.Effect.suspend(() => pickWinner(i) ? sink.onSuccess(a) : _effect.Effect.unit))))));
491
- function pickWinner(i) {
492
- if (winningIndex === -1) {
493
- winningIndex = i;
494
- resume(_effect.Effect.succeed([i, fibers]));
495
- }
496
- return winningIndex === i;
1016
+ class TakeWhile extends _protos.FxBase {
1017
+ i0;
1018
+ i1;
1019
+ constructor(i0, i1) {
1020
+ super();
1021
+ this.i0 = i0;
1022
+ this.i1 = i1;
1023
+ }
1024
+ run(sink) {
1025
+ return Sink.takeWhile(sink, this.i1, s => this.i0.run(s));
1026
+ }
1027
+ static make(fx, predicate) {
1028
+ if (isEmpty(fx) || isNever(fx)) return fx;else {
1029
+ return new TakeWhile(fx, predicate);
497
1030
  }
498
- })).pipe(_effect.Effect.flatMap(([winningIndex, fibers]) => _effect.Effect.suspend(() => {
499
- const [winner] = fibers.splice(winningIndex, 1);
500
- return _effect.Effect.flatMap(_effect.Fiber.interruptAll(fibers), () => _effect.Fiber.join(winner));
501
- }))));
502
- }
503
- const empty = exports.empty = /*#__PURE__*/new _fxPrimitive.Empty();
504
- const never = exports.never = /*#__PURE__*/new _fxPrimitive.Never();
505
- const failCause = cause => new _fxPrimitive.Fail(cause);
506
- exports.failCause = failCause;
507
- const fail = e => failCause(_effect.Cause.fail(e));
508
- exports.fail = fail;
509
- const fromSink = f => new _fxPrimitive.FromSink(sink => _effect.Effect.catchAllCause(f(sink), sink.onFailure));
510
- exports.fromSink = fromSink;
511
- const suspend = f => new _fxPrimitive.Suspend(f);
512
- exports.suspend = suspend;
513
- const sync = f => new _fxPrimitive.Sync(f);
514
- exports.sync = sync;
515
- const slice = exports.slice = /*#__PURE__*/(0, _Function.dual)(3, function slice(fx, skip, take) {
516
- return Slice.make(fx, (0, _bounds.boundsFrom)(skip, take));
517
- });
518
- const take = exports.take = /*#__PURE__*/(0, _Function.dual)(2, function take(fx, n) {
519
- return slice(fx, 0, n);
520
- });
521
- const drop = exports.drop = /*#__PURE__*/(0, _Function.dual)(2, function drop(fx, n) {
522
- return slice(fx, n, Infinity);
523
- });
524
- const takeWhile = exports.takeWhile = /*#__PURE__*/(0, _Function.dual)(2, function takeWhile(fx, predicate) {
525
- return withEarlyExit(({
526
- sink
527
- }) => (0, _run.run)(fx, Sink.WithContext(sink.onFailure, a => _effect.Effect.matchCauseEffect(predicate(a), {
528
- onFailure: sink.onFailure,
529
- onSuccess: b => b ? sink.onSuccess(a) : sink.earlyExit
530
- }))));
531
- });
532
- const takeUntil = exports.takeUntil = /*#__PURE__*/(0, _Function.dual)(2, function takeUntil(fx, predicate) {
533
- return takeWhile(fx, a => _effect.Effect.map(predicate(a), x => !x));
534
- });
535
- const dropWhile = exports.dropWhile = /*#__PURE__*/(0, _Function.dual)(2, function dropWhile(fx, predicate) {
536
- return withEarlyExit(({
537
- sink
538
- }) => _effect.Effect.suspend(() => {
539
- let isDropping = true;
540
- return (0, _run.run)(fx, Sink.WithContext(sink.onFailure, a => isDropping ? _effect.Effect.matchCauseEffect(predicate(a), {
541
- onFailure: sink.onFailure,
542
- onSuccess: b => {
543
- if (b) {
544
- return _effect.Effect.unit;
545
- } else {
546
- isDropping = false;
547
- return sink.onSuccess(a);
548
- }
549
- }
550
- }) : sink.onSuccess(a)));
1031
+ }
1032
+ }
1033
+ function dropWhile(fx, f) {
1034
+ return DropUntil.make(fx, f);
1035
+ }
1036
+ function dropUntil(fx, f) {
1037
+ return DropUntil.make(fx, Predicate.not(f));
1038
+ }
1039
+ class DropUntil extends _protos.FxBase {
1040
+ i0;
1041
+ i1;
1042
+ constructor(i0, i1) {
1043
+ super();
1044
+ this.i0 = i0;
1045
+ this.i1 = i1;
1046
+ }
1047
+ run(sink) {
1048
+ return this.i0.run(Sink.dropWhile(sink, this.i1));
1049
+ }
1050
+ static make(fx, predicate) {
1051
+ if (isEmpty(fx) || isNever(fx)) return fx;else {
1052
+ return new DropUntil(fx, predicate);
1053
+ }
1054
+ }
1055
+ }
1056
+ function dropAfter(fx, f) {
1057
+ return DropAfter.make(fx, f);
1058
+ }
1059
+ class DropAfter extends _protos.FxBase {
1060
+ i0;
1061
+ i1;
1062
+ constructor(i0, i1) {
1063
+ super();
1064
+ this.i0 = i0;
1065
+ this.i1 = i1;
1066
+ }
1067
+ run(sink) {
1068
+ return this.i0.run(Sink.dropAfter(sink, this.i1));
1069
+ }
1070
+ static make(fx, predicate) {
1071
+ if (isEmpty(fx) || isNever(fx)) return fx;else {
1072
+ return new DropAfter(fx, predicate);
1073
+ }
1074
+ }
1075
+ }
1076
+ function takeWhileEffect(fx, f) {
1077
+ return TakeWhileEffect.make(fx, f);
1078
+ }
1079
+ function takeUntilEffect(fx, f) {
1080
+ return TakeWhileEffect.make(fx, a => Effect.map(f(a), Boolean.not));
1081
+ }
1082
+ class TakeWhileEffect extends _protos.FxBase {
1083
+ i0;
1084
+ i1;
1085
+ constructor(i0, i1) {
1086
+ super();
1087
+ this.i0 = i0;
1088
+ this.i1 = i1;
1089
+ }
1090
+ run(sink) {
1091
+ return Sink.takeWhileEffect(sink, this.i1, s => this.i0.run(s));
1092
+ }
1093
+ static make(fx, f) {
1094
+ if (isEmpty(fx) || isNever(fx)) return fx;else {
1095
+ return new TakeWhileEffect(fx, f);
1096
+ }
1097
+ }
1098
+ }
1099
+ function dropWhileEffect(fx, f) {
1100
+ return DropWhileEffect.make(fx, f);
1101
+ }
1102
+ function dropUntilEffect(fx, f) {
1103
+ return DropWhileEffect.make(fx, a => Effect.map(f(a), Boolean.not));
1104
+ }
1105
+ class DropWhileEffect extends _protos.FxBase {
1106
+ i0;
1107
+ i1;
1108
+ constructor(i0, i1) {
1109
+ super();
1110
+ this.i0 = i0;
1111
+ this.i1 = i1;
1112
+ }
1113
+ run(sink) {
1114
+ return this.i0.run(Sink.dropWhileEffect(sink, this.i1));
1115
+ }
1116
+ static make(fx, f) {
1117
+ if (isEmpty(fx) || isNever(fx)) return fx;else {
1118
+ return new DropWhileEffect(fx, f);
1119
+ }
1120
+ }
1121
+ }
1122
+ function dropAfterEffect(fx, f) {
1123
+ return DropAfterEffect.make(fx, f);
1124
+ }
1125
+ class DropAfterEffect extends _protos.FxBase {
1126
+ i0;
1127
+ i1;
1128
+ constructor(i0, i1) {
1129
+ super();
1130
+ this.i0 = i0;
1131
+ this.i1 = i1;
1132
+ }
1133
+ run(sink) {
1134
+ return this.i0.run(Sink.dropAfterEffect(sink, this.i1));
1135
+ }
1136
+ static make(fx, f) {
1137
+ if (isEmpty(fx) || isNever(fx)) return fx;else {
1138
+ return new DropAfterEffect(fx, f);
1139
+ }
1140
+ }
1141
+ }
1142
+ function during(fx, window) {
1143
+ return During.make(fx, window);
1144
+ }
1145
+ function since(fx, window) {
1146
+ return During.make(fx, map(window, () => never));
1147
+ }
1148
+ function until(fx, window) {
1149
+ return During.make(fx, succeed(window));
1150
+ }
1151
+ class During extends _protos.FxBase {
1152
+ i0;
1153
+ i1;
1154
+ constructor(i0, i1) {
1155
+ super();
1156
+ this.i0 = i0;
1157
+ this.i1 = i1;
1158
+ }
1159
+ run(sink) {
1160
+ return (0, _helpers.withScopedFork)(fork => Sink.withEarlyExit(sink, s => {
1161
+ let taking = false;
1162
+ const onFailure = cause => s.onFailure(cause);
1163
+ return Effect.flatMap(fork(take(this.i1, 1).run(Sink.make(onFailure, nested => {
1164
+ taking = true;
1165
+ return take(nested, 1).run(Sink.make(onFailure, () => s.earlyExit));
1166
+ }))), () => Effect.zipRight(
1167
+ // Allow fibers to start
1168
+ (0, _helpers.adjustTime)(1), this.i0.run(Sink.make(onFailure, a => taking ? s.onSuccess(a) : Effect.unit))));
1169
+ }), ExecutionStrategy.sequential);
1170
+ }
1171
+ static make(fx, window) {
1172
+ if (isEmpty(fx) || isNever(fx)) return fx;else {
1173
+ return new During(fx, window);
1174
+ }
1175
+ }
1176
+ }
1177
+ function middleware(fx, effect, sink) {
1178
+ return new Middleware(fx, effect, sink);
1179
+ }
1180
+ function onExit(fx, f) {
1181
+ return middleware(fx, Effect.onExit(f));
1182
+ }
1183
+ function onInterrupt(fx, f) {
1184
+ return middleware(fx, Effect.onInterrupt(f));
1185
+ }
1186
+ function onError(fx, f) {
1187
+ return middleware(fx, Effect.onError(f));
1188
+ }
1189
+ const scoped = fx => middleware(fx, Effect.scoped);
1190
+ exports.scoped = scoped;
1191
+ function annotateLogs(fx, key, value) {
1192
+ return middleware(fx, effect => Effect.annotateLogs(effect, key, value));
1193
+ }
1194
+ function annotateSpans(fx, key, value) {
1195
+ return middleware(fx, effect => Effect.annotateSpans(effect, key, value));
1196
+ }
1197
+ const interruptible = fx => middleware(fx, Effect.interruptible);
1198
+ exports.interruptible = interruptible;
1199
+ const uninterruptible = fx => middleware(fx, Effect.uninterruptible);
1200
+ exports.uninterruptible = uninterruptible;
1201
+ function locally(use, self, value) {
1202
+ return middleware(use, effect => Effect.locally(effect, self, value));
1203
+ }
1204
+ function locallyWith(use, self, f) {
1205
+ return middleware(use, effect => Effect.locallyWith(effect, self, f));
1206
+ }
1207
+ function withTracerTiming(fx, enabled) {
1208
+ return middleware(fx, effect => Effect.withTracerTiming(effect, enabled));
1209
+ }
1210
+ function withConcurrency(fx, concurrency) {
1211
+ return middleware(fx, effect => Effect.withConcurrency(effect, concurrency));
1212
+ }
1213
+ function withConfigProvider(fx, configProvider) {
1214
+ return middleware(fx, effect => Effect.withConfigProvider(effect, configProvider));
1215
+ }
1216
+ function withLogSpan(fx, span) {
1217
+ return middleware(fx, effect => Effect.withLogSpan(effect, span));
1218
+ }
1219
+ function withMaxOpsBeforeYield(fx, maxOps) {
1220
+ return middleware(fx, effect => Effect.withMaxOpsBeforeYield(effect, maxOps));
1221
+ }
1222
+ function withParentSpan(fx, parentSpan) {
1223
+ return middleware(fx, effect => Effect.withParentSpan(effect, parentSpan));
1224
+ }
1225
+ function withRequestBatching(fx, requestBatching) {
1226
+ return middleware(fx, effect => Effect.withRequestBatching(effect, requestBatching));
1227
+ }
1228
+ function withRequestCache(fx, cache) {
1229
+ return middleware(fx, effect => Effect.withRequestCache(effect, cache));
1230
+ }
1231
+ function withRequestCaching(fx, requestCaching) {
1232
+ return middleware(fx, effect => Effect.withRequestCaching(effect, requestCaching));
1233
+ }
1234
+ function withScheduler(fx, scheduler) {
1235
+ return middleware(fx, effect => Effect.withScheduler(effect, scheduler));
1236
+ }
1237
+ function withTracer(fx, tracer) {
1238
+ return middleware(fx, effect => Effect.withTracer(effect, tracer));
1239
+ }
1240
+ class Middleware extends _protos.FxBase {
1241
+ i0;
1242
+ i1;
1243
+ i2;
1244
+ constructor(i0, i1, i2) {
1245
+ super();
1246
+ this.i0 = i0;
1247
+ this.i1 = i1;
1248
+ this.i2 = i2;
1249
+ }
1250
+ run(sink) {
1251
+ return Effect.contextWithEffect(ctx => {
1252
+ const s = Sink.provide(sink, ctx);
1253
+ return this.i1(this.i0.run(this.i2 ? this.i2(s) : s));
1254
+ });
1255
+ }
1256
+ }
1257
+ function acquireUseRelease(acquire, use, release) {
1258
+ return new AcquireUseRelease(acquire, use, release);
1259
+ }
1260
+ class AcquireUseRelease extends _protos.FxBase {
1261
+ acquire;
1262
+ use;
1263
+ release;
1264
+ constructor(acquire, use, release) {
1265
+ super();
1266
+ this.acquire = acquire;
1267
+ this.use = use;
1268
+ this.release = release;
1269
+ }
1270
+ run(sink) {
1271
+ return Effect.catchAllCause(Effect.acquireUseRelease(this.acquire, a => this.use(a).run(sink), (a, exit) => Effect.catchAllCause(this.release(a, exit), cause => sink.onFailure(cause))), cause => sink.onFailure(cause));
1272
+ }
1273
+ }
1274
+ function withSpan(self, name, options = {}) {
1275
+ return acquireUseRelease(Effect.flatMap(Effect.optionFromOptional(Effect.currentSpan), parent => Effect.makeSpan(name, {
1276
+ ...options,
1277
+ parent: options?.parent || Option.getOrUndefined(parent)
1278
+ })), span => middleware(self, effect => Effect.provideService(effect, Tracer.ParentSpan, span), s => Sink.setSpan(s, span)), (span, exit) => Effect.flatMap(Clock.currentTimeNanos, time => Effect.sync(() => span.end(time, exit))));
1279
+ }
1280
+ function provideContext(fx, context) {
1281
+ return ProvideFx.make(fx, Provide.ProvideContext(context));
1282
+ }
1283
+ function provideLayer(fx, layer) {
1284
+ return ProvideFx.make(fx, Provide.ProvideLayer(layer));
1285
+ }
1286
+ function provideRuntime(fx, runtime) {
1287
+ return ProvideFx.make(fx, Provide.ProvideRuntime(runtime));
1288
+ }
1289
+ function provideService(fx, service, instance) {
1290
+ return ProvideFx.make(fx, Provide.ProvideService(service, instance));
1291
+ }
1292
+ function provideServiceEffect(fx, service, instance) {
1293
+ return ProvideFx.make(fx, Provide.ProvideServiceEffect(service, instance));
1294
+ }
1295
+ function provide(fx, provide) {
1296
+ if (Layer.isLayer(provide)) return provideLayer(fx, provide);else if (Context.isContext(provide)) return provideContext(fx, provide);else return provideRuntime(fx, provide);
1297
+ }
1298
+ class ProvideFx extends _protos.FxBase {
1299
+ i0;
1300
+ i1;
1301
+ constructor(i0, i1) {
1302
+ super();
1303
+ this.i0 = i0;
1304
+ this.i1 = i1;
1305
+ }
1306
+ run(sink) {
1307
+ return Effect.acquireUseRelease(Scope.make(), scope => Effect.matchEffect(Provide.buildWithScope(this.i1, scope), {
1308
+ onFailure: error => sink.onFailure(Cause.fail(error)),
1309
+ onSuccess: ctx => Effect.provide(this.i0.run(sink), ctx)
1310
+ }), (scope, exit) => Scope.close(scope, exit));
1311
+ }
1312
+ static make(fx, provide) {
1313
+ if (isEmpty(fx) || isNever(fx)) return fx;else if (isProvideFx(fx)) {
1314
+ return new ProvideFx(fx.i0, Provide.merge(fx.i1, provide));
1315
+ } else {
1316
+ return new ProvideFx(fx, provide);
1317
+ }
1318
+ }
1319
+ }
1320
+ function isProvideFx(u) {
1321
+ return u.constructor === ProvideFx;
1322
+ }
1323
+ function mapCause(fx, f) {
1324
+ return new TransformerCause(fx, SyncOp.Map(f));
1325
+ }
1326
+ function mapError(fx, f) {
1327
+ return mapCause(fx, Cause.map(f));
1328
+ }
1329
+ function filterCause(fx, f) {
1330
+ return new TransformerCause(fx, SyncOp.Filter(f));
1331
+ }
1332
+ function filterError(fx, f) {
1333
+ return filterCause(fx, cause => Option.match(Cause.failureOption(cause), {
1334
+ onNone: _Function.constTrue,
1335
+ onSome: f
551
1336
  }));
552
- });
553
- const dropUntil = exports.dropUntil = /*#__PURE__*/(0, _Function.dual)(2, function dropUntil(fx, predicate) {
554
- return dropWhile(fx, a => _effect.Effect.map(predicate(a), x => !x));
555
- });
556
- const dropAfter = exports.dropAfter = /*#__PURE__*/(0, _Function.dual)(2, function dropAfter(fx, predicate) {
557
- return fromSink(sink => _effect.Effect.suspend(() => {
558
- let isDropping = false;
559
- return (0, _run.run)(fx, Sink.WithContext(sink.onFailure, a => isDropping ? _effect.Effect.unit : _effect.Effect.matchCauseEffect(predicate(a), {
560
- onFailure: sink.onFailure,
561
- onSuccess: b => {
562
- if (b) {
563
- isDropping = true;
564
- return _effect.Effect.unit;
565
- } else {
566
- return sink.onSuccess(a);
567
- }
568
- }
569
- })));
1337
+ }
1338
+ function filterMapCause(fx, f) {
1339
+ return new TransformerCause(fx, SyncOp.FilterMap(f));
1340
+ }
1341
+ function filterMapError(fx, f) {
1342
+ return filterMapCause(fx, cause => Either.match(Cause.failureOrCause(cause), {
1343
+ onLeft: e => Option.map(f(e), Cause.fail),
1344
+ onRight: Option.some
570
1345
  }));
571
- });
572
- const continueWith = exports.continueWith = /*#__PURE__*/(0, _Function.dual)(2, function continueWith(fx, f) {
573
- return fromSink(sink => _effect.Effect.flatMap((0, _run.run)(fx, sink), () => (0, _run.run)(f(), sink)));
574
- });
575
- const recoverWith = exports.recoverWith = /*#__PURE__*/(0, _Function.dual)(2, function recoverWith(fx, f) {
576
- return fromSink(sink => _effect.Effect.catchAllCause(observe(fx, sink.onSuccess), cause => (0, _run.run)(from(f(cause)), sink)));
577
- });
578
- const mapEffect = exports.mapEffect = /*#__PURE__*/(0, _Function.dual)(2, function mapEffect(fx, f) {
579
- return _fxPrimitive.TransformerEffect.make(fx, (0, _effectOperator.MapEffect)(f));
580
- });
581
- const tap = exports.tap = /*#__PURE__*/(0, _Function.dual)(2, function tap(fx, f) {
582
- return _fxPrimitive.TransformerEffect.make(fx, (0, _effectOperator.TapEffect)(f));
583
- });
584
- const filterEffect = exports.filterEffect = /*#__PURE__*/(0, _Function.dual)(2, function filterEffect(fx, predicate) {
585
- return _fxPrimitive.TransformerEffect.make(fx, (0, _effectOperator.FilterEffect)(predicate));
586
- });
587
- const filterMapEffect = exports.filterMapEffect = /*#__PURE__*/(0, _Function.dual)(2, function filterEffect(fx, f) {
588
- return _fxPrimitive.TransformerEffect.make(fx, (0, _effectOperator.FilterMapEffect)(f));
589
- });
590
- const middleware = exports.middleware = /*#__PURE__*/(0, _Function.dual)(args => args.length === 3 || typeof args[0] !== "function", function middleware(fx, f, g) {
591
- return Middleware.make(fx, f, g ?? _Function.identity);
592
- });
593
- const loop = exports.loop = /*#__PURE__*/(0, _Function.dual)(3, function loop(fx, seed, f) {
594
- return Loop.make(fx, seed, f);
595
- });
596
- const loopEffect = exports.loopEffect = /*#__PURE__*/(0, _Function.dual)(3, function loopEffect(fx, seed, f) {
597
- return LoopEffect.make(fx, f, seed);
598
- });
599
- const startWith = exports.startWith = /*#__PURE__*/(0, _Function.dual)(2, function startWith(fx, value) {
600
- return fromSink(sink => _effect.Effect.flatMap(sink.onSuccess(value), () => (0, _run.run)(fx, sink)));
601
- });
602
- const endWith = exports.endWith = /*#__PURE__*/(0, _Function.dual)(2, function endWith(fx, value) {
603
- return fromSink(sink => _effect.Effect.flatMap((0, _run.run)(fx, sink), () => sink.onSuccess(value)));
604
- });
605
- const scan = exports.scan = /*#__PURE__*/(0, _Function.dual)(3, function loop(fx, seed, f) {
606
- return continueWith(new _fxPrimitive.Succeed(seed), () => Loop.make(fx, seed, (b, a) => {
607
- const b2 = f(b, a);
608
- return [b2, b2];
1346
+ }
1347
+ function mapCauseEffect(fx, f) {
1348
+ return new TransformerCause(fx, EffectOp.MapEffect(f));
1349
+ }
1350
+ function mapErrorEffect(fx, f) {
1351
+ return mapCauseEffect(fx, cause => Either.match(Cause.failureOrCause(cause), {
1352
+ onLeft: e => Effect.map(f(e), Cause.fail),
1353
+ onRight: cause => Effect.succeed(cause)
609
1354
  }));
610
- });
611
- const scanEffect = exports.scanEffect = /*#__PURE__*/(0, _Function.dual)(3, function loopEffect(fx, seed, f) {
612
- return continueWith(new _fxPrimitive.Succeed(seed), () => LoopEffect.make(fx, (b, a) => _effect.Effect.map(f(b, a), b2 => [b2, b2]), seed));
613
- });
614
- const flatMapCauseWithStrategy = exports.flatMapCauseWithStrategy = /*#__PURE__*/(0, _Function.dual)(3, function flatMapCause(fx, f, strategy) {
615
- return new _fxPrimitive.WithFlattenStrategy(({
616
- fork,
617
- sink
618
- }) => (0, _run.run)(fx, Sink.WithContext(cause => fork((0, _run.run)(from(f(cause)), sink)), sink.onSuccess)), strategy);
619
- });
620
- const flatMapErrorWithStrategy = exports.flatMapErrorWithStrategy = /*#__PURE__*/(0, _Function.dual)(3, function flatMapCause(fx, f, strategy) {
621
- return new _fxPrimitive.WithFlattenStrategy(({
622
- fork,
623
- sink
624
- }) => (0, _run.run)(fx, Sink.WithContext(cause => fork((0, _run.run)(from(cause.pipe(_effect.Cause.failureOrCause, _effect.Either.match({
1355
+ }
1356
+ function filterCauseEffect(fx, f) {
1357
+ return new TransformerCause(fx, EffectOp.FilterEffect(f));
1358
+ }
1359
+ function filterErrorEffect(fx, f) {
1360
+ return filterCauseEffect(fx, cause => Either.match(Cause.failureOrCause(cause), {
625
1361
  onLeft: f,
626
- onRight: failCause
627
- }))), sink)), sink.onSuccess)), strategy);
628
- });
629
- const flatMapCause = exports.flatMapCause = /*#__PURE__*/(0, _Function.dual)(2, function flatMapCause(fx, f) {
630
- return flatMapCauseWithStrategy(fx, f, strategies.Unbounded);
631
- });
632
- const flatMapError = exports.flatMapError = /*#__PURE__*/(0, _Function.dual)(2, function flatMapError(fx, f) {
633
- return flatMapErrorWithStrategy(fx, f, strategies.Unbounded);
634
- });
635
- const flatMapCauseConcurrently = exports.flatMapCauseConcurrently = /*#__PURE__*/(0, _Function.dual)(3, function flatMapCauseConcurrently(fx, f, concurrency) {
636
- return flatMapCauseWithStrategy(fx, f, strategies.Bounded(concurrency));
637
- });
638
- const flatMapErrorConcurrently = exports.flatMapErrorConcurrently = /*#__PURE__*/(0, _Function.dual)(3, function flatMapCauseConcurrently(fx, f, concurrency) {
639
- return flatMapErrorWithStrategy(fx, f, strategies.Bounded(concurrency));
640
- });
641
- const switchMapCause = exports.switchMapCause = /*#__PURE__*/(0, _Function.dual)(2, function switchMapCause(fx, f) {
642
- return flatMapCauseWithStrategy(fx, f, strategies.Switch);
643
- });
644
- const switchMapError = exports.switchMapError = /*#__PURE__*/(0, _Function.dual)(2, function switchMapError(fx, f) {
645
- return flatMapErrorWithStrategy(fx, f, strategies.Switch);
646
- });
647
- const exhaustMapCause = exports.exhaustMapCause = /*#__PURE__*/(0, _Function.dual)(2, function exhaustMapCause(fx, f) {
648
- return flatMapCauseWithStrategy(fx, f, strategies.Exhaust);
649
- });
650
- const exhaustMapError = exports.exhaustMapError = /*#__PURE__*/(0, _Function.dual)(2, function switchMapError(fx, f) {
651
- return flatMapErrorWithStrategy(fx, f, strategies.Exhaust);
652
- });
653
- const exhaustMapLatestCause = exports.exhaustMapLatestCause = /*#__PURE__*/(0, _Function.dual)(2, function exhaustMapLatestCause(fx, f) {
654
- return flatMapCauseWithStrategy(fx, f, strategies.ExhaustLatest);
655
- });
656
- const exhaustMapLatestError = exports.exhaustMapLatestError = /*#__PURE__*/(0, _Function.dual)(2, function switchMapError(fx, f) {
657
- return flatMapErrorWithStrategy(fx, f, strategies.ExhaustLatest);
658
- });
659
- const matchCauseWithStrategy = exports.matchCauseWithStrategy = /*#__PURE__*/(0, _Function.dual)(2, function flatMapCause(fx, options) {
660
- return new _fxPrimitive.WithFlattenStrategy(({
661
- fork,
662
- sink
663
- }) => (0, _run.run)(fx, Sink.WithContext(cause => fork((0, _run.run)(from(options.onFailure(cause)), sink)), a => fork((0, _run.run)(from(options.onSuccess(a)), sink)))), options.strategy);
664
- });
665
- const matchErrorWithStrategy = exports.matchErrorWithStrategy = /*#__PURE__*/(0, _Function.dual)(2, function flatMapCause(fx, options) {
666
- return new _fxPrimitive.WithFlattenStrategy(({
667
- fork,
668
- sink
669
- }) => (0, _run.run)(fx, Sink.WithContext(cause => fork((0, _run.run)(from(cause.pipe(_effect.Cause.failureOrCause, _effect.Either.match({
670
- onLeft: options.onFailure,
671
- onRight: failCause
672
- }))), sink)), a => fork((0, _run.run)(from(options.onSuccess(a)), sink)))), options.strategy);
673
- });
674
- const matchCause = exports.matchCause = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
675
- return matchCauseWithStrategy(fx, {
676
- ...options,
677
- strategy: strategies.Unbounded
678
- });
679
- });
680
- const match = exports.match = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
681
- return matchErrorWithStrategy(fx, {
682
- ...options,
683
- strategy: strategies.Unbounded
684
- });
685
- });
686
- const matchCauseConcurrently = exports.matchCauseConcurrently = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
687
- return matchCauseWithStrategy(fx, {
688
- onFailure: options.onFailure,
689
- onSuccess: options.onSuccess,
690
- strategy: strategies.Bounded(options.concurrency)
691
- });
692
- });
693
- const matchErrorConcurrently = exports.matchErrorConcurrently = /*#__PURE__*/(0, _Function.dual)(2, function matchErrorConcurrently(fx, options) {
694
- return matchErrorWithStrategy(fx, {
695
- ...options,
696
- strategy: strategies.Bounded(options.concurrency)
697
- });
698
- });
699
- const switchMatchCause = exports.switchMatchCause = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
700
- return matchCauseWithStrategy(fx, {
701
- ...options,
702
- strategy: strategies.Switch
703
- });
704
- });
705
- const switchMatch = exports.switchMatch = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
706
- return matchErrorWithStrategy(fx, {
707
- ...options,
708
- strategy: strategies.Switch
709
- });
710
- });
711
- const exhaustMatchCause = exports.exhaustMatchCause = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
712
- return matchCauseWithStrategy(fx, {
713
- ...options,
714
- strategy: strategies.Exhaust
715
- });
716
- });
717
- const exhaustMatch = exports.exhaustMatch = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
718
- return matchErrorWithStrategy(fx, {
719
- ...options,
720
- strategy: strategies.Exhaust
721
- });
722
- });
723
- const exhaustLatestMatchCause = exports.exhaustLatestMatchCause = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
724
- return matchCauseWithStrategy(fx, {
725
- ...options,
726
- strategy: strategies.ExhaustLatest
727
- });
728
- });
729
- const exhaustLatestMatch = exports.exhaustLatestMatch = /*#__PURE__*/(0, _Function.dual)(2, function matchCause(fx, options) {
730
- return matchErrorWithStrategy(fx, {
731
- ...options,
732
- strategy: strategies.ExhaustLatest
733
- });
734
- });
735
- const withEarlyExit = f => new _fxPrimitive.WithEarlyExit(f);
736
- exports.withEarlyExit = withEarlyExit;
737
- const withScopedFork = f => new _fxPrimitive.WithScopedFork(f);
738
- exports.withScopedFork = withScopedFork;
739
- const withFlattenStrategy = (f, strategy) => new _fxPrimitive.WithFlattenStrategy(f, strategy);
740
- exports.withFlattenStrategy = withFlattenStrategy;
741
- const during = exports.during = /*#__PURE__*/(0, _Function.dual)(2, function during(fx, window) {
742
- return withEarlyExit(({
743
- fork,
744
- sink
745
- }) => _effect.Effect.suspend(() => {
746
- let taking = false;
747
- return _effect.Effect.flatMap(fork((0, _run.run)(take(window, 1), Sink.WithContext(sink.onFailure, nested => {
748
- taking = true;
749
- return fork((0, _run.run)(take(nested, 1), Sink.WithContext(sink.onFailure, () => sink.earlyExit)));
750
- }))), () => (0, _helpers.adjustTime)(1).pipe(_effect.Effect.zipRight((0, _run.run)(fx, Sink.Sink(sink.onFailure, a => taking ? sink.onSuccess(a) : _effect.Effect.unit)))));
1362
+ onRight: () => Effect.succeed(true)
751
1363
  }));
752
- });
753
- const since = exports.since = /*#__PURE__*/(0, _Function.dual)(2, function since(fx, window) {
754
- return during(fx, map(window, () => never));
755
- });
756
- const until = exports.until = /*#__PURE__*/(0, _Function.dual)(2, function until(fx, window) {
757
- return during(fx, succeed(window));
758
- });
759
- const fromScheduled = exports.fromScheduled = /*#__PURE__*/(0, _Function.dual)(2, function fromScheduled(fx, scheduled) {
760
- return fromSink(sink => _effect.Effect.catchAllCause(_effect.Effect.repeat(_effect.Effect.matchCauseEffect(fx, sink), scheduled), sink.onFailure));
761
- });
762
- const periodic = exports.periodic = /*#__PURE__*/(0, _Function.dual)(2, function periodic(fx, duration) {
763
- return fromScheduled(fx, Schedule.spaced(duration));
764
- });
765
- const provide = exports.provide = /*#__PURE__*/(0, _Function.dual)(2, function provideContext(fx, context) {
766
- if (_effect.Layer.isLayer(context)) {
767
- return FxProvide.make(fx, Provide.ProvideLayer(context));
768
- } else if ((0, _context.isContext)(context)) {
769
- return FxProvide.make(fx, Provide.ProvideContext(context));
770
- } else {
771
- return FxProvide.make(fx, Provide.ProvideRuntime(context));
772
- }
773
- });
774
- const provideService = exports.provideService = /*#__PURE__*/(0, _Function.dual)(3, function provideService(fx, tag, service) {
775
- return FxProvide.make(fx, Provide.ProvideService(tag, service));
776
- });
777
- const provideServiceEffect = exports.provideServiceEffect = /*#__PURE__*/(0, _Function.dual)(3, function provideService(fx, tag, service) {
778
- return FxProvide.make(fx, Provide.ProvideServiceEffect(tag, service));
779
- });
780
- const skipRepeatsWith = exports.skipRepeatsWith = /*#__PURE__*/(0, _Function.dual)(2, function skipRepeatsWith(fx, eq) {
781
- return FilterMapLoop.make(fx, _effect.Option.none(), (previous, a) => _effect.Option.match(previous, {
782
- onNone: () => _effect.Option.some([a, _effect.Option.some(a)]),
783
- onSome: prev => eq(a, prev) ? _effect.Option.none() : _effect.Option.some([a, _effect.Option.some(a)])
1364
+ }
1365
+ function filterMapCauseEffect(fx, f) {
1366
+ return new TransformerCause(fx, EffectOp.FilterMapEffect(f));
1367
+ }
1368
+ function filterMapErrorEffect(fx, f) {
1369
+ return filterMapCauseEffect(fx, cause => Either.match(Cause.failureOrCause(cause), {
1370
+ onLeft: e => Effect.map(f(e), Option.map(Cause.fail)),
1371
+ onRight: cause => Effect.succeed(Option.some(cause))
784
1372
  }));
785
- });
786
- const skipRepeats = fx => skipRepeatsWith(fx, _effect.Equal.equals);
787
- exports.skipRepeats = skipRepeats;
788
- class Reduce extends _effect.Effectable.Class {
789
- fx;
790
- seed;
791
- f;
792
- constructor(fx, seed, f) {
1373
+ }
1374
+ function loopCause(fx, seed, f) {
1375
+ return new TransformerCause(fx, SyncLoopOp.LoopOperator(seed, f));
1376
+ }
1377
+ function loopError(fx, seed, f) {
1378
+ return loopCause(fx, seed, (b, cause) => Either.match(Cause.failureOrCause(cause), {
1379
+ onLeft: e => {
1380
+ const [c, b2] = f(b, e);
1381
+ return [Cause.fail(c), b2];
1382
+ },
1383
+ onRight: cause => [cause, b]
1384
+ }));
1385
+ }
1386
+ function loopCauseEffect(fx, seed, f) {
1387
+ return new TransformerCause(fx, EffectLoopOp.LoopEffectOperator(seed, f));
1388
+ }
1389
+ function loopErrorEffect(fx, seed, f) {
1390
+ return loopCauseEffect(fx, seed, (b, cause) => Either.match(Cause.failureOrCause(cause), {
1391
+ onLeft: e => Effect.map(f(b, e), ([c, b2]) => [Cause.fail(c), b2]),
1392
+ onRight: cause => Effect.succeed([cause, b])
1393
+ }));
1394
+ }
1395
+ function filterMapLoopCause(fx, seed, f) {
1396
+ return new TransformerCause(fx, SyncLoopOp.FilterMapLoopOperator(seed, f));
1397
+ }
1398
+ function filterMapLoopError(fx, seed, f) {
1399
+ return filterMapLoopCause(fx, seed, (b, cause) => Either.match(Cause.failureOrCause(cause), {
1400
+ onLeft: e => {
1401
+ const [c, b2] = f(b, e);
1402
+ return [Option.map(Cause.fail)(c), b2];
1403
+ },
1404
+ onRight: cause => [Option.some(cause), b]
1405
+ }));
1406
+ }
1407
+ function filterMapLoopCauseEffect(fx, seed, f) {
1408
+ return new TransformerCause(fx, EffectLoopOp.FilterMapLoopEffectOperator(seed, f));
1409
+ }
1410
+ function filterMapLoopErrorEffect(fx, seed, f) {
1411
+ return filterMapLoopCauseEffect(fx, seed, (b, cause) => Either.match(Cause.failureOrCause(cause), {
1412
+ onLeft: e => Effect.map(f(b, e), ([c, b2]) => [Option.map(c, Cause.fail), b2]),
1413
+ onRight: cause => Effect.succeed([Option.some(cause), b])
1414
+ }));
1415
+ }
1416
+ class TransformerCause extends _protos.FxBase {
1417
+ i0;
1418
+ i1;
1419
+ constructor(i0, i1) {
793
1420
  super();
794
- this.fx = fx;
795
- this.seed = seed;
796
- this.f = f;
1421
+ this.i0 = i0;
1422
+ this.i1 = i1;
797
1423
  }
798
- static make(fx, seed, f) {
799
- if (fx instanceof _fxPrimitive.Transformer) {
800
- return FilterMapReduce.make(fx.i0, seed, (0, _syncOperator.compileSyncReducer)(fx.i1, f));
801
- }
802
- return new Reduce(fx, seed, f);
1424
+ run(sink) {
1425
+ return this.i0.run(Op.compileOperatorSinkCause(this.i1, sink));
803
1426
  }
804
- cached = null;
805
- commit() {
806
- return this.cached ||= _effect.Effect.suspend(() => {
807
- let acc = this.seed;
808
- return _effect.Effect.map(observe(this.fx, a => _effect.Effect.sync(() => acc = this.f(acc, a))), () => acc);
809
- });
1427
+ }
1428
+ function flatMapCauseWithStrategy(fx, f, flattenStrategy, executionStrategy = ExecutionStrategy.sequential) {
1429
+ return new FlatMapCauseWithStrategy(fx, f, flattenStrategy, executionStrategy);
1430
+ }
1431
+ function flatMapErrorWithStrategy(fx, f, flattenStrategy, executionStrategy = ExecutionStrategy.sequential) {
1432
+ return flatMapCauseWithStrategy(fx, cause => Either.match(Cause.failureOrCause(cause), {
1433
+ onLeft: f,
1434
+ onRight: cause => failCause(cause)
1435
+ }), flattenStrategy, executionStrategy);
1436
+ }
1437
+ function switchMapCause(fx, f, executionStrategy) {
1438
+ return flatMapCauseWithStrategy(fx, f, _strategies.Switch, executionStrategy);
1439
+ }
1440
+ function switchMapError(fx, f, executionStrategy) {
1441
+ return flatMapErrorWithStrategy(fx, f, _strategies.Switch, executionStrategy);
1442
+ }
1443
+ function flatMapCause(fx, f, executionStrategy) {
1444
+ return flatMapCauseWithStrategy(fx, f, _strategies.Unbounded, executionStrategy);
1445
+ }
1446
+ function flatMapError(fx, f, executionStrategy) {
1447
+ return flatMapErrorWithStrategy(fx, f, _strategies.Unbounded, executionStrategy);
1448
+ }
1449
+ function flatMapCauseConcurrently(fx, f, concurrency, executionStrategy) {
1450
+ return flatMapCauseWithStrategy(fx, f, (0, _strategies.Bounded)(concurrency), executionStrategy);
1451
+ }
1452
+ function flatMapErrorConcurrently(fx, f, concurrency, executionStrategy) {
1453
+ return flatMapErrorWithStrategy(fx, f, (0, _strategies.Bounded)(concurrency), executionStrategy);
1454
+ }
1455
+ function exhaustMapCause(fx, f, executionStrategy) {
1456
+ return flatMapCauseWithStrategy(fx, f, _strategies.Exhaust, executionStrategy);
1457
+ }
1458
+ function exhaustMapError(fx, f, executionStrategy) {
1459
+ return flatMapErrorWithStrategy(fx, f, _strategies.Exhaust, executionStrategy);
1460
+ }
1461
+ function exhaustMapLatestCause(fx, f, executionStrategy) {
1462
+ return flatMapCauseWithStrategy(fx, f, _strategies.ExhaustLatest, executionStrategy);
1463
+ }
1464
+ function exhaustMapLatestError(fx, f, executionStrategy) {
1465
+ return flatMapErrorWithStrategy(fx, f, _strategies.ExhaustLatest, executionStrategy);
1466
+ }
1467
+ class FlatMapCauseWithStrategy extends _protos.FxBase {
1468
+ i0;
1469
+ i1;
1470
+ i2;
1471
+ i3;
1472
+ withFork;
1473
+ constructor(i0, i1, i2, i3) {
1474
+ super();
1475
+ this.i0 = i0;
1476
+ this.i1 = i1;
1477
+ this.i2 = i2;
1478
+ this.i3 = i3;
1479
+ this.withFork = (0, _helpers.withFlattenStrategy)(this.i2);
1480
+ }
1481
+ run(sink) {
1482
+ return this.withFork(fork => this.i0.run(Sink.make(cause => fork(this.i1(cause).run(sink)), a => sink.onSuccess(a))), this.i3);
810
1483
  }
811
1484
  }
812
- class FilterMapReduce extends _effect.Effectable.Class {
1485
+ class MatchWithStrategy extends _protos.FxBase {
813
1486
  i0;
814
1487
  i1;
815
1488
  i2;
816
- constructor(i0, i1, i2) {
1489
+ i3;
1490
+ i4;
1491
+ withFork;
1492
+ constructor(i0, i1, i2, i3, i4) {
817
1493
  super();
818
1494
  this.i0 = i0;
819
1495
  this.i1 = i1;
820
1496
  this.i2 = i2;
1497
+ this.i3 = i3;
1498
+ this.i4 = i4;
1499
+ this.withFork = (0, _helpers.withFlattenStrategy)(this.i3);
821
1500
  }
822
- static make(fx, seed, f) {
823
- if (fx instanceof _fxPrimitive.FromIterable) {
824
- if (Array.isArray(fx.i0)) {
825
- return new _protos.OnceEffect(_effect.Effect.sync(() => reduceFilterArray(fx.i0, seed, f)));
826
- } else {
827
- return _effect.Effect.sync(() => reduceFilterIterable(fx.i0, seed, f));
828
- }
829
- }
830
- return new FilterMapReduce(fx, seed, f);
1501
+ run(sink) {
1502
+ return this.withFork(fork => this.i0.run(Sink.make(cause => fork(this.i1(cause).run(sink)), a => fork(this.i2(a).run(sink)))), this.i4);
831
1503
  }
832
- cached = null;
833
- commit() {
834
- return this.cached ||= _effect.Effect.suspend(() => {
835
- let acc = this.i1;
836
- return _effect.Effect.map(observe(this.i0, a => _effect.Option.match(this.i2(acc, a), {
837
- onNone: () => _effect.Effect.unit,
838
- onSome: b => _effect.Effect.succeed(acc = b)
839
- })), () => acc);
1504
+ }
1505
+ function matchCauseWithStrategy(fx, flattenStrategy, opts) {
1506
+ return new MatchWithStrategy(fx, opts.onFailure, opts.onSuccess, flattenStrategy, opts.executionStrategy || ExecutionStrategy.sequential);
1507
+ }
1508
+ function matchErrorWithStrategy(fx, flattenStrategy, {
1509
+ executionStrategy,
1510
+ onFailure,
1511
+ onSuccess
1512
+ }) {
1513
+ return new MatchWithStrategy(fx, cause => Either.match(Cause.failureOrCause(cause), {
1514
+ onLeft: onFailure,
1515
+ onRight: cause => failCause(cause)
1516
+ }), onSuccess, flattenStrategy, executionStrategy || ExecutionStrategy.sequential);
1517
+ }
1518
+ function matchCause(fx, opts) {
1519
+ return matchCauseWithStrategy(fx, _strategies.Unbounded, opts);
1520
+ }
1521
+ function matchError(fx, opts) {
1522
+ return matchErrorWithStrategy(fx, _strategies.Unbounded, opts);
1523
+ }
1524
+ function matchCauseConcurrently(fx, concurrency, opts) {
1525
+ return matchCauseWithStrategy(fx, (0, _strategies.Bounded)(concurrency), opts);
1526
+ }
1527
+ function matchErrorConcurrently(fx, concurrency, opts) {
1528
+ return matchErrorWithStrategy(fx, (0, _strategies.Bounded)(concurrency), opts);
1529
+ }
1530
+ function switchMatchCause(fx, opts) {
1531
+ return matchCauseWithStrategy(fx, _strategies.Switch, opts);
1532
+ }
1533
+ function switchMatchError(fx, opts) {
1534
+ return matchErrorWithStrategy(fx, _strategies.Switch, opts);
1535
+ }
1536
+ function exhaustMatchCause(fx, opts) {
1537
+ return matchCauseWithStrategy(fx, _strategies.Exhaust, opts);
1538
+ }
1539
+ function exhaustMatchError(fx, opts) {
1540
+ return matchErrorWithStrategy(fx, _strategies.Exhaust, opts);
1541
+ }
1542
+ function exhaustMatchLatestCause(fx, opts) {
1543
+ return matchCauseWithStrategy(fx, _strategies.ExhaustLatest, opts);
1544
+ }
1545
+ function exhaustMatchLatestError(fx, opts) {
1546
+ return matchErrorWithStrategy(fx, _strategies.ExhaustLatest, opts);
1547
+ }
1548
+ function tuple(fx) {
1549
+ return new Tuple(fx);
1550
+ }
1551
+ class Tuple extends _protos.FxBase {
1552
+ i0;
1553
+ constructor(i0) {
1554
+ super();
1555
+ this.i0 = i0;
1556
+ }
1557
+ run(sink) {
1558
+ return (0, _helpers.tupleSink)(sink, onSuccess => Effect.forEach(this.i0, (fx, i) => fx.run(Sink.make(sink.onFailure, a => onSuccess(i, a))), UNBOUNDED), this.i0.length);
1559
+ }
1560
+ }
1561
+ function struct(fx) {
1562
+ const entries = Object.entries(fx);
1563
+ return map(tuple(entries.map(([key, fx]) => map(fx, a => [key, a]))), Object.fromEntries);
1564
+ }
1565
+ function all(fx) {
1566
+ if (Array.isArray(fx)) return tuple(fx);else return struct(fx);
1567
+ }
1568
+ function exit(fx) {
1569
+ return new ExitFx(fx);
1570
+ }
1571
+ class ExitFx extends _protos.FxBase {
1572
+ i0;
1573
+ constructor(i0) {
1574
+ super();
1575
+ this.i0 = i0;
1576
+ }
1577
+ run(sink) {
1578
+ return this.i0.run(Sink.make(cause => sink.onSuccess(Exit.failCause(cause)), a => sink.onSuccess(Exit.succeed(a))));
1579
+ }
1580
+ }
1581
+ function toEnqueue(fx, queue) {
1582
+ return observe(fx, a => queue.offer(a));
1583
+ }
1584
+ function debounce(fx, delay) {
1585
+ return switchMapEffect(fx, a => Effect.as(Effect.sleep(delay), a));
1586
+ }
1587
+ function throttle(fx, delay) {
1588
+ return exhaustMapEffect(fx, a => Effect.as(Effect.sleep(delay), a));
1589
+ }
1590
+ function throttleLatest(fx, delay) {
1591
+ return exhaustMapLatestEffect(fx, a => Effect.as(Effect.sleep(delay), a));
1592
+ }
1593
+ function fromAsyncIterable(iterable) {
1594
+ return new FromAsyncIterable(iterable);
1595
+ }
1596
+ class FromAsyncIterable extends _protos.FxBase {
1597
+ i0;
1598
+ constructor(i0) {
1599
+ super();
1600
+ this.i0 = i0;
1601
+ }
1602
+ run(sink) {
1603
+ return Effect.asyncEffect(cb => {
1604
+ const iterator = this.i0[Symbol.asyncIterator]();
1605
+ const loop = result => result.done ? Effect.sync(() => cb(Effect.unit)) : Effect.zipRight(sink.onSuccess(result.value), Effect.flatMap(Effect.promise(() => iterator.next()), loop));
1606
+ return Effect.flatMap(Effect.promise(() => iterator.next()), loop);
840
1607
  });
841
1608
  }
842
1609
  }
843
- function reduceFilterIterable(iterable, seed, f) {
844
- const iterator = iterable[Symbol.iterator]();
845
- let acc = seed;
846
- let result = iterator.next();
847
- let option = _effect.Option.none();
848
- while (!result.done) {
849
- option = f(acc, result.value);
850
- if (_effect.Option.isSome(option)) {
851
- acc = option.value;
852
- }
853
- result = iterator.next();
854
- }
855
- return acc;
856
- }
857
- function reduceFilterArray(iterable, seed, f) {
858
- const length = iterable.length;
859
- let acc = seed;
860
- let option = _effect.Option.none();
861
- for (let i = 0; i < length; i++) {
862
- option = f(acc, iterable[i]);
863
- if (_effect.Option.isSome(option)) {
864
- acc = option.value;
865
- }
1610
+ function findFirst(fx, predicate) {
1611
+ return Effect.asyncEffect(cb => observe(fx, a => predicate(a) ? Effect.sync(() => cb(Effect.succeed(a))) : Effect.unit));
1612
+ }
1613
+ function first(fx) {
1614
+ return findFirst(fx, _Function.constTrue);
1615
+ }
1616
+ function either(fx) {
1617
+ return new EitherFx(fx);
1618
+ }
1619
+ class EitherFx extends _protos.FxBase {
1620
+ i0;
1621
+ constructor(i0) {
1622
+ super();
1623
+ this.i0 = i0;
1624
+ }
1625
+ run(sink) {
1626
+ return this.i0.run(Sink.make(cause => Either.match(Cause.failureOrCause(cause), {
1627
+ onLeft: e => sink.onSuccess(Either.left(e)),
1628
+ onRight: cause => sink.onFailure(cause)
1629
+ }), a => sink.onSuccess(Either.right(a))));
866
1630
  }
867
- return acc;
868
1631
  }
869
- const reduce = exports.reduce = /*#__PURE__*/(0, _Function.dual)(3, function reduce(fx, seed, f) {
870
- return Reduce.make(fx, seed, f);
871
- });
872
- function toChunk(fx) {
873
- return reduce(fx, _effect.Chunk.empty(), _effect.Chunk.append);
1632
+ function mergeFirst(fx, that) {
1633
+ return merge(fx, filter(that, _Function.constFalse));
874
1634
  }
875
- const snapshot = exports.snapshot = /*#__PURE__*/(0, _Function.dual)(3, function snapshot(fx, sampled, f) {
1635
+ function mergeRace(fx, that) {
1636
+ return new MergeRace(fx, that);
1637
+ }
1638
+ class MergeRace extends _protos.FxBase {
1639
+ i0;
1640
+ i1;
1641
+ constructor(i0, i1) {
1642
+ super();
1643
+ this.i0 = i0;
1644
+ this.i1 = i1;
1645
+ }
1646
+ run(sink) {
1647
+ return Effect.gen(this, function* (_) {
1648
+ const fiber1 = yield* _(Effect.fork(this.i0.run(Sink.make(sink.onFailure, a => Effect.flatMap(sink.onSuccess(a), () => Fiber.interrupt(fiber2))))));
1649
+ const fiber2 = yield* _(Effect.fork(this.i1.run(sink)));
1650
+ return yield* _(Fiber.joinAll([fiber1, fiber2]));
1651
+ });
1652
+ }
1653
+ }
1654
+ function raceAll(fx) {
1655
+ return new RaceAll(fx);
1656
+ }
1657
+ function race(fx, that) {
1658
+ return raceAll([fx, that]);
1659
+ }
1660
+ class RaceAll extends _protos.FxBase {
1661
+ i0;
1662
+ constructor(i0) {
1663
+ super();
1664
+ this.i0 = i0;
1665
+ }
1666
+ run(sink) {
1667
+ return Effect.gen(this, function* (_) {
1668
+ const winner = yield* _(Deferred.make());
1669
+ const fibers = [];
1670
+ for (const fx of this.i0) {
1671
+ const fiber = yield* _(Effect.fork(fx.run(Sink.make(sink.onFailure, a => Effect.flatMap(Deferred.succeed(winner, fiber), () => sink.onSuccess(a))))));
1672
+ fibers.push(fiber);
1673
+ }
1674
+ const winningFiber = yield* _(Deferred.await(winner));
1675
+ yield* _(Fiber.interruptAll(fibers.filter(x => x !== winningFiber)));
1676
+ return yield* _(Fiber.join(winningFiber));
1677
+ });
1678
+ }
1679
+ }
1680
+ function snapshot(fx, sampled, f) {
876
1681
  return new Snapshot(fx, sampled, f);
877
- });
878
- function fromEmitter(f) {
879
- return withEarlyExit(({
880
- scope,
881
- sink
882
- }) => _effect.Effect.zipRight(_effect.Effect.provideService(_effect.Effect.flatMap(Emitter.make(sink), f), _effect.Scope.Scope, scope), _effect.Effect.never));
883
- }
884
- function fromEffect(effect) {
885
- return (0, _effectPrimitive.matchEffectPrimitive)(effect, {
886
- Success: e => succeed(e.i0),
887
- Failure: e => failCause(e.i0),
888
- Left: e => fail(e.left),
889
- Right: e => succeed(e.right),
890
- None: () => fail(new _effect.Cause.NoSuchElementException()),
891
- Some: e => succeed(e.value),
892
- Sync: e => sync(e.i0),
893
- Otherwise: () => fromSink(sink => _effect.Effect.matchCauseEffect(effect, sink))
1682
+ }
1683
+ function sample(fx, sampled) {
1684
+ return snapshot(fx, sampled, (_, b) => b);
1685
+ }
1686
+ class Snapshot extends _protos.FxBase {
1687
+ i0;
1688
+ i1;
1689
+ i2;
1690
+ constructor(i0, i1, i2) {
1691
+ super();
1692
+ this.i0 = i0;
1693
+ this.i1 = i1;
1694
+ this.i2 = i2;
1695
+ }
1696
+ run(sink) {
1697
+ return Effect.flatMap(Ref.make(Option.none()), ref => Effect.all([this.i1.run(Sink.make(sink.onFailure, b => Ref.set(ref, Option.some(b)))), this.i0.run(Sink.make(sink.onFailure, a => Effect.flatMap(Ref.get(ref), Option.match({
1698
+ onNone: () => Effect.unit,
1699
+ onSome: b => sink.onSuccess(this.i2(a, b))
1700
+ }))))], UNBOUNDED));
1701
+ }
1702
+ }
1703
+ function snapshotEffect(fx, sampled, f) {
1704
+ return new SnapshotEffect(fx, sampled, f);
1705
+ }
1706
+ class SnapshotEffect extends _protos.FxBase {
1707
+ i0;
1708
+ i1;
1709
+ i2;
1710
+ constructor(i0, i1, i2) {
1711
+ super();
1712
+ this.i0 = i0;
1713
+ this.i1 = i1;
1714
+ this.i2 = i2;
1715
+ }
1716
+ run(sink) {
1717
+ return Effect.flatMap(Ref.make(Option.none()), ref => Effect.flatMap(Effect.tap(Effect.fork(this.i1.run(Sink.make(sink.onFailure, b => Ref.set(ref, Option.some(b))))), () => this.i0.run(Sink.make(sink.onFailure, a => Effect.flatMap(Ref.get(ref), Option.match({
1718
+ onNone: () => Effect.unit,
1719
+ onSome: b => Effect.matchCauseEffect(this.i2(a, b), sink)
1720
+ }))))), Fiber.interrupt));
1721
+ }
1722
+ }
1723
+ function if_(bool, options) {
1724
+ return switchMap(bool, b => b ? options.onTrue : options.onFalse);
1725
+ }
1726
+ function when(bool, options) {
1727
+ return if_(bool, {
1728
+ onTrue: succeed(options.onTrue),
1729
+ onFalse: succeed(options.onFalse)
894
1730
  });
895
1731
  }
896
- function fromStream(stream, options) {
897
- return fromSink(sink => _effect.Effect.acquireUseRelease(_effect.Scope.make(), scope => _effect.Effect.gen(function* (_) {
898
- const pull = _effect.Effect.either(yield* _(_effect.Stream.toPull(stream), _effect.Effect.provideService(_effect.Scope.Scope, scope)));
899
- while (true) {
900
- const either = yield* _(pull);
901
- if (_effect.Either.isRight(either)) {
902
- yield* _(_effect.Effect.forEach(either.right, sink.onSuccess));
903
- } else if (_effect.Option.isNone(either.left)) {
904
- return;
905
- } else {
906
- yield* _(sink.onFailure(_effect.Cause.fail(either.left.value)));
907
- }
908
- // Schedule subsequent pulls using the current scheduler.
909
- yield* _(_effect.Effect.yieldNow(options));
910
- }
911
- }), _effect.Scope.close));
912
- }
913
- const matchers = {
914
- RefSubject: _Function.identity,
915
- Fx: _Function.identity,
916
- Effect: fromEffect,
917
- Cause: failCause,
918
- Iterable: fromIterable,
919
- Otherwise: succeed
920
- };
921
- function from(input) {
922
- return (0, _matchers.matchFxInput)(input, matchers);
1732
+ function mapBoth(fx, f, g) {
1733
+ return map(mapError(fx, f), g);
923
1734
  }
924
1735
  //# sourceMappingURL=core.js.map