@typed/fx 2.0.0-beta.0 → 2.0.0-beta.10

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 (640) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +58 -21
  3. package/dist/Fx/Fx.d.ts +371 -19
  4. package/dist/Fx/Fx.d.ts.map +1 -1
  5. package/dist/Fx/Fx.js +37 -6
  6. package/dist/Fx/TypeId.d.ts +52 -6
  7. package/dist/Fx/TypeId.d.ts.map +1 -1
  8. package/dist/Fx/TypeId.js +41 -4
  9. package/dist/Fx/combinators/additive.d.ts +245 -0
  10. package/dist/Fx/combinators/additive.d.ts.map +1 -0
  11. package/dist/Fx/combinators/additive.js +243 -0
  12. package/dist/Fx/combinators/catch.d.ts +246 -12
  13. package/dist/Fx/combinators/catch.d.ts.map +1 -1
  14. package/dist/Fx/combinators/catch.js +236 -12
  15. package/dist/Fx/combinators/causes.d.ts +25 -2
  16. package/dist/Fx/combinators/causes.d.ts.map +1 -1
  17. package/dist/Fx/combinators/causes.js +25 -2
  18. package/dist/Fx/combinators/changesWithEffect.d.ts +40 -0
  19. package/dist/Fx/combinators/changesWithEffect.d.ts.map +1 -0
  20. package/dist/Fx/combinators/changesWithEffect.js +48 -0
  21. package/dist/Fx/combinators/compact.d.ts +18 -1
  22. package/dist/Fx/combinators/compact.d.ts.map +1 -1
  23. package/dist/Fx/combinators/compact.js +18 -1
  24. package/dist/Fx/combinators/concatMap.d.ts +86 -0
  25. package/dist/Fx/combinators/concatMap.d.ts.map +1 -0
  26. package/dist/Fx/combinators/concatMap.js +86 -0
  27. package/dist/Fx/combinators/continueWith.d.ts +113 -5
  28. package/dist/Fx/combinators/continueWith.d.ts.map +1 -1
  29. package/dist/Fx/combinators/continueWith.js +113 -5
  30. package/dist/Fx/combinators/debounce.d.ts +34 -0
  31. package/dist/Fx/combinators/debounce.d.ts.map +1 -0
  32. package/dist/Fx/combinators/debounce.js +35 -0
  33. package/dist/Fx/combinators/delay.d.ts +36 -0
  34. package/dist/Fx/combinators/delay.d.ts.map +1 -0
  35. package/dist/Fx/combinators/delay.js +33 -0
  36. package/dist/Fx/combinators/dropUntil.d.ts +71 -0
  37. package/dist/Fx/combinators/dropUntil.d.ts.map +1 -0
  38. package/dist/Fx/combinators/dropUntil.js +65 -0
  39. package/dist/Fx/combinators/during.d.ts +38 -0
  40. package/dist/Fx/combinators/during.d.ts.map +1 -0
  41. package/dist/Fx/combinators/during.js +85 -0
  42. package/dist/Fx/combinators/ensuring.d.ts +34 -4
  43. package/dist/Fx/combinators/ensuring.d.ts.map +1 -1
  44. package/dist/Fx/combinators/ensuring.js +34 -4
  45. package/dist/Fx/combinators/exhaustLatestMap.d.ts +41 -5
  46. package/dist/Fx/combinators/exhaustLatestMap.d.ts.map +1 -1
  47. package/dist/Fx/combinators/exhaustLatestMap.js +41 -5
  48. package/dist/Fx/combinators/exhaustLatestMapEffect.d.ts +40 -4
  49. package/dist/Fx/combinators/exhaustLatestMapEffect.d.ts.map +1 -1
  50. package/dist/Fx/combinators/exhaustLatestMapEffect.js +40 -4
  51. package/dist/Fx/combinators/exhaustMap.d.ts +38 -1
  52. package/dist/Fx/combinators/exhaustMap.d.ts.map +1 -1
  53. package/dist/Fx/combinators/exhaustMap.js +38 -1
  54. package/dist/Fx/combinators/exhaustMapEffect.d.ts +33 -1
  55. package/dist/Fx/combinators/exhaustMapEffect.d.ts.map +1 -1
  56. package/dist/Fx/combinators/exhaustMapEffect.js +33 -1
  57. package/dist/Fx/combinators/exit.d.ts +23 -2
  58. package/dist/Fx/combinators/exit.d.ts.map +1 -1
  59. package/dist/Fx/combinators/exit.js +23 -2
  60. package/dist/Fx/combinators/filter.d.ts +17 -1
  61. package/dist/Fx/combinators/filter.d.ts.map +1 -1
  62. package/dist/Fx/combinators/filter.js +17 -1
  63. package/dist/Fx/combinators/filterEffect.d.ts +22 -1
  64. package/dist/Fx/combinators/filterEffect.d.ts.map +1 -1
  65. package/dist/Fx/combinators/filterEffect.js +22 -1
  66. package/dist/Fx/combinators/filterMap.d.ts +20 -1
  67. package/dist/Fx/combinators/filterMap.d.ts.map +1 -1
  68. package/dist/Fx/combinators/filterMap.js +20 -1
  69. package/dist/Fx/combinators/filterMapEffect.d.ts +21 -1
  70. package/dist/Fx/combinators/filterMapEffect.d.ts.map +1 -1
  71. package/dist/Fx/combinators/filterMapEffect.js +21 -1
  72. package/dist/Fx/combinators/filterMapLoop.d.ts +20 -1
  73. package/dist/Fx/combinators/filterMapLoop.d.ts.map +1 -1
  74. package/dist/Fx/combinators/filterMapLoop.js +20 -1
  75. package/dist/Fx/combinators/filterMapLoopCause.d.ts +21 -1
  76. package/dist/Fx/combinators/filterMapLoopCause.d.ts.map +1 -1
  77. package/dist/Fx/combinators/filterMapLoopCause.js +21 -1
  78. package/dist/Fx/combinators/filterMapLoopCauseEffect.d.ts +21 -1
  79. package/dist/Fx/combinators/filterMapLoopCauseEffect.d.ts.map +1 -1
  80. package/dist/Fx/combinators/filterMapLoopCauseEffect.js +21 -1
  81. package/dist/Fx/combinators/filterMapLoopEffect.d.ts +21 -1
  82. package/dist/Fx/combinators/filterMapLoopEffect.d.ts.map +1 -1
  83. package/dist/Fx/combinators/filterMapLoopEffect.js +21 -1
  84. package/dist/Fx/combinators/flatMap.d.ts +50 -5
  85. package/dist/Fx/combinators/flatMap.d.ts.map +1 -1
  86. package/dist/Fx/combinators/flatMap.js +36 -3
  87. package/dist/Fx/combinators/flatMapConcurrently.d.ts +51 -4
  88. package/dist/Fx/combinators/flatMapConcurrently.d.ts.map +1 -1
  89. package/dist/Fx/combinators/flatMapConcurrently.js +51 -4
  90. package/dist/Fx/combinators/flatMapConcurrentlyEffect.d.ts +48 -4
  91. package/dist/Fx/combinators/flatMapConcurrentlyEffect.d.ts.map +1 -1
  92. package/dist/Fx/combinators/flatMapConcurrentlyEffect.js +40 -2
  93. package/dist/Fx/combinators/flatMapEffect.d.ts +46 -4
  94. package/dist/Fx/combinators/flatMapEffect.d.ts.map +1 -1
  95. package/dist/Fx/combinators/flatMapEffect.js +32 -2
  96. package/dist/Fx/combinators/flip.d.ts +34 -2
  97. package/dist/Fx/combinators/flip.d.ts.map +1 -1
  98. package/dist/Fx/combinators/flip.js +34 -2
  99. package/dist/Fx/combinators/gen.d.ts +29 -10
  100. package/dist/Fx/combinators/gen.d.ts.map +1 -1
  101. package/dist/Fx/combinators/gen.js +28 -4
  102. package/dist/Fx/combinators/genScoped.d.ts +33 -10
  103. package/dist/Fx/combinators/genScoped.d.ts.map +1 -1
  104. package/dist/Fx/combinators/genScoped.js +31 -3
  105. package/dist/Fx/combinators/grouped.d.ts +89 -0
  106. package/dist/Fx/combinators/grouped.d.ts.map +1 -0
  107. package/dist/Fx/combinators/grouped.js +146 -0
  108. package/dist/Fx/combinators/index.d.ts +45 -0
  109. package/dist/Fx/combinators/index.d.ts.map +1 -1
  110. package/dist/Fx/combinators/index.js +45 -0
  111. package/dist/Fx/combinators/keyed.d.ts +124 -10
  112. package/dist/Fx/combinators/keyed.d.ts.map +1 -1
  113. package/dist/Fx/combinators/keyed.js +69 -11
  114. package/dist/Fx/combinators/loop.d.ts +17 -1
  115. package/dist/Fx/combinators/loop.d.ts.map +1 -1
  116. package/dist/Fx/combinators/loop.js +17 -1
  117. package/dist/Fx/combinators/loopCause.d.ts +18 -1
  118. package/dist/Fx/combinators/loopCause.d.ts.map +1 -1
  119. package/dist/Fx/combinators/loopCause.js +18 -1
  120. package/dist/Fx/combinators/loopCauseEffect.d.ts +19 -1
  121. package/dist/Fx/combinators/loopCauseEffect.d.ts.map +1 -1
  122. package/dist/Fx/combinators/loopCauseEffect.js +19 -1
  123. package/dist/Fx/combinators/loopEffect.d.ts +24 -1
  124. package/dist/Fx/combinators/loopEffect.d.ts.map +1 -1
  125. package/dist/Fx/combinators/loopEffect.js +24 -1
  126. package/dist/Fx/combinators/map.d.ts +46 -1
  127. package/dist/Fx/combinators/map.d.ts.map +1 -1
  128. package/dist/Fx/combinators/map.js +43 -1
  129. package/dist/Fx/combinators/mapBoth.d.ts +40 -0
  130. package/dist/Fx/combinators/mapBoth.d.ts.map +1 -0
  131. package/dist/Fx/combinators/mapBoth.js +33 -0
  132. package/dist/Fx/combinators/mapEffect.d.ts +25 -1
  133. package/dist/Fx/combinators/mapEffect.d.ts.map +1 -1
  134. package/dist/Fx/combinators/mapEffect.js +25 -1
  135. package/dist/Fx/combinators/mapError.d.ts +33 -0
  136. package/dist/Fx/combinators/mapError.d.ts.map +1 -0
  137. package/dist/Fx/combinators/mapError.js +32 -0
  138. package/dist/Fx/combinators/mergeAll.d.ts +35 -1
  139. package/dist/Fx/combinators/mergeAll.d.ts.map +1 -1
  140. package/dist/Fx/combinators/mergeAll.js +35 -1
  141. package/dist/Fx/combinators/mergeOrdered.d.ts +36 -4
  142. package/dist/Fx/combinators/mergeOrdered.d.ts.map +1 -1
  143. package/dist/Fx/combinators/mergeOrdered.js +68 -14
  144. package/dist/Fx/combinators/onError.d.ts +34 -4
  145. package/dist/Fx/combinators/onError.d.ts.map +1 -1
  146. package/dist/Fx/combinators/onError.js +34 -4
  147. package/dist/Fx/combinators/onExit.d.ts +29 -3
  148. package/dist/Fx/combinators/onExit.d.ts.map +1 -1
  149. package/dist/Fx/combinators/onExit.js +29 -3
  150. package/dist/Fx/combinators/onInterrupt.d.ts +49 -4
  151. package/dist/Fx/combinators/onInterrupt.d.ts.map +1 -1
  152. package/dist/Fx/combinators/onInterrupt.js +49 -4
  153. package/dist/Fx/combinators/pairwise.d.ts +28 -0
  154. package/dist/Fx/combinators/pairwise.d.ts.map +1 -0
  155. package/dist/Fx/combinators/pairwise.js +31 -0
  156. package/dist/Fx/combinators/provide.d.ts +162 -8
  157. package/dist/Fx/combinators/provide.d.ts.map +1 -1
  158. package/dist/Fx/combinators/provide.js +154 -6
  159. package/dist/Fx/combinators/race.d.ts +92 -0
  160. package/dist/Fx/combinators/race.d.ts.map +1 -0
  161. package/dist/Fx/combinators/race.js +149 -0
  162. package/dist/Fx/combinators/repeat.d.ts +41 -0
  163. package/dist/Fx/combinators/repeat.d.ts.map +1 -0
  164. package/dist/Fx/combinators/repeat.js +57 -0
  165. package/dist/Fx/combinators/result.d.ts +45 -0
  166. package/dist/Fx/combinators/result.d.ts.map +1 -0
  167. package/dist/Fx/combinators/result.js +46 -0
  168. package/dist/Fx/combinators/retry.d.ts +53 -0
  169. package/dist/Fx/combinators/retry.d.ts.map +1 -0
  170. package/dist/Fx/combinators/retry.js +71 -0
  171. package/dist/Fx/combinators/sample.d.ts +31 -0
  172. package/dist/Fx/combinators/sample.d.ts.map +1 -0
  173. package/dist/Fx/combinators/sample.js +42 -0
  174. package/dist/Fx/combinators/scan.d.ts +72 -0
  175. package/dist/Fx/combinators/scan.d.ts.map +1 -0
  176. package/dist/Fx/combinators/scan.js +77 -0
  177. package/dist/Fx/combinators/since.d.ts +30 -0
  178. package/dist/Fx/combinators/since.d.ts.map +1 -0
  179. package/dist/Fx/combinators/since.js +39 -0
  180. package/dist/Fx/combinators/skip.d.ts +45 -1
  181. package/dist/Fx/combinators/skip.d.ts.map +1 -1
  182. package/dist/Fx/combinators/skip.js +43 -1
  183. package/dist/Fx/combinators/skipRepeats.d.ts +17 -1
  184. package/dist/Fx/combinators/skipRepeats.d.ts.map +1 -1
  185. package/dist/Fx/combinators/skipRepeats.js +17 -1
  186. package/dist/Fx/combinators/skipRepeatsWith.d.ts +18 -1
  187. package/dist/Fx/combinators/skipRepeatsWith.d.ts.map +1 -1
  188. package/dist/Fx/combinators/skipRepeatsWith.js +18 -1
  189. package/dist/Fx/combinators/skipWhile.d.ts +117 -0
  190. package/dist/Fx/combinators/skipWhile.d.ts.map +1 -0
  191. package/dist/Fx/combinators/skipWhile.js +134 -0
  192. package/dist/Fx/combinators/slice.d.ts +97 -2
  193. package/dist/Fx/combinators/slice.d.ts.map +1 -1
  194. package/dist/Fx/combinators/slice.js +45 -1
  195. package/dist/Fx/combinators/switchMap.d.ts +39 -1
  196. package/dist/Fx/combinators/switchMap.d.ts.map +1 -1
  197. package/dist/Fx/combinators/switchMap.js +43 -5
  198. package/dist/Fx/combinators/switchMapEffect.d.ts +38 -1
  199. package/dist/Fx/combinators/switchMapEffect.d.ts.map +1 -1
  200. package/dist/Fx/combinators/switchMapEffect.js +38 -1
  201. package/dist/Fx/combinators/take.d.ts +46 -1
  202. package/dist/Fx/combinators/take.d.ts.map +1 -1
  203. package/dist/Fx/combinators/take.js +44 -1
  204. package/dist/Fx/combinators/takeUntil.d.ts +62 -2
  205. package/dist/Fx/combinators/takeUntil.d.ts.map +1 -1
  206. package/dist/Fx/combinators/takeUntil.js +62 -2
  207. package/dist/Fx/combinators/takeWhile.d.ts +60 -0
  208. package/dist/Fx/combinators/takeWhile.d.ts.map +1 -0
  209. package/dist/Fx/combinators/takeWhile.js +54 -0
  210. package/dist/Fx/combinators/tapEffect.d.ts +17 -1
  211. package/dist/Fx/combinators/tapEffect.d.ts.map +1 -1
  212. package/dist/Fx/combinators/tapEffect.js +17 -1
  213. package/dist/Fx/combinators/throttle.d.ts +79 -0
  214. package/dist/Fx/combinators/throttle.d.ts.map +1 -0
  215. package/dist/Fx/combinators/throttle.js +99 -0
  216. package/dist/Fx/combinators/timeout.d.ts +76 -0
  217. package/dist/Fx/combinators/timeout.d.ts.map +1 -0
  218. package/dist/Fx/combinators/timeout.js +110 -0
  219. package/dist/Fx/combinators/tuple.d.ts +32 -2
  220. package/dist/Fx/combinators/tuple.d.ts.map +1 -1
  221. package/dist/Fx/combinators/tuple.js +36 -5
  222. package/dist/Fx/combinators/until.d.ts +27 -0
  223. package/dist/Fx/combinators/until.d.ts.map +1 -0
  224. package/dist/Fx/combinators/until.js +56 -0
  225. package/dist/Fx/combinators/unwrap.d.ts +31 -2
  226. package/dist/Fx/combinators/unwrap.d.ts.map +1 -1
  227. package/dist/Fx/combinators/unwrap.js +30 -1
  228. package/dist/Fx/combinators/unwrapScoped.d.ts +34 -1
  229. package/dist/Fx/combinators/unwrapScoped.d.ts.map +1 -1
  230. package/dist/Fx/combinators/unwrapScoped.js +34 -1
  231. package/dist/Fx/combinators/when.d.ts +37 -2
  232. package/dist/Fx/combinators/when.d.ts.map +1 -1
  233. package/dist/Fx/combinators/when.js +38 -3
  234. package/dist/Fx/combinators/withLatestFrom.d.ts +58 -0
  235. package/dist/Fx/combinators/withLatestFrom.d.ts.map +1 -0
  236. package/dist/Fx/combinators/withLatestFrom.js +68 -0
  237. package/dist/Fx/combinators/withSpan.d.ts +35 -1
  238. package/dist/Fx/combinators/withSpan.d.ts.map +1 -1
  239. package/dist/Fx/combinators/withSpan.js +34 -3
  240. package/dist/Fx/combinators/zip.d.ts +135 -0
  241. package/dist/Fx/combinators/zip.d.ts.map +1 -0
  242. package/dist/Fx/combinators/zip.js +160 -0
  243. package/dist/Fx/constructors/at.d.ts +23 -3
  244. package/dist/Fx/constructors/at.d.ts.map +1 -1
  245. package/dist/Fx/constructors/at.js +21 -1
  246. package/dist/Fx/constructors/die.d.ts +22 -1
  247. package/dist/Fx/constructors/die.d.ts.map +1 -1
  248. package/dist/Fx/constructors/die.js +22 -1
  249. package/dist/Fx/constructors/empty.d.ts +19 -1
  250. package/dist/Fx/constructors/empty.d.ts.map +1 -1
  251. package/dist/Fx/constructors/empty.js +19 -1
  252. package/dist/Fx/constructors/fail.d.ts +22 -1
  253. package/dist/Fx/constructors/fail.d.ts.map +1 -1
  254. package/dist/Fx/constructors/fail.js +22 -1
  255. package/dist/Fx/constructors/failCause.d.ts +23 -1
  256. package/dist/Fx/constructors/failCause.d.ts.map +1 -1
  257. package/dist/Fx/constructors/failCause.js +23 -1
  258. package/dist/Fx/constructors/fn.d.ts +116 -16
  259. package/dist/Fx/constructors/fn.d.ts.map +1 -1
  260. package/dist/Fx/constructors/fn.js +36 -0
  261. package/dist/Fx/constructors/fromEffect.d.ts +45 -3
  262. package/dist/Fx/constructors/fromEffect.d.ts.map +1 -1
  263. package/dist/Fx/constructors/fromEffect.js +45 -3
  264. package/dist/Fx/constructors/fromFailures.d.ts +25 -1
  265. package/dist/Fx/constructors/fromFailures.d.ts.map +1 -1
  266. package/dist/Fx/constructors/fromFailures.js +25 -1
  267. package/dist/Fx/constructors/fromIterable.d.ts +23 -1
  268. package/dist/Fx/constructors/fromIterable.d.ts.map +1 -1
  269. package/dist/Fx/constructors/fromIterable.js +23 -1
  270. package/dist/Fx/constructors/fromSchedule.d.ts +26 -1
  271. package/dist/Fx/constructors/fromSchedule.d.ts.map +1 -1
  272. package/dist/Fx/constructors/fromSchedule.js +28 -3
  273. package/dist/Fx/constructors/index.d.ts +2 -1
  274. package/dist/Fx/constructors/index.d.ts.map +1 -1
  275. package/dist/Fx/constructors/index.js +2 -1
  276. package/dist/Fx/constructors/interrupt.d.ts +22 -2
  277. package/dist/Fx/constructors/interrupt.d.ts.map +1 -1
  278. package/dist/Fx/constructors/interrupt.js +22 -2
  279. package/dist/Fx/constructors/make.d.ts +151 -4
  280. package/dist/Fx/constructors/make.d.ts.map +1 -1
  281. package/dist/Fx/constructors/make.js +60 -7
  282. package/dist/Fx/constructors/periodic.d.ts +31 -2
  283. package/dist/Fx/constructors/periodic.d.ts.map +1 -1
  284. package/dist/Fx/constructors/periodic.js +30 -1
  285. package/dist/Fx/constructors/succeed.d.ts +79 -7
  286. package/dist/Fx/constructors/succeed.d.ts.map +1 -1
  287. package/dist/Fx/constructors/succeed.js +79 -7
  288. package/dist/Fx/constructors/suspend.d.ts +28 -0
  289. package/dist/Fx/constructors/suspend.d.ts.map +1 -1
  290. package/dist/Fx/constructors/suspend.js +28 -0
  291. package/dist/Fx/constructors/sync.d.ts +32 -0
  292. package/dist/Fx/constructors/sync.d.ts.map +1 -0
  293. package/dist/Fx/constructors/sync.js +32 -0
  294. package/dist/Fx/internal/DeferredRef.d.ts +259 -7
  295. package/dist/Fx/internal/DeferredRef.d.ts.map +1 -1
  296. package/dist/Fx/internal/DeferredRef.js +260 -9
  297. package/dist/Fx/internal/UnionToTuple.d.ts +22 -0
  298. package/dist/Fx/internal/UnionToTuple.d.ts.map +1 -1
  299. package/dist/Fx/internal/diff.d.ts +586 -0
  300. package/dist/Fx/internal/diff.d.ts.map +1 -1
  301. package/dist/Fx/internal/diff.js +120 -9
  302. package/dist/Fx/internal/effectableEvaluateKey.d.ts +30 -0
  303. package/dist/Fx/internal/effectableEvaluateKey.d.ts.map +1 -0
  304. package/dist/Fx/internal/effectableEvaluateKey.js +29 -0
  305. package/dist/Fx/internal/effectableWithOverride.d.ts +55 -0
  306. package/dist/Fx/internal/effectableWithOverride.d.ts.map +1 -0
  307. package/dist/Fx/internal/effectableWithOverride.js +46 -0
  308. package/dist/Fx/internal/equivalence.d.ts +29 -0
  309. package/dist/Fx/internal/equivalence.d.ts.map +1 -1
  310. package/dist/Fx/internal/equivalence.js +29 -0
  311. package/dist/Fx/internal/multicast.d.ts +145 -2
  312. package/dist/Fx/internal/multicast.d.ts.map +1 -1
  313. package/dist/Fx/internal/multicast.js +146 -4
  314. package/dist/Fx/internal/ring-buffer.d.ts +149 -0
  315. package/dist/Fx/internal/ring-buffer.d.ts.map +1 -1
  316. package/dist/Fx/internal/ring-buffer.js +155 -0
  317. package/dist/Fx/internal/scope.d.ts +184 -0
  318. package/dist/Fx/internal/scope.d.ts.map +1 -1
  319. package/dist/Fx/internal/scope.js +150 -0
  320. package/dist/Fx/internal/yieldable.d.ts +117 -2
  321. package/dist/Fx/internal/yieldable.d.ts.map +1 -1
  322. package/dist/Fx/internal/yieldable.js +86 -3
  323. package/dist/Fx/run/collect.d.ts +93 -4
  324. package/dist/Fx/run/collect.d.ts.map +1 -1
  325. package/dist/Fx/run/collect.js +94 -5
  326. package/dist/Fx/run/first.d.ts +23 -1
  327. package/dist/Fx/run/first.d.ts.map +1 -1
  328. package/dist/Fx/run/first.js +23 -1
  329. package/dist/Fx/run/fork.d.ts +52 -2
  330. package/dist/Fx/run/fork.d.ts.map +1 -1
  331. package/dist/Fx/run/fork.js +52 -2
  332. package/dist/Fx/run/observe.d.ts +112 -4
  333. package/dist/Fx/run/observe.d.ts.map +1 -1
  334. package/dist/Fx/run/observe.js +137 -16
  335. package/dist/Fx/run/runPromise.d.ts +45 -2
  336. package/dist/Fx/run/runPromise.d.ts.map +1 -1
  337. package/dist/Fx/run/runPromise.js +45 -2
  338. package/dist/Fx/stream.d.ts +92 -0
  339. package/dist/Fx/stream.d.ts.map +1 -1
  340. package/dist/Fx/stream.js +60 -1
  341. package/dist/Push/Push.d.ts +1286 -98
  342. package/dist/Push/Push.d.ts.map +1 -1
  343. package/dist/Push/Push.js +1074 -88
  344. package/dist/RefArray.d.ts +2 -0
  345. package/dist/RefArray.d.ts.map +1 -0
  346. package/dist/RefArray.js +1 -0
  347. package/dist/RefBigDecimal.d.ts +2 -0
  348. package/dist/RefBigDecimal.d.ts.map +1 -0
  349. package/dist/RefBigDecimal.js +1 -0
  350. package/dist/RefBigInt.d.ts +2 -0
  351. package/dist/RefBigInt.d.ts.map +1 -0
  352. package/dist/RefBigInt.js +1 -0
  353. package/dist/RefBoolean.d.ts +2 -0
  354. package/dist/RefBoolean.d.ts.map +1 -0
  355. package/dist/RefBoolean.js +1 -0
  356. package/dist/RefCause.d.ts +2 -0
  357. package/dist/RefCause.d.ts.map +1 -0
  358. package/dist/RefCause.js +1 -0
  359. package/dist/RefChunk.d.ts +2 -0
  360. package/dist/RefChunk.d.ts.map +1 -0
  361. package/dist/RefChunk.js +1 -0
  362. package/dist/RefDateTime.d.ts +2 -0
  363. package/dist/RefDateTime.d.ts.map +1 -0
  364. package/dist/RefDateTime.js +1 -0
  365. package/dist/RefDuration.d.ts +2 -0
  366. package/dist/RefDuration.d.ts.map +1 -0
  367. package/dist/RefDuration.js +1 -0
  368. package/dist/RefGraph.d.ts +2 -0
  369. package/dist/RefGraph.d.ts.map +1 -0
  370. package/dist/RefGraph.js +1 -0
  371. package/dist/RefHashMap.d.ts +2 -0
  372. package/dist/RefHashMap.d.ts.map +1 -0
  373. package/dist/RefHashMap.js +1 -0
  374. package/dist/RefHashRing.d.ts +2 -0
  375. package/dist/RefHashRing.d.ts.map +1 -0
  376. package/dist/RefHashRing.js +1 -0
  377. package/dist/RefHashSet.d.ts +2 -0
  378. package/dist/RefHashSet.d.ts.map +1 -0
  379. package/dist/RefHashSet.js +1 -0
  380. package/dist/RefIterable.d.ts +2 -0
  381. package/dist/RefIterable.d.ts.map +1 -0
  382. package/dist/RefIterable.js +1 -0
  383. package/dist/RefOption.d.ts +2 -0
  384. package/dist/RefOption.d.ts.map +1 -0
  385. package/dist/RefOption.js +1 -0
  386. package/dist/RefRecord.d.ts +2 -0
  387. package/dist/RefRecord.d.ts.map +1 -0
  388. package/dist/RefRecord.js +1 -0
  389. package/dist/RefResult.d.ts +2 -0
  390. package/dist/RefResult.d.ts.map +1 -0
  391. package/dist/RefResult.js +1 -0
  392. package/dist/RefString.d.ts +2 -0
  393. package/dist/RefString.d.ts.map +1 -0
  394. package/dist/RefString.js +1 -0
  395. package/dist/RefStruct.d.ts +2 -0
  396. package/dist/RefStruct.d.ts.map +1 -0
  397. package/dist/RefStruct.js +1 -0
  398. package/dist/RefSubject/Hydration.d.ts +504 -0
  399. package/dist/RefSubject/Hydration.d.ts.map +1 -0
  400. package/dist/RefSubject/Hydration.js +300 -0
  401. package/dist/RefSubject/RefArray.d.ts +382 -35
  402. package/dist/RefSubject/RefArray.d.ts.map +1 -1
  403. package/dist/RefSubject/RefArray.js +374 -40
  404. package/dist/RefSubject/RefBigDecimal.d.ts +241 -21
  405. package/dist/RefSubject/RefBigDecimal.d.ts.map +1 -1
  406. package/dist/RefSubject/RefBigDecimal.js +229 -20
  407. package/dist/RefSubject/RefBigInt.d.ts +181 -16
  408. package/dist/RefSubject/RefBigInt.d.ts.map +1 -1
  409. package/dist/RefSubject/RefBigInt.js +169 -15
  410. package/dist/RefSubject/RefBoolean.d.ts +181 -16
  411. package/dist/RefSubject/RefBoolean.d.ts.map +1 -1
  412. package/dist/RefSubject/RefBoolean.js +169 -15
  413. package/dist/RefSubject/RefCause.d.ts +133 -12
  414. package/dist/RefSubject/RefCause.d.ts.map +1 -1
  415. package/dist/RefSubject/RefCause.js +121 -11
  416. package/dist/RefSubject/RefChunk.d.ts +481 -76
  417. package/dist/RefSubject/RefChunk.d.ts.map +1 -1
  418. package/dist/RefSubject/RefChunk.js +471 -75
  419. package/dist/RefSubject/RefDateTime.d.ts +137 -16
  420. package/dist/RefSubject/RefDateTime.d.ts.map +1 -1
  421. package/dist/RefSubject/RefDateTime.js +122 -12
  422. package/dist/RefSubject/RefDuration.d.ts +169 -15
  423. package/dist/RefSubject/RefDuration.d.ts.map +1 -1
  424. package/dist/RefSubject/RefDuration.js +157 -14
  425. package/dist/RefSubject/RefGraph.d.ts +349 -35
  426. package/dist/RefSubject/RefGraph.d.ts.map +1 -1
  427. package/dist/RefSubject/RefGraph.js +334 -32
  428. package/dist/RefSubject/RefHashMap.d.ts +323 -28
  429. package/dist/RefSubject/RefHashMap.d.ts.map +1 -1
  430. package/dist/RefSubject/RefHashMap.js +317 -29
  431. package/dist/RefSubject/RefHashRing.d.ts +159 -15
  432. package/dist/RefSubject/RefHashRing.d.ts.map +1 -1
  433. package/dist/RefSubject/RefHashRing.js +145 -12
  434. package/dist/RefSubject/RefHashSet.d.ts +251 -22
  435. package/dist/RefSubject/RefHashSet.d.ts.map +1 -1
  436. package/dist/RefSubject/RefHashSet.js +238 -20
  437. package/dist/RefSubject/RefIterable.d.ts +358 -32
  438. package/dist/RefSubject/RefIterable.d.ts.map +1 -1
  439. package/dist/RefSubject/RefIterable.js +350 -30
  440. package/dist/RefSubject/RefOption.d.ts +157 -14
  441. package/dist/RefSubject/RefOption.d.ts.map +1 -1
  442. package/dist/RefSubject/RefOption.js +145 -13
  443. package/dist/RefSubject/RefRecord.d.ts +402 -64
  444. package/dist/RefSubject/RefRecord.d.ts.map +1 -1
  445. package/dist/RefSubject/RefRecord.js +364 -39
  446. package/dist/RefSubject/RefResult.d.ts +167 -35
  447. package/dist/RefSubject/RefResult.d.ts.map +1 -1
  448. package/dist/RefSubject/RefResult.js +133 -12
  449. package/dist/RefSubject/RefString.d.ts +205 -18
  450. package/dist/RefSubject/RefString.d.ts.map +1 -1
  451. package/dist/RefSubject/RefString.js +193 -17
  452. package/dist/RefSubject/RefStruct.d.ts +169 -14
  453. package/dist/RefSubject/RefStruct.d.ts.map +1 -1
  454. package/dist/RefSubject/RefStruct.js +157 -13
  455. package/dist/RefSubject/RefSubject.d.ts +1242 -43
  456. package/dist/RefSubject/RefSubject.d.ts.map +1 -1
  457. package/dist/RefSubject/RefSubject.js +1012 -86
  458. package/dist/RefSubject/RefTrie.d.ts +323 -37
  459. package/dist/RefSubject/RefTrie.d.ts.map +1 -1
  460. package/dist/RefSubject/RefTrie.js +311 -31
  461. package/dist/RefSubject/RefTuple.d.ts +127 -11
  462. package/dist/RefSubject/RefTuple.d.ts.map +1 -1
  463. package/dist/RefSubject/RefTuple.js +114 -9
  464. package/dist/RefSubject/index.d.ts +1 -0
  465. package/dist/RefSubject/index.d.ts.map +1 -1
  466. package/dist/RefSubject/index.js +1 -0
  467. package/dist/RefSubject.d.ts +2 -1
  468. package/dist/RefSubject.d.ts.map +1 -1
  469. package/dist/RefSubject.js +2 -1
  470. package/dist/RefTrie.d.ts +2 -0
  471. package/dist/RefTrie.d.ts.map +1 -0
  472. package/dist/RefTrie.js +1 -0
  473. package/dist/RefTuple.d.ts +2 -0
  474. package/dist/RefTuple.d.ts.map +1 -0
  475. package/dist/RefTuple.js +1 -0
  476. package/dist/Sink/Sink.d.ts +396 -23
  477. package/dist/Sink/Sink.d.ts.map +1 -1
  478. package/dist/Sink/Sink.js +55 -7
  479. package/dist/Sink/combinators.d.ts +789 -3
  480. package/dist/Sink/combinators.d.ts.map +1 -1
  481. package/dist/Sink/combinators.js +812 -7
  482. package/dist/Subject/Subject.d.ts +1022 -27
  483. package/dist/Subject/Subject.d.ts.map +1 -1
  484. package/dist/Subject/Subject.js +909 -43
  485. package/dist/Versioned/Versioned.d.ts +475 -25
  486. package/dist/Versioned/Versioned.d.ts.map +1 -1
  487. package/dist/Versioned/Versioned.js +298 -46
  488. package/dist/index.d.ts +22 -3
  489. package/dist/index.d.ts.map +1 -1
  490. package/dist/index.js +22 -3
  491. package/package.json +125 -11
  492. package/dist/Fx/constructors/fromYieldable.d.ts +0 -12
  493. package/dist/Fx/constructors/fromYieldable.d.ts.map +0 -1
  494. package/dist/Fx/constructors/fromYieldable.js +0 -12
  495. package/src/Fx/Fx.ts +0 -164
  496. package/src/Fx/TypeId.ts +0 -25
  497. package/src/Fx/combinators/catch.ts +0 -165
  498. package/src/Fx/combinators/causes.ts +0 -23
  499. package/src/Fx/combinators/compact.ts +0 -15
  500. package/src/Fx/combinators/continueWith.ts +0 -78
  501. package/src/Fx/combinators/ensuring.ts +0 -23
  502. package/src/Fx/combinators/exhaustLatestMap.ts +0 -74
  503. package/src/Fx/combinators/exhaustLatestMapEffect.ts +0 -25
  504. package/src/Fx/combinators/exhaustMap.ts +0 -36
  505. package/src/Fx/combinators/exhaustMapEffect.ts +0 -23
  506. package/src/Fx/combinators/exit.ts +0 -15
  507. package/src/Fx/combinators/filter.ts +0 -22
  508. package/src/Fx/combinators/filterEffect.ts +0 -31
  509. package/src/Fx/combinators/filterMap.ts +0 -23
  510. package/src/Fx/combinators/filterMapEffect.ts +0 -32
  511. package/src/Fx/combinators/filterMapLoop.ts +0 -35
  512. package/src/Fx/combinators/filterMapLoopCause.ts +0 -36
  513. package/src/Fx/combinators/filterMapLoopCauseEffect.ts +0 -46
  514. package/src/Fx/combinators/filterMapLoopEffect.ts +0 -36
  515. package/src/Fx/combinators/flatMap.ts +0 -51
  516. package/src/Fx/combinators/flatMapConcurrently.ts +0 -36
  517. package/src/Fx/combinators/flatMapConcurrentlyEffect.ts +0 -26
  518. package/src/Fx/combinators/flatMapEffect.ts +0 -42
  519. package/src/Fx/combinators/flip.ts +0 -14
  520. package/src/Fx/combinators/gen.ts +0 -24
  521. package/src/Fx/combinators/genScoped.ts +0 -24
  522. package/src/Fx/combinators/index.ts +0 -51
  523. package/src/Fx/combinators/keyed.ts +0 -369
  524. package/src/Fx/combinators/loop.ts +0 -27
  525. package/src/Fx/combinators/loopCause.ts +0 -34
  526. package/src/Fx/combinators/loopCauseEffect.ts +0 -36
  527. package/src/Fx/combinators/loopEffect.ts +0 -34
  528. package/src/Fx/combinators/map.ts +0 -22
  529. package/src/Fx/combinators/mapEffect.ts +0 -32
  530. package/src/Fx/combinators/mergeAll.ts +0 -22
  531. package/src/Fx/combinators/mergeOrdered.ts +0 -123
  532. package/src/Fx/combinators/onError.ts +0 -40
  533. package/src/Fx/combinators/onExit.ts +0 -82
  534. package/src/Fx/combinators/onInterrupt.ts +0 -87
  535. package/src/Fx/combinators/provide.ts +0 -62
  536. package/src/Fx/combinators/skip.ts +0 -20
  537. package/src/Fx/combinators/skipRepeats.ts +0 -15
  538. package/src/Fx/combinators/skipRepeatsWith.ts +0 -40
  539. package/src/Fx/combinators/slice.ts +0 -32
  540. package/src/Fx/combinators/switchMap.ts +0 -55
  541. package/src/Fx/combinators/switchMapEffect.ts +0 -25
  542. package/src/Fx/combinators/take.ts +0 -17
  543. package/src/Fx/combinators/takeUntil.ts +0 -50
  544. package/src/Fx/combinators/tapEffect.ts +0 -39
  545. package/src/Fx/combinators/tuple.ts +0 -79
  546. package/src/Fx/combinators/unwrap.ts +0 -21
  547. package/src/Fx/combinators/unwrapScoped.ts +0 -26
  548. package/src/Fx/combinators/when.ts +0 -64
  549. package/src/Fx/combinators/withSpan.ts +0 -24
  550. package/src/Fx/constructors/at.ts +0 -23
  551. package/src/Fx/constructors/die.ts +0 -17
  552. package/src/Fx/constructors/empty.ts +0 -10
  553. package/src/Fx/constructors/fail.ts +0 -14
  554. package/src/Fx/constructors/failCause.ts +0 -14
  555. package/src/Fx/constructors/fn.ts +0 -245
  556. package/src/Fx/constructors/fromEffect.ts +0 -24
  557. package/src/Fx/constructors/fromFailures.ts +0 -19
  558. package/src/Fx/constructors/fromIterable.ts +0 -15
  559. package/src/Fx/constructors/fromSchedule.ts +0 -18
  560. package/src/Fx/constructors/fromYieldable.ts +0 -17
  561. package/src/Fx/constructors/index.ts +0 -15
  562. package/src/Fx/constructors/interrupt.ts +0 -13
  563. package/src/Fx/constructors/make.ts +0 -103
  564. package/src/Fx/constructors/periodic.ts +0 -15
  565. package/src/Fx/constructors/succeed.ts +0 -37
  566. package/src/Fx/constructors/suspend.ts +0 -6
  567. package/src/Fx/index.ts +0 -6
  568. package/src/Fx/internal/DeferredRef.ts +0 -87
  569. package/src/Fx/internal/UnionToTuple.ts +0 -12
  570. package/src/Fx/internal/diff.ts +0 -191
  571. package/src/Fx/internal/equivalence.ts +0 -12
  572. package/src/Fx/internal/multicast.ts +0 -51
  573. package/src/Fx/internal/ring-buffer.ts +0 -60
  574. package/src/Fx/internal/scope.ts +0 -58
  575. package/src/Fx/internal/yieldable.ts +0 -31
  576. package/src/Fx/run/collect.ts +0 -79
  577. package/src/Fx/run/first.ts +0 -20
  578. package/src/Fx/run/fork.ts +0 -40
  579. package/src/Fx/run/index.ts +0 -5
  580. package/src/Fx/run/observe.ts +0 -114
  581. package/src/Fx/run/runPromise.ts +0 -32
  582. package/src/Fx/stream.ts +0 -42
  583. package/src/Fx.catch.test.ts +0 -61
  584. package/src/Fx.fn.test.ts +0 -51
  585. package/src/Fx.lifecycle.test.ts +0 -80
  586. package/src/Fx.test.ts +0 -71
  587. package/src/Fx.ts +0 -1
  588. package/src/Push/Push.ts +0 -903
  589. package/src/Push/index.ts +0 -1
  590. package/src/Push.test.ts +0 -26
  591. package/src/Push.ts +0 -1
  592. package/src/RefSubject/RefArray.ts +0 -512
  593. package/src/RefSubject/RefBigDecimal.test.ts +0 -56
  594. package/src/RefSubject/RefBigDecimal.ts +0 -295
  595. package/src/RefSubject/RefBigInt.test.ts +0 -56
  596. package/src/RefSubject/RefBigInt.ts +0 -189
  597. package/src/RefSubject/RefBoolean.test.ts +0 -57
  598. package/src/RefSubject/RefBoolean.ts +0 -185
  599. package/src/RefSubject/RefCause.test.ts +0 -53
  600. package/src/RefSubject/RefCause.ts +0 -146
  601. package/src/RefSubject/RefChunk.ts +0 -510
  602. package/src/RefSubject/RefDateTime.test.ts +0 -43
  603. package/src/RefSubject/RefDateTime.ts +0 -264
  604. package/src/RefSubject/RefDuration.test.ts +0 -49
  605. package/src/RefSubject/RefDuration.ts +0 -188
  606. package/src/RefSubject/RefGraph.ts +0 -650
  607. package/src/RefSubject/RefHashMap.ts +0 -465
  608. package/src/RefSubject/RefHashRing.ts +0 -262
  609. package/src/RefSubject/RefHashSet.ts +0 -308
  610. package/src/RefSubject/RefIterable.ts +0 -445
  611. package/src/RefSubject/RefOption.test.ts +0 -67
  612. package/src/RefSubject/RefOption.ts +0 -193
  613. package/src/RefSubject/RefRecord.ts +0 -612
  614. package/src/RefSubject/RefResult.test.ts +0 -63
  615. package/src/RefSubject/RefResult.ts +0 -209
  616. package/src/RefSubject/RefString.test.ts +0 -61
  617. package/src/RefSubject/RefString.ts +0 -256
  618. package/src/RefSubject/RefStruct.test.ts +0 -60
  619. package/src/RefSubject/RefStruct.ts +0 -253
  620. package/src/RefSubject/RefSubject.ts +0 -2545
  621. package/src/RefSubject/RefTrie.ts +0 -356
  622. package/src/RefSubject/RefTuple.test.ts +0 -60
  623. package/src/RefSubject/RefTuple.ts +0 -231
  624. package/src/RefSubject/index.ts +0 -21
  625. package/src/RefSubject.test.ts +0 -65
  626. package/src/RefSubject.ts +0 -1
  627. package/src/Sink/Sink.ts +0 -159
  628. package/src/Sink/combinators.ts +0 -993
  629. package/src/Sink/index.ts +0 -2
  630. package/src/Sink.ts +0 -1
  631. package/src/Subject/Subject.ts +0 -441
  632. package/src/Subject/index.ts +0 -1
  633. package/src/Subject.test.ts +0 -47
  634. package/src/Subject.ts +0 -1
  635. package/src/Versioned/Versioned.ts +0 -521
  636. package/src/Versioned/index.ts +0 -1
  637. package/src/Versioned.test.ts +0 -23
  638. package/src/Versioned.ts +0 -1
  639. package/src/index.ts +0 -7
  640. package/tsconfig.json +0 -6
package/dist/Push/Push.js CHANGED
@@ -3,13 +3,30 @@
3
3
  import * as Effect from "effect/Effect";
4
4
  import { dual, identity } from "effect/Function";
5
5
  import * as Layer from "effect/Layer";
6
+ import * as Option from "effect/Option";
6
7
  import { pipeArguments } from "effect/Pipeable";
7
- import * as ServiceMap from "effect/ServiceMap";
8
+ import * as Context from "effect/Context";
8
9
  import * as Fx from "../Fx/index.js";
9
10
  import { FxTypeId } from "../Fx/TypeId.js";
10
11
  import * as Sink from "../Sink.js";
11
12
  /**
12
- * Creates a `Push` from a `Sink` and an `Fx`.
13
+ * Couples a `Sink` input with an independent `Fx` output.
14
+ *
15
+ * The result forwards each input callback directly to `sink` and delegates every
16
+ * output subscription to `fx`. It does not connect the two values, change output
17
+ * cardinality or ordering, buffer inputs, or start either side eagerly.
18
+ *
19
+ * @remarks
20
+ * ## Why
21
+ *
22
+ * `make` is the explicit boundary where a command consumer and event producer
23
+ * become one bidirectional capability without hiding either contract.
24
+ *
25
+ * ## Ownership and lifetime
26
+ *
27
+ * Construction is allocation-free apart from the wrapper. Each input callback is
28
+ * owned by its caller; each output run is owned by the wrapped Fx run and inherits
29
+ * its interruption, Scope, cleanup, failures, and services.
13
30
  *
14
31
  * @example
15
32
  * ```ts
@@ -18,30 +35,21 @@ import * as Sink from "../Sink.js";
18
35
  * import { Fx } from "@typed/fx"
19
36
  * import * as Sink from "@typed/fx/Sink"
20
37
  *
21
- * const program = Effect.gen(function* () {
22
- * const sink = Sink.make(
23
- * (cause) => Effect.sync(() => console.log("Failed:", cause)),
24
- * (value) => Effect.sync(() => console.log("Success:", value))
25
- * )
26
- *
27
- * const fx = Fx.succeed("Output")
28
- *
29
- * const push = Push.make(sink, fx)
38
+ * const received: Array<number> = []
39
+ * const sink = Sink.make(() => Effect.void, (value: number) =>
40
+ * Effect.sync(() => received.push(value))
41
+ * )
42
+ * const push = Push.make(sink, Fx.fromIterable(["ready", "done"]))
30
43
  *
31
- * // Push a value
32
- * yield* push.onSuccess(42)
33
- * // Output: "Success: 42"
34
- *
35
- * // Observe the Fx
36
- * yield* Fx.observe(push, (value) =>
37
- * Effect.sync(() => console.log("Emitted:", value))
38
- * )
39
- * // Output: "Emitted: Output"
40
- * })
44
+ * const program = Effect.gen(function* () {
45
+ * yield* push.onSuccess(42) // acknowledges the Sink callback
46
+ * const output = yield* Fx.collectAll(push)
47
+ * return { received, output }
48
+ * }).pipe(Effect.scoped)
41
49
  * ```
42
50
  *
43
51
  * @since 1.0.0
44
- * @category constructors
52
+ * @category Push construction
45
53
  */
46
54
  export const make = dual(2, (sink, fx) => new PushImpl(sink, fx));
47
55
  const VARIANCE = {
@@ -73,56 +81,289 @@ class PushImpl {
73
81
  }
74
82
  }
75
83
  /**
76
- * Maps over the input (Sink) side of a `Push`.
84
+ * Synchronously transforms each successful input before sending it to the Sink.
85
+ *
86
+ * One input maps to exactly one downstream input. Calling `onSuccess` evaluates
87
+ * `f` immediately, before the returned downstream Effect is run; allocation and
88
+ * thrown exceptions therefore occur at callback invocation (and become defects
89
+ * only when that invocation itself occurs inside Effect evaluation). The Sink
90
+ * callback Effect remains the acknowledgment. Calls are not serialized; execution
91
+ * order and concurrency follow the producer. The Fx output is unchanged.
92
+ *
93
+ * @remarks
94
+ * ## Why
95
+ *
96
+ * Adapt an external command shape to an existing consumer without rebuilding or
97
+ * changing the independent output stream.
98
+ *
99
+ * ## Ownership and lifetime
100
+ *
101
+ * `f` runs synchronously when `onSuccess` is called, before its returned Effect
102
+ * exists, and acquires no resource. Downstream handling retains the original
103
+ * Sink's `E`, `R`, caller fiber, interruption, and cleanup behavior.
77
104
  *
78
105
  * @example
79
106
  * ```ts
80
107
  * import { Effect } from "effect"
108
+ * import * as Fx from "@typed/fx/Fx"
81
109
  * import * as Push from "@typed/fx/Push"
82
- * import { Fx } from "@typed/fx"
83
110
  * import * as Sink from "@typed/fx/Sink"
84
111
  *
85
- * const program = Effect.gen(function* () {
86
- * const push = Push.make(
87
- * Sink.make(
88
- * (cause) => Effect.void,
89
- * (value) => Effect.sync(() => console.log("Number:", value))
90
- * ),
91
- * Fx.succeed("Output")
92
- * )
93
- *
94
- * // Map input from string to number
95
- * const mapped = Push.mapInput(push, (str: string) => parseInt(str))
96
- *
97
- * // Push a string, which gets converted to a number
98
- * yield* mapped.onSuccess("42")
99
- * // Output: "Number: 42"
112
+ * const events: Array<string> = []
113
+ * const base = Push.make(
114
+ * Sink.make(() => Effect.void, (n: number) => Effect.sync(() => events.push(`sink:${n}`))),
115
+ * Fx.empty
116
+ * )
117
+ * const mapped = Push.mapInput(base, (text: string) => {
118
+ * events.push(`map:${text}`)
119
+ * return Number(text)
100
120
  * })
121
+ * const acknowledgement = mapped.onSuccess("42")
122
+ * // events is already ["map:42"]; the Sink Effect has not run yet.
123
+ * const program = Effect.as(acknowledgement, events)
101
124
  * ```
102
125
  *
103
126
  * @since 1.0.0
104
- * @category combinators
127
+ * @category Transforming inputs
105
128
  */
106
129
  export const mapInput = dual(2, function mapInput(push, f) {
107
130
  return make(Sink.map(push, f), push);
108
131
  });
132
+ /**
133
+ * Effectfully transforms each successful input before sending it to the Sink.
134
+ *
135
+ * Calling `onSuccess(value)` invokes `f(value)` immediately to construct an
136
+ * Effect. Allocation and thrown exceptions therefore occur before an
137
+ * acknowledgment Effect is returned. Running that returned Effect later executes
138
+ * the constructed Effect in the caller's fiber. On success its single `A` reaches
139
+ * the Sink; typed failure, defect, or interruption sends its full Cause to the
140
+ * Sink failure callback. Calls are not serialized, so the producer controls order
141
+ * and concurrency. Output values and order are unchanged.
142
+ *
143
+ * @remarks
144
+ * ## Why
145
+ *
146
+ * Use this at an input boundary that must decode, validate, or load Effect
147
+ * services before the existing consumer can accept a value.
148
+ *
149
+ * ## Ownership and lifetime
150
+ *
151
+ * Effect construction happens eagerly at `onSuccess`; only execution is deferred.
152
+ * The fiber running the returned acknowledgment owns execution and interruption
153
+ * of the constructed Effect and downstream callback. `E` is handled by the Sink
154
+ * failure channel, while `R3` joins the input service requirements.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { Effect } from "effect"
159
+ * import * as Fx from "@typed/fx/Fx"
160
+ * import * as Push from "@typed/fx/Push"
161
+ * import * as Sink from "@typed/fx/Sink"
162
+ *
163
+ * const numbers: Array<number> = []
164
+ * const base = Push.make(
165
+ * Sink.make(() => Effect.void, (n: number) => Effect.sync(() => numbers.push(n))),
166
+ * Fx.empty
167
+ * )
168
+ * const parsed = Push.mapInputEffect(base, (text: string) =>
169
+ * text === "" ? Effect.fail("empty" as const) : Effect.succeed(Number(text))
170
+ * )
171
+ * ```
172
+ *
173
+ * @since 1.0.0
174
+ * @category Transforming inputs
175
+ */
109
176
  export const mapInputEffect = dual(2, function mapInputEffect(push, f) {
110
177
  return make(Sink.mapEffect(push, f), push);
111
178
  });
179
+ /**
180
+ * Keeps successful inputs that satisfy `f` and discards the rest.
181
+ *
182
+ * Calling `onSuccess` runs the predicate immediately. A match constructs one Sink
183
+ * callback Effect; a non-match immediately returns an empty acknowledgment.
184
+ * Predicate allocation and throws therefore occur before the returned Effect is
185
+ * run. The producer controls call order and concurrency; output is preserved.
186
+ *
187
+ * @remarks
188
+ * ## Why
189
+ *
190
+ * Filtering before the consumer avoids teaching the underlying Sink about input
191
+ * values that are irrelevant to it.
192
+ *
193
+ * ## Ownership and lifetime
194
+ *
195
+ * The predicate is synchronous at `onSuccess` invocation and acquires no
196
+ * resources. Accepted callback Effects retain the original Sink's errors,
197
+ * services, interruption, and cleanup.
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * import { Effect } from "effect"
202
+ * import * as Fx from "@typed/fx/Fx"
203
+ * import * as Push from "@typed/fx/Push"
204
+ * import * as Sink from "@typed/fx/Sink"
205
+ *
206
+ * const checks: Array<number> = []
207
+ * const positives = Push.filterInput(
208
+ * Push.make(Sink.make(() => Effect.void, (n: number) => Effect.log(n)), Fx.empty),
209
+ * (n) => (checks.push(n), n > 0)
210
+ * )
211
+ * const acknowledgement = positives.onSuccess(-1)
212
+ * // checks is already [-1]; acknowledgement performs no Sink callback.
213
+ * ```
214
+ *
215
+ * @since 1.0.0
216
+ * @category Selecting inputs
217
+ */
112
218
  export const filterInput = dual(2, function filterInput(push, f) {
113
219
  return make(Sink.filter(push, f), push);
114
220
  });
221
+ /**
222
+ * Effectfully decides whether each successful input reaches the Sink.
223
+ *
224
+ * Calling `onSuccess(value)` invokes `f(value)` immediately to construct the
225
+ * predicate Effect; allocation and throws happen before an acknowledgment is
226
+ * returned. Running the acknowledgment later executes that Effect in the caller's
227
+ * fiber. `true` forwards one value, `false` none, and failure sends its Cause to
228
+ * the Sink failure callback. Calls are not serialized; the producer controls
229
+ * order and concurrency. Output behavior is unchanged.
230
+ *
231
+ * @remarks
232
+ * ## Why
233
+ *
234
+ * This supports authorization and service-backed eligibility checks directly at
235
+ * the consumer boundary.
236
+ *
237
+ * ## Ownership and lifetime
238
+ *
239
+ * Predicate Effect construction is eager; its execution and downstream callback
240
+ * belong to the fiber that runs the returned acknowledgment, whose interruption
241
+ * stops them. Predicate services join input `R`; typed `E` is consumed through
242
+ * the Sink failure channel.
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * import { Effect } from "effect"
247
+ * import * as Fx from "@typed/fx/Fx"
248
+ * import * as Push from "@typed/fx/Push"
249
+ * import * as Sink from "@typed/fx/Sink"
250
+ *
251
+ * const even = Push.filterInputEffect(
252
+ * Push.make(Sink.make(() => Effect.void, (_n: number) => Effect.void), Fx.empty),
253
+ * (n) => Effect.succeed(n % 2 === 0)
254
+ * )
255
+ * ```
256
+ *
257
+ * @since 1.0.0
258
+ * @category Selecting inputs
259
+ */
115
260
  export const filterInputEffect = dual(2, function filterInputEffect(push, f) {
116
261
  return make(Sink.filterEffect(push, f), push);
117
262
  });
263
+ /**
264
+ * Transforms an input and forwards it only when `f` returns `Some`.
265
+ *
266
+ * Calling `onSuccess` evaluates `f` immediately. `Some(a)` constructs one Sink
267
+ * callback Effect; `None` immediately returns an empty acknowledgment. Mapping
268
+ * allocation and throws therefore happen before the returned Effect runs. Calls
269
+ * are not serialized, so ordering follows the producer. Output is unchanged.
270
+ *
271
+ * @remarks
272
+ * ## Why
273
+ *
274
+ * `Option` combines parsing and filtering without a sentinel value or a separate
275
+ * predicate pass.
276
+ *
277
+ * ## Ownership and lifetime
278
+ *
279
+ * The mapping is synchronous at `onSuccess` invocation and resource-free. A
280
+ * forwarded callback Effect retains the original Sink's lifetime, error channel,
281
+ * and service requirements.
282
+ *
283
+ * @example
284
+ * ```ts
285
+ * import { Effect, Option } from "effect"
286
+ * import * as Fx from "@typed/fx/Fx"
287
+ * import * as Push from "@typed/fx/Push"
288
+ * import * as Sink from "@typed/fx/Sink"
289
+ *
290
+ * const parsed: Array<string> = []
291
+ * const integers = Push.filterMapInput(
292
+ * Push.make(Sink.make(() => Effect.void, (n: number) => Effect.log(n)), Fx.empty),
293
+ * (text: string) => {
294
+ * parsed.push(text)
295
+ * return /^\d+$/.test(text) ? Option.some(Number(text)) : Option.none()
296
+ * }
297
+ * )
298
+ * const acknowledgement = integers.onSuccess("nope")
299
+ * // parsed is already ["nope"]; acknowledgement performs no Sink callback.
300
+ * ```
301
+ *
302
+ * @since 1.0.0
303
+ * @category Selecting inputs
304
+ */
118
305
  export const filterMapInput = dual(2, function filterMapInput(push, f) {
119
306
  return make(Sink.filterMap(push, f), push);
120
307
  });
308
+ /**
309
+ * Effectfully transforms an input and forwards only a resulting `Some` value.
310
+ *
311
+ * Calling `onSuccess(value)` invokes `f(value)` immediately to construct an
312
+ * Effect; allocation and throws happen before an acknowledgment is returned.
313
+ * Running that acknowledgment later executes the constructed Effect in the
314
+ * caller's fiber. `Some(a)` produces one Sink callback, `None` none, and failure
315
+ * sends its full Cause to the Sink failure callback. Concurrent calls are not
316
+ * serialized.
317
+ *
318
+ * @remarks
319
+ * ## Why
320
+ *
321
+ * This is the input-boundary form for service-backed lookup or validation where
322
+ * absence is expected but failure remains meaningful.
323
+ *
324
+ * ## Ownership and lifetime
325
+ *
326
+ * Mapper Effect construction is eager; execution belongs to the fiber that runs
327
+ * the returned acknowledgment and can be interrupted there. Mapper requirements
328
+ * join the Sink input requirements; its `E` is handled through the same failure
329
+ * callback. The output Fx is untouched.
330
+ *
331
+ * @example
332
+ * ```ts
333
+ * import { Effect, Option } from "effect"
334
+ * import * as Fx from "@typed/fx/Fx"
335
+ * import * as Push from "@typed/fx/Push"
336
+ * import * as Sink from "@typed/fx/Sink"
337
+ *
338
+ * const known = Push.filterMapInputEffect(
339
+ * Push.make(Sink.make(() => Effect.void, (_n: number) => Effect.void), Fx.empty),
340
+ * (text: string) => Effect.succeed(text === "one" ? Option.some(1) : Option.none())
341
+ * )
342
+ * ```
343
+ *
344
+ * @since 1.0.0
345
+ * @category Selecting inputs
346
+ */
121
347
  export const filterMapInputEffect = dual(2, function filterMapInputEffect(push, f) {
122
348
  return make(Sink.filterMapEffect(push, f), push);
123
349
  });
124
350
  /**
125
- * Maps over the output (Fx) side of a `Push`.
351
+ * Synchronously transforms every value emitted by the Fx output side.
352
+ *
353
+ * It emits exactly one `C` for every upstream `B`, preserving order and the
354
+ * complete input Sink. The mapping does not buffer or introduce concurrency.
355
+ *
356
+ * @remarks
357
+ * ## Why
358
+ *
359
+ * Adapt observed events without changing the commands the bidirectional boundary
360
+ * accepts.
361
+ *
362
+ * ## Ownership and lifetime
363
+ *
364
+ * `f` runs in the upstream Fx delivery path and owns no resource. Output
365
+ * subscription, interruption, failures, services, and cleanup remain those of the
366
+ * wrapped Fx and downstream Sink.
126
367
  *
127
368
  * @example
128
369
  * ```ts
@@ -152,135 +393,880 @@ export const filterMapInputEffect = dual(2, function filterMapInputEffect(push,
152
393
  * ```
153
394
  *
154
395
  * @since 1.0.0
155
- * @category combinators
396
+ * @category Transforming outputs
156
397
  */
157
398
  export const map = dual(2, function map(push, f) {
158
399
  return make(push, Fx.map(push, f));
159
400
  });
401
+ /**
402
+ * Effectfully transforms each Fx output value.
403
+ *
404
+ * The mapper runs once per upstream value and emits one result on success, in
405
+ * upstream order for a sequential source. Its typed failures join `E2`; its
406
+ * required services join `R2`. The input side is unchanged.
407
+ *
408
+ * @remarks
409
+ * ## Why
410
+ *
411
+ * Use this for output enrichment that needs Effect services or can fail while
412
+ * keeping input handling independent.
413
+ *
414
+ * ## Ownership and lifetime
415
+ *
416
+ * Each mapper Effect runs inside the output subscription and is interrupted with
417
+ * it. No work starts before `run`; cleanup belongs to the upstream Fx and mapper
418
+ * effects. `mapEffect` itself introduces no separate buffer or long-lived fiber.
419
+ *
420
+ * @example
421
+ * ```ts
422
+ * import { Effect } from "effect"
423
+ * import * as Fx from "@typed/fx/Fx"
424
+ * import * as Push from "@typed/fx/Push"
425
+ * import * as Sink from "@typed/fx/Sink"
426
+ *
427
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.succeed(2))
428
+ * const doubled = Push.mapEffect(push, (n) => Effect.succeed(n * 2))
429
+ * ```
430
+ *
431
+ * @since 1.0.0
432
+ * @category Transforming outputs
433
+ */
160
434
  export const mapEffect = dual(2, function mapEffect(push, f) {
161
435
  return make(push, Fx.mapEffect(push, f));
162
436
  });
437
+ /**
438
+ * Transforms the output (Fx) error channel of a `Push` using the provided function.
439
+ *
440
+ * Failures (Cause) are mapped via `Cause.map`, so only the typed failure (`Fail`)
441
+ * is transformed; defects and interrupts are preserved unchanged.
442
+ *
443
+ * Mirrors `Effect.mapError` on the Fx side. Cardinality, value order, input
444
+ * callbacks, and output service requirements are unchanged.
445
+ *
446
+ * @remarks
447
+ * ## Why
448
+ *
449
+ * Normalize an output failure type at the observation boundary without touching
450
+ * input errors or collapsing defects and interruption into typed failures.
451
+ *
452
+ * ## Ownership and lifetime
453
+ *
454
+ * The mapping is synchronous and resource-free. It runs when the output Cause is
455
+ * delivered and preserves the upstream subscription, Scope, interruption, and
456
+ * cleanup behavior.
457
+ *
458
+ * @example
459
+ * ```ts
460
+ * import { Effect } from "effect"
461
+ * import * as Fx from "@typed/fx/Fx"
462
+ * import * as Push from "@typed/fx/Push"
463
+ * import * as Sink from "@typed/fx/Sink"
464
+ *
465
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.fail("offline"))
466
+ * const normalized = Push.mapError(push, (message) => ({ message }))
467
+ * ```
468
+ *
469
+ * @since 1.0.0
470
+ * @category Output failures
471
+ */
472
+ export const mapError = dual(2, function mapError(push, f) {
473
+ return make(push, Fx.mapError(push, f));
474
+ });
475
+ /**
476
+ * Transforms both the output (Fx) success and error channels of a `Push` using the provided options.
477
+ *
478
+ * Mirrors `Effect.mapBoth` on the Fx side: `onSuccess` maps every emitted value
479
+ * one-to-one and `onFailure` maps typed failures via `Cause.map`; defects and
480
+ * interrupts are preserved. Ordering, services, and the input side are unchanged.
481
+ *
482
+ * @remarks
483
+ * ## Why
484
+ *
485
+ * Adapt both observable result channels at once while leaving command handling
486
+ * and non-typed Cause information intact.
487
+ *
488
+ * ## Ownership and lifetime
489
+ *
490
+ * Both functions run synchronously in the output delivery path and acquire no
491
+ * resources. The wrapped Fx retains ownership of its subscription and finalizers.
492
+ *
493
+ * @example
494
+ * ```ts
495
+ * import { Effect } from "effect"
496
+ * import * as Fx from "@typed/fx/Fx"
497
+ * import * as Push from "@typed/fx/Push"
498
+ * import * as Sink from "@typed/fx/Sink"
499
+ *
500
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.succeed(2))
501
+ * const labeled = Push.mapBoth(push, {
502
+ * onFailure: (error: never) => error,
503
+ * onSuccess: (value) => `value:${value}`
504
+ * })
505
+ * ```
506
+ *
507
+ * @since 1.0.0
508
+ * @category Transforming outputs
509
+ */
510
+ export const mapBoth = dual(2, function mapBoth(push, options) {
511
+ return make(push, Fx.mapBoth(push, options));
512
+ });
513
+ /**
514
+ * Keeps Fx output values that satisfy `f`.
515
+ *
516
+ * The upstream Sink invokes the predicate synchronously for each output value,
517
+ * before the returned downstream callback Effect runs. Predicate allocation and
518
+ * throws therefore occur at upstream callback invocation. Matches preserve their
519
+ * relative order; non-matches produce no output. No buffer is added and every
520
+ * input callback is unchanged.
521
+ *
522
+ * @remarks
523
+ * ## Why
524
+ *
525
+ * Restrict observed events without restricting which commands the Push accepts.
526
+ *
527
+ * ## Ownership and lifetime
528
+ *
529
+ * The predicate is synchronous at upstream `onSuccess` invocation and
530
+ * resource-free. Subscription, interruption, failures, services, and cleanup
531
+ * remain those of the wrapped Fx.
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * import { Effect } from "effect"
536
+ * import * as Fx from "@typed/fx/Fx"
537
+ * import * as Push from "@typed/fx/Push"
538
+ * import * as Sink from "@typed/fx/Sink"
539
+ *
540
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.fromIterable([1, 2, 3]))
541
+ * const even = Push.filter(push, (n) => n % 2 === 0)
542
+ * ```
543
+ *
544
+ * @since 1.0.0
545
+ * @category Selecting outputs
546
+ */
163
547
  export const filter = dual(2, function filter(push, f) {
164
548
  return make(push, Fx.filter(push, f));
165
549
  });
550
+ /**
551
+ * Effectfully decides which Fx output values are emitted.
552
+ *
553
+ * Each upstream value runs one predicate. `true` emits that value, `false` emits
554
+ * none, and predicate failures join the output error channel. For a sequential
555
+ * source the predicate is acknowledged before the next delivery, preserving
556
+ * order; the input side is unchanged.
557
+ *
558
+ * @remarks
559
+ * ## Why
560
+ *
561
+ * Use this when an observed event needs an Effect service or fallible check before
562
+ * it is visible downstream.
563
+ *
564
+ * ## Ownership and lifetime
565
+ *
566
+ * Predicate effects run inside and are interrupted with the output subscription.
567
+ * Their `E3` failures and `R3` services join the Fx channels. No separate queue or
568
+ * persistent fiber is introduced.
569
+ *
570
+ * @example
571
+ * ```ts
572
+ * import { Effect } from "effect"
573
+ * import * as Fx from "@typed/fx/Fx"
574
+ * import * as Push from "@typed/fx/Push"
575
+ * import * as Sink from "@typed/fx/Sink"
576
+ *
577
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.fromIterable([1, 2]))
578
+ * const positive = Push.filterEffect(push, (n) => Effect.succeed(n > 0))
579
+ * ```
580
+ *
581
+ * @since 1.0.0
582
+ * @category Selecting outputs
583
+ */
166
584
  export const filterEffect = dual(2, function filterEffect(push, f) {
167
585
  return make(push, Fx.filterEffect(push, f));
168
586
  });
587
+ /**
588
+ * Maps each Fx output and emits only resulting `Some` values.
589
+ *
590
+ * The upstream Sink evaluates `f` synchronously for each value, before its
591
+ * returned downstream callback Effect runs. Mapping allocation and throws occur
592
+ * at that callback invocation. `Some(c)` emits exactly one `c`; `None` emits
593
+ * nothing. Relative order, errors, services, and input behavior are preserved.
594
+ *
595
+ * @remarks
596
+ * ## Why
597
+ *
598
+ * Combine output parsing and filtering without a sentinel value or a second pass.
599
+ *
600
+ * ## Ownership and lifetime
601
+ *
602
+ * The mapper is synchronous at upstream `onSuccess` invocation and resource-free.
603
+ * The wrapped Fx retains ownership of subscription, Scope, interruption, and
604
+ * finalizers.
605
+ *
606
+ * @example
607
+ * ```ts
608
+ * import { Effect, Option } from "effect"
609
+ * import * as Fx from "@typed/fx/Fx"
610
+ * import * as Push from "@typed/fx/Push"
611
+ * import * as Sink from "@typed/fx/Sink"
612
+ *
613
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.fromIterable(["1", "x"]))
614
+ * const numbers = Push.filterMap(push, (text) => /^\d+$/.test(text) ? Option.some(Number(text)) : Option.none())
615
+ * ```
616
+ *
617
+ * @since 1.0.0
618
+ * @category Selecting outputs
619
+ */
169
620
  export const filterMap = dual(2, function filterMap(push, f) {
170
621
  return make(push, Fx.filterMap(push, f));
171
622
  });
623
+ /**
624
+ * Effectfully maps each Fx output and emits only resulting `Some` values.
625
+ *
626
+ * One mapper Effect runs per upstream value. `Some(c)` emits once, `None` emits
627
+ * nothing, and failures join the output error channel. Sequential sources retain
628
+ * order; the input Sink remains unchanged.
629
+ *
630
+ * @remarks
631
+ * ## Why
632
+ *
633
+ * This models service-backed lookup where absence is an ordinary filtered result
634
+ * but operational failure must remain observable.
635
+ *
636
+ * ## Ownership and lifetime
637
+ *
638
+ * Mapper effects are owned and interrupted by the output subscription. Their
639
+ * services join `R2` and failures join `E2`; the combinator adds no independent
640
+ * buffer or resource.
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * import { Effect, Option } from "effect"
645
+ * import * as Fx from "@typed/fx/Fx"
646
+ * import * as Push from "@typed/fx/Push"
647
+ * import * as Sink from "@typed/fx/Sink"
648
+ *
649
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.succeed("one"))
650
+ * const ids = Push.filterMapEffect(push, (name) => Effect.succeed(name === "one" ? Option.some(1) : Option.none()))
651
+ * ```
652
+ *
653
+ * @since 1.0.0
654
+ * @category Selecting outputs
655
+ */
172
656
  export const filterMapEffect = dual(2, function filterMapEffect(push, f) {
173
657
  return make(push, Fx.filterMapEffect(push, f));
174
658
  });
175
659
  /**
176
- * Transforms each output value into a new `Fx`, switching to the latest inner `Fx` when a new value arrives.
660
+ * Transforms each output value into an inner `Fx`, observing only the latest one.
661
+ *
662
+ * A new outer value interrupts the previous inner fiber before starting the next.
663
+ * Output cardinality is the cardinality of the successive active inners; values
664
+ * from an interrupted inner stop. Outer order determines replacement order, while
665
+ * each active inner preserves its own order. The input Sink is unchanged.
666
+ *
667
+ * @remarks
668
+ * ## Why
669
+ *
670
+ * Latest-wins composition models search, navigation, and other work where a newer
671
+ * request makes the previous result irrelevant.
672
+ *
673
+ * ## Ownership and lifetime
674
+ *
675
+ * Running the result requires `Scope.Scope`. Each inner runs in that Scope and is
676
+ * interrupted on replacement or outer interruption; the last inner is joined
677
+ * before normal completion. Outer and inner errors/services are combined.
177
678
  *
178
679
  * @example
179
680
  * ```ts
180
681
  * import { Effect } from "effect"
682
+ * import * as Fx from "@typed/fx/Fx"
181
683
  * import * as Push from "@typed/fx/Push"
182
- * import { Fx } from "@typed/fx"
183
684
  * import * as Sink from "@typed/fx/Sink"
184
685
  *
185
- * const program = Effect.gen(function* () {
186
- * const push = Push.make(
187
- * Sink.make(
188
- * (cause) => Effect.void,
189
- * (value) => Effect.void
190
- * ),
191
- * Fx.succeed(1)
686
+ * const finalized: Array<number> = []
687
+ * const outer = Fx.make<number>((sink) =>
688
+ * sink.onSuccess(1).pipe(
689
+ * Effect.andThen(Effect.sleep("5 millis")),
690
+ * Effect.andThen(sink.onSuccess(2))
192
691
  * )
193
- *
194
- * // Switch to a new Fx for each value
195
- * const switched = Push.switchMap(push, (n) =>
196
- * Fx.fromIterable([n, n * 2, n * 3])
692
+ * )
693
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), outer)
694
+ * const switched = Push.switchMap(push, (id) =>
695
+ * Fx.make<number>((sink) =>
696
+ * Effect.gen(function* () {
697
+ * yield* Effect.sleep("2 millis")
698
+ * yield* sink.onSuccess(id * 10 + 1)
699
+ * yield* Effect.sleep(id === 1 ? "20 millis" : "2 millis")
700
+ * yield* sink.onSuccess(id * 10 + 2)
701
+ * }).pipe(Effect.ensuring(Effect.sync(() => finalized.push(id))))
197
702
  * )
198
- *
199
- * // Only the latest Fx's values are emitted
200
- * yield* Fx.observe(switched, (value) =>
201
- * Effect.sync(() => console.log(value))
202
- * )
203
- * })
703
+ * )
704
+ * const program = Fx.collectAll(switched).pipe(
705
+ * Effect.map((values) => ({ values, finalized })),
706
+ * Effect.scoped
707
+ * )
708
+ * // Effect.runPromise(program) => { values: [11, 21, 22], finalized: [1, 2] }
204
709
  * ```
205
710
  *
206
711
  * @since 1.0.0
207
- * @category combinators
712
+ * @category Concurrent output work
208
713
  */
209
714
  export const switchMap = dual(2, function switchMap(push, f) {
210
715
  return make(push, Fx.switchMap(push, f));
211
716
  });
212
- export const switchMapEffect = dual(2, function switchMapEffect(push, f) {
213
- return make(push, Fx.switchMapEffect(push, f));
214
- });
215
717
  /**
216
- * Transforms each output value into a new `Fx` and merges all inner `Fx` values concurrently.
718
+ * Transforms each output value into an Effect, keeping only the latest Effect.
719
+ *
720
+ * Each new outer value interrupts the previous Effect before starting its own.
721
+ * Every Effect can emit at most one value; interrupted Effects emit none. The
722
+ * input side is unchanged.
723
+ *
724
+ * @remarks
725
+ * ## Why
726
+ *
727
+ * This is latest-wins Effect composition without manually wrapping each Effect as
728
+ * an Fx.
729
+ *
730
+ * ## Ownership and lifetime
731
+ *
732
+ * The output subscription's Scope owns the active Effect fiber. Replacement and
733
+ * subscription interruption run its interruption/finalizers. `E3` joins output
734
+ * errors and `R3` joins required services.
217
735
  *
218
736
  * @example
219
737
  * ```ts
220
738
  * import { Effect } from "effect"
739
+ * import * as Fx from "@typed/fx/Fx"
221
740
  * import * as Push from "@typed/fx/Push"
222
- * import { Fx } from "@typed/fx"
223
741
  * import * as Sink from "@typed/fx/Sink"
224
742
  *
225
- * const program = Effect.gen(function* () {
226
- * const push = Push.make(
227
- * Sink.make(
228
- * (cause) => Effect.void,
229
- * (value) => Effect.void
230
- * ),
231
- * Fx.succeed(1)
743
+ * const finalized: Array<number> = []
744
+ * const source = Fx.make<number>((sink) =>
745
+ * sink.onSuccess(1).pipe(
746
+ * Effect.andThen(Effect.sleep("2 millis")),
747
+ * Effect.andThen(sink.onSuccess(2))
232
748
  * )
233
- *
234
- * // FlatMap merges all inner Fx values
235
- * const flattened = Push.flatMap(push, (n) =>
236
- * Fx.fromIterable([n, n * 2, n * 3])
749
+ * )
750
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), source)
751
+ * const latest = Push.switchMapEffect(push, (id) =>
752
+ * Effect.sleep(id === 1 ? "20 millis" : "1 millis").pipe(
753
+ * Effect.as(id),
754
+ * Effect.ensuring(Effect.sync(() => finalized.push(id)))
237
755
  * )
756
+ * )
757
+ * const program = Fx.collectAll(latest).pipe(
758
+ * Effect.map((values) => ({ values, finalized })),
759
+ * Effect.scoped
760
+ * )
761
+ * // Effect.runPromise(program) => { values: [2], finalized: [1, 2] }
762
+ * ```
238
763
  *
239
- * // All values from all inner Fx are emitted
240
- * yield* Fx.observe(flattened, (value) =>
241
- * Effect.sync(() => console.log(value))
764
+ * @since 1.0.0
765
+ * @category Concurrent output work
766
+ */
767
+ export const switchMapEffect = dual(2, function switchMapEffect(push, f) {
768
+ return make(push, Fx.switchMapEffect(push, f));
769
+ });
770
+ /**
771
+ * Transforms each output value into an inner `Fx` and merges all inners concurrently.
772
+ *
773
+ * Every outer value starts one inner. All inner values are emitted; order within
774
+ * each inner is preserved, but values from different inners may interleave. The
775
+ * outer stream waits for all inners before normal completion. The input Sink is
776
+ * unchanged.
777
+ *
778
+ * @remarks
779
+ * ## Why
780
+ *
781
+ * Use concurrent flattening when every produced task matters and independent work
782
+ * should overlap.
783
+ *
784
+ * ## Ownership and lifetime
785
+ *
786
+ * The output Scope owns a fiber set containing all active inners. Outer
787
+ * interruption interrupts that set and runs inner cleanup. Inner failures and
788
+ * services join the outer Fx channels; no ordering buffer is added.
789
+ *
790
+ * @example
791
+ * ```ts
792
+ * import { Effect } from "effect"
793
+ * import * as Fx from "@typed/fx/Fx"
794
+ * import * as Push from "@typed/fx/Push"
795
+ * import * as Sink from "@typed/fx/Sink"
796
+ *
797
+ * const finalized: Array<number> = []
798
+ * const push = Push.make(
799
+ * Sink.make(() => Effect.void, (_: string) => Effect.void),
800
+ * Fx.fromIterable([1, 2])
801
+ * )
802
+ * const merged = Push.flatMap(push, (id) =>
803
+ * Fx.make<number>((sink) =>
804
+ * Effect.gen(function* () {
805
+ * yield* Effect.sleep(id === 1 ? "5 millis" : "10 millis")
806
+ * yield* sink.onSuccess(id * 10 + 1)
807
+ * yield* Effect.sleep("20 millis")
808
+ * yield* sink.onSuccess(id * 10 + 2)
809
+ * }).pipe(Effect.ensuring(Effect.sync(() => finalized.push(id))))
242
810
  * )
243
- * })
811
+ * )
812
+ * const program = Fx.collectAll(merged).pipe(
813
+ * Effect.map((values) => ({ values, finalized })),
814
+ * Effect.scoped
815
+ * )
816
+ * // Effect.runPromise(program) => { values: [11, 21, 12, 22], finalized: [1, 2] }
244
817
  * ```
245
818
  *
246
819
  * @since 1.0.0
247
- * @category combinators
820
+ * @category Concurrent output work
248
821
  */
249
822
  export const flatMap = dual(2, function flatMap(push, f) {
250
823
  return make(push, Fx.flatMap(push, f));
251
824
  });
825
+ /**
826
+ * Transforms every output value into an Effect and merges their results concurrently.
827
+ *
828
+ * One Effect starts per outer value and can emit one result. All successful
829
+ * results are emitted, but concurrent completion order may differ from input
830
+ * order. The input side is unchanged.
831
+ *
832
+ * @remarks
833
+ * ## Why
834
+ *
835
+ * This runs independent Effect work concurrently without manually lifting each
836
+ * Effect into Fx.
837
+ *
838
+ * ## Ownership and lifetime
839
+ *
840
+ * Active Effects are fibers owned by the output Scope. Completion waits for all
841
+ * of them; interruption stops them and runs their finalizers. `E3` and `R3` join
842
+ * the output failure and service channels.
843
+ *
844
+ * @example
845
+ * ```ts
846
+ * import { Effect } from "effect"
847
+ * import * as Fx from "@typed/fx/Fx"
848
+ * import * as Push from "@typed/fx/Push"
849
+ * import * as Sink from "@typed/fx/Sink"
850
+ *
851
+ * const finalized: Array<number> = []
852
+ * const push = Push.make(
853
+ * Sink.make(() => Effect.void, (_: string) => Effect.void),
854
+ * Fx.fromIterable([1, 2])
855
+ * )
856
+ * const loaded = Push.flatMapEffect(push, (id) =>
857
+ * Effect.sleep(id === 1 ? "20 millis" : "1 millis").pipe(
858
+ * Effect.as(id),
859
+ * Effect.ensuring(Effect.sync(() => finalized.push(id)))
860
+ * )
861
+ * )
862
+ * const program = Fx.collectAll(loaded).pipe(
863
+ * Effect.map((values) => ({ values, finalized })),
864
+ * Effect.scoped
865
+ * )
866
+ * // Effect.runPromise(program) => { values: [2, 1], finalized: [2, 1] }
867
+ * ```
868
+ *
869
+ * @since 1.0.0
870
+ * @category Concurrent output work
871
+ */
252
872
  export const flatMapEffect = dual(2, function flatMapEffect(push, f) {
253
873
  return make(push, Fx.flatMapEffect(push, f));
254
874
  });
875
+ /**
876
+ * Runs at most one inner Fx and ignores outer values while it is active.
877
+ *
878
+ * The first value seen while idle starts an inner; every value arriving before
879
+ * that inner completes is dropped. `f(value)` is still evaluated and its inner Fx
880
+ * is constructed before the busy check; dropping means the returned Fx is not
881
+ * run. Accepted inners preserve their own order and all values. Input is unchanged.
882
+ *
883
+ * @remarks
884
+ * ## Why
885
+ *
886
+ * Exhaust semantics prevent duplicate work, such as repeated submit clicks, while
887
+ * allowing another request after the active one completes.
888
+ *
889
+ * ## Ownership and lifetime
890
+ *
891
+ * The output Scope owns the active inner fiber, joins it before completion, and
892
+ * interrupts it with the subscription. Inner failures and services join the
893
+ * outer channels; there is no pending-value buffer.
894
+ *
895
+ * @example
896
+ * ```ts
897
+ * import { Effect } from "effect"
898
+ * import * as Fx from "@typed/fx/Fx"
899
+ * import * as Push from "@typed/fx/Push"
900
+ * import * as Sink from "@typed/fx/Sink"
901
+ *
902
+ * const constructed: Array<number> = []
903
+ * const started: Array<number> = []
904
+ * const finalized: Array<number> = []
905
+ * const push = Push.make(
906
+ * Sink.make(() => Effect.void, (_: string) => Effect.void),
907
+ * Fx.fromIterable([1, 2])
908
+ * )
909
+ * const exhausted = Push.exhaustMap(push, (id) => {
910
+ * constructed.push(id)
911
+ * return Fx.make<number>((sink) =>
912
+ * Effect.gen(function* () {
913
+ * yield* Effect.sync(() => started.push(id))
914
+ * yield* Effect.sleep("5 millis")
915
+ * yield* sink.onSuccess(id * 10 + 1)
916
+ * yield* Effect.sleep("5 millis")
917
+ * yield* sink.onSuccess(id * 10 + 2)
918
+ * }).pipe(Effect.ensuring(Effect.sync(() => finalized.push(id))))
919
+ * )
920
+ * })
921
+ * const program = Fx.collectAll(exhausted).pipe(
922
+ * Effect.map((values) => ({ values, constructed, started, finalized })),
923
+ * Effect.scoped
924
+ * )
925
+ * // => { values: [11, 12], constructed: [1, 2], started: [1], finalized: [1] }
926
+ * ```
927
+ *
928
+ * @since 1.0.0
929
+ * @category Concurrent output work
930
+ */
255
931
  export const exhaustMap = dual(2, function exhaustMap(push, f) {
256
932
  return make(push, Fx.exhaustMap(push, f));
257
933
  });
934
+ /**
935
+ * Runs at most one mapped Effect and ignores values while it is active.
936
+ *
937
+ * The first value while idle starts one Effect and can emit one result; all values
938
+ * received before it completes are dropped. The mapping callback is still invoked
939
+ * and constructs an Effect for every value before the busy check; dropped Effects
940
+ * are not run. The input side is unchanged.
941
+ *
942
+ * @remarks
943
+ * ## Why
944
+ *
945
+ * This guards non-overlapping Effect work without manual busy state.
946
+ *
947
+ * ## Ownership and lifetime
948
+ *
949
+ * The output Scope owns and joins the active Effect fiber. Subscription
950
+ * interruption stops it and runs finalizers. Its errors and services join the
951
+ * output channels; no value is buffered for later.
952
+ *
953
+ * @example
954
+ * ```ts
955
+ * import { Effect } from "effect"
956
+ * import * as Fx from "@typed/fx/Fx"
957
+ * import * as Push from "@typed/fx/Push"
958
+ * import * as Sink from "@typed/fx/Sink"
959
+ *
960
+ * const constructed: Array<number> = []
961
+ * const finalized: Array<number> = []
962
+ * const push = Push.make(
963
+ * Sink.make(() => Effect.void, (_: string) => Effect.void),
964
+ * Fx.fromIterable([1, 2])
965
+ * )
966
+ * const saving = Push.exhaustMapEffect(push, (id) => {
967
+ * constructed.push(id)
968
+ * return Effect.sleep("10 millis").pipe(
969
+ * Effect.as(id),
970
+ * Effect.ensuring(Effect.sync(() => finalized.push(id)))
971
+ * )
972
+ * })
973
+ * const program = Fx.collectAll(saving).pipe(
974
+ * Effect.map((values) => ({ values, constructed, finalized })),
975
+ * Effect.scoped
976
+ * )
977
+ * // Effect.runPromise(program) => { values: [1], constructed: [1, 2], finalized: [1] }
978
+ * ```
979
+ *
980
+ * @since 1.0.0
981
+ * @category Concurrent output work
982
+ */
258
983
  export const exhaustMapEffect = dual(2, function exhaustMapEffect(push, f) {
259
984
  return make(push, Fx.exhaustMapEffect(push, f));
260
985
  });
986
+ /**
987
+ * Runs one inner Fx at a time and retains only the latest value received while busy.
988
+ *
989
+ * A value while idle starts immediately. While its inner runs, newer outer values
990
+ * replace a single pending slot. `f(value)` is evaluated and an inner Fx is
991
+ * constructed before every replacement; a superseded pending Fx is never run.
992
+ * After completion, only the latest pending Fx starts. Accepted inners preserve
993
+ * their own order and all values. The input Sink is unchanged.
994
+ *
995
+ * @remarks
996
+ * ## Why
997
+ *
998
+ * This is useful when work must not overlap but the newest requested state must
999
+ * eventually be processed.
1000
+ *
1001
+ * ## Ownership and lifetime
1002
+ *
1003
+ * The output Scope owns one active inner fiber and an in-memory latest slot. It
1004
+ * joins the final inner before completion and interrupts it with the subscription.
1005
+ * Inner failures and services join the output channels.
1006
+ *
1007
+ * @example
1008
+ * ```ts
1009
+ * import { Effect } from "effect"
1010
+ * import * as Fx from "@typed/fx/Fx"
1011
+ * import * as Push from "@typed/fx/Push"
1012
+ * import * as Sink from "@typed/fx/Sink"
1013
+ *
1014
+ * const constructed: Array<number> = []
1015
+ * const started: Array<number> = []
1016
+ * const finalized: Array<number> = []
1017
+ * const push = Push.make(
1018
+ * Sink.make(() => Effect.void, (_: string) => Effect.void),
1019
+ * Fx.fromIterable([1, 2, 3])
1020
+ * )
1021
+ * const latest = Push.exhaustLatestMap(push, (id) => {
1022
+ * constructed.push(id)
1023
+ * return Fx.make<number>((sink) =>
1024
+ * Effect.gen(function* () {
1025
+ * yield* Effect.sync(() => started.push(id))
1026
+ * yield* Effect.sleep("5 millis")
1027
+ * yield* sink.onSuccess(id * 10 + 1)
1028
+ * yield* Effect.sleep("5 millis")
1029
+ * yield* sink.onSuccess(id * 10 + 2)
1030
+ * }).pipe(Effect.ensuring(Effect.sync(() => finalized.push(id))))
1031
+ * )
1032
+ * })
1033
+ * const program = Fx.collectAll(latest).pipe(
1034
+ * Effect.map((values) => ({ values, constructed, started, finalized })),
1035
+ * Effect.scoped
1036
+ * )
1037
+ * // => values [11, 12, 31, 32]; constructed [1, 2, 3]; started/finalized [1, 3].
1038
+ * ```
1039
+ *
1040
+ * @since 1.0.0
1041
+ * @category Concurrent output work
1042
+ */
261
1043
  export const exhaustLatestMap = dual(2, function exhaustLatestMap(push, f) {
262
1044
  return make(push, Fx.exhaustLatestMap(push, f));
263
1045
  });
1046
+ /**
1047
+ * Runs one mapped Effect at a time and retains only the latest value received while busy.
1048
+ *
1049
+ * Each accepted Effect can emit one result. While it runs, one pending Effect is
1050
+ * repeatedly overwritten; after completion only the latest pending Effect starts.
1051
+ * The mapping callback still runs and constructs an Effect for every value before
1052
+ * replacement; superseded Effects are not run. The input side is unchanged.
1053
+ *
1054
+ * @remarks
1055
+ * ## Why
1056
+ *
1057
+ * This provides non-overlapping Effect work with eventual latest-state handling,
1058
+ * avoiding an unbounded queue of obsolete requests.
1059
+ *
1060
+ * ## Ownership and lifetime
1061
+ *
1062
+ * The output Scope owns the active Effect fiber and pending slot. It waits for the
1063
+ * final Effect, interrupts it with the subscription, and runs its finalizers.
1064
+ * Effect failures and services join the output channels.
1065
+ *
1066
+ * @example
1067
+ * ```ts
1068
+ * import { Effect } from "effect"
1069
+ * import * as Fx from "@typed/fx/Fx"
1070
+ * import * as Push from "@typed/fx/Push"
1071
+ * import * as Sink from "@typed/fx/Sink"
1072
+ *
1073
+ * const constructed: Array<number> = []
1074
+ * const finalized: Array<number> = []
1075
+ * const push = Push.make(
1076
+ * Sink.make(() => Effect.void, (_: string) => Effect.void),
1077
+ * Fx.fromIterable([1, 2, 3])
1078
+ * )
1079
+ * const latestSaved = Push.exhaustLatestMapEffect(push, (id) => {
1080
+ * constructed.push(id)
1081
+ * return Effect.sleep("10 millis").pipe(
1082
+ * Effect.as(id),
1083
+ * Effect.ensuring(Effect.sync(() => finalized.push(id)))
1084
+ * )
1085
+ * })
1086
+ * const program = Fx.collectAll(latestSaved).pipe(
1087
+ * Effect.map((values) => ({ values, constructed, finalized })),
1088
+ * Effect.scoped
1089
+ * )
1090
+ * // Effect.runPromise(program) => { values: [1, 3], constructed: [1, 2, 3], finalized: [1, 3] }
1091
+ * ```
1092
+ *
1093
+ * @since 1.0.0
1094
+ * @category Concurrent output work
1095
+ */
264
1096
  export const exhaustLatestMapEffect = dual(2, function exhaustLatestMapEffect(push, f) {
265
1097
  return make(push, Fx.exhaustLatestMapEffect(push, f));
266
1098
  });
1099
+ /**
1100
+ * Maps over the output (Fx) side of a `Push` with an accumulator: for each emitted value `b`,
1101
+ * applies `f(state, b)` to get `[nextState, emitted]` and emits the second element.
1102
+ * The first element is the initial state; subsequent states are updated by each step.
1103
+ * It emits exactly one `C` per upstream value, in order. Accumulator state is
1104
+ * private to each output subscription; the input Sink is unchanged.
1105
+ *
1106
+ * @remarks
1107
+ * ## Why
1108
+ *
1109
+ * Stateful output projection can derive running totals or protocol state without
1110
+ * moving that state into the bidirectional input boundary.
1111
+ *
1112
+ * ## Ownership and lifetime
1113
+ *
1114
+ * Each run owns its own synchronous accumulator. It is discarded when that run
1115
+ * completes or is interrupted and acquires no Scope or external resource.
1116
+ *
1117
+ * @example
1118
+ * ```ts
1119
+ * import { Effect } from "effect"
1120
+ * import * as Fx from "@typed/fx/Fx"
1121
+ * import * as Push from "@typed/fx/Push"
1122
+ * import * as Sink from "@typed/fx/Sink"
1123
+ *
1124
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.fromIterable([1, 2, 3]))
1125
+ * const totals = Push.mapAccum(push, 0, (total, value) => [total + value, total + value] as const)
1126
+ * ```
1127
+ *
1128
+ * @param initial - Initial accumulator state.
1129
+ * @param f - Reducer `(state, value) => [nextState, emitted]`.
1130
+ * @returns A `Push` whose Fx side emits the accumulated/mapped values.
1131
+ * @since 1.0.0
1132
+ * @category Stateful outputs
1133
+ */
1134
+ export const mapAccum = dual(3, function mapAccum(push, initial, f) {
1135
+ return make(push, Fx.make((sink) => push.run(Sink.loop(sink, initial, (s, b) => {
1136
+ const [sNext, c] = f(s, b);
1137
+ return [c, sNext];
1138
+ }))));
1139
+ });
1140
+ /**
1141
+ * Maps over the output (Fx) side of a `Push` with an effectful accumulator: for each emitted value `b`,
1142
+ * runs `f(state, b)` to get `[nextState, emitted]` and emits the second element.
1143
+ * The adapter does not serialize callbacks. Calling `onSuccess` invokes `f`
1144
+ * immediately with the current seed and constructs its Effect; overlapping calls
1145
+ * can therefore observe the same seed. Successful completion commits the returned
1146
+ * seed and emits in completion order, so later completion may overwrite newer
1147
+ * state. Reducer failure is sent to the output Sink, emits nothing, restores that
1148
+ * call's previous seed, and completes normally so a continuing producer can send
1149
+ * later values. The input Sink is unchanged.
1150
+ *
1151
+ * @remarks
1152
+ * ## Why
1153
+ *
1154
+ * Use an effectful accumulator when each transition needs services or can fail,
1155
+ * while keeping state local to observation rather than global application state.
1156
+ *
1157
+ * ## Ownership and lifetime
1158
+ *
1159
+ * Each output run owns one mutable seed, but concurrent producer callbacks may
1160
+ * race over it; callers needing serialized state transitions must serialize the
1161
+ * upstream deliveries. Each callback fiber runs and interrupts its own reducer
1162
+ * Effect. `E3` and `R3` join the output channels. State is discarded when the
1163
+ * subscription ends.
1164
+ *
1165
+ * @example
1166
+ * ```ts
1167
+ * import { Effect } from "effect"
1168
+ * import * as Fx from "@typed/fx/Fx"
1169
+ * import * as Push from "@typed/fx/Push"
1170
+ * import * as Sink from "@typed/fx/Sink"
1171
+ *
1172
+ * const concurrent = Fx.make<number>((sink) =>
1173
+ * Effect.all([sink.onSuccess(1), sink.onSuccess(2)], {
1174
+ * concurrency: "unbounded",
1175
+ * discard: true
1176
+ * })
1177
+ * )
1178
+ * const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), concurrent)
1179
+ * const totals = Push.mapAccumEffect(push, 0, (seed, value) =>
1180
+ * Effect.sleep(value === 1 ? "20 millis" : "1 millis").pipe(
1181
+ * Effect.as([seed + value, seed + value] as const)
1182
+ * )
1183
+ * )
1184
+ * const program = Fx.collectAll(totals).pipe(Effect.scoped)
1185
+ * // Both reducers see seed 0; Effect.runPromise(program) resolves to [2, 1].
1186
+ *
1187
+ * const values: Array<number> = []
1188
+ * let failures = 0
1189
+ * const sequential = Push.make(
1190
+ * Sink.make(() => Effect.void, (_: string) => Effect.void),
1191
+ * Fx.fromIterable([1, 2, 3])
1192
+ * )
1193
+ * const continued = Push.mapAccumEffect(sequential, 0, (seed, value) =>
1194
+ * value === 2
1195
+ * ? Effect.fail("rejected" as const)
1196
+ * : Effect.succeed([seed + value, seed + value] as const)
1197
+ * )
1198
+ * const recovery = continued.run(Sink.make(
1199
+ * () => Effect.sync(() => { failures += 1 }),
1200
+ * (value) => Effect.sync(() => values.push(value))
1201
+ * ))
1202
+ * // Effect.runPromise(recovery) leaves values [1, 4] and failures 1.
1203
+ * ```
1204
+ *
1205
+ * @param initial - Initial accumulator state.
1206
+ * @param f - Effectful reducer `(state, value) => Effect<[nextState, emitted]>`.
1207
+ * @returns A `Push` whose Fx side emits the accumulated/mapped values.
1208
+ * @since 1.0.0
1209
+ * @category Stateful outputs
1210
+ */
1211
+ export const mapAccumEffect = dual(3, function mapAccumEffect(push, initial, f) {
1212
+ return make(push, Fx.make((sink) => push.run(Sink.filterMapLoopEffect(sink, initial, (s, b) => f(s, b).pipe(Effect.map(([sNext, c]) => [Option.some(c), sNext]), Effect.catchCause((cause) => sink.onFailure(cause).pipe(Effect.as([Option.none(), s]))))))));
1213
+ });
1214
+ /**
1215
+ * Defines a named Effect service whose value is a `Push`.
1216
+ *
1217
+ * The returned class exposes `onSuccess`, `onFailure`, and `run` as Effects that
1218
+ * first resolve the service from Context. `make` captures the Sink construction
1219
+ * context and combines it with each output subscriber's context; it does not start
1220
+ * the Fx or send an input while building the Layer.
1221
+ *
1222
+ * @remarks
1223
+ * ## Why
1224
+ *
1225
+ * A service gives a bidirectional application capability one stable identity, so
1226
+ * producers and observers can depend on it through ordinary Effect requirements.
1227
+ *
1228
+ * ## Ownership and lifetime
1229
+ *
1230
+ * The returned Layer owns service installation and captures non-Scope services
1231
+ * needed by both sides. Output runs retain the caller's Scope and interruption;
1232
+ * input acknowledgment Effects run in their caller. Layer release drops the
1233
+ * service but does not invent cleanup beyond the supplied Sink and Fx.
1234
+ *
1235
+ * @example
1236
+ * ```ts
1237
+ * import { Effect, Layer } from "effect"
1238
+ * import * as Fx from "@typed/fx/Fx"
1239
+ * import * as Push from "@typed/fx/Push"
1240
+ * import * as Sink from "@typed/fx/Sink"
1241
+ *
1242
+ * class Messages extends Push.Service<Messages, string, never, string>()("Messages") {}
1243
+ * const MessagesLive = Messages.make(
1244
+ * Sink.make(() => Effect.void, (message) => Effect.log(message)),
1245
+ * Fx.succeed("ready")
1246
+ * )
1247
+ * const send = Messages.onSuccess("hello").pipe(Effect.provide(MessagesLive))
1248
+ * ```
1249
+ *
1250
+ * @since 1.0.0
1251
+ * @category Push services
1252
+ */
267
1253
  export function Service() {
268
1254
  return (id) => {
269
- const service = ServiceMap.Service(id);
1255
+ const service = Context.Service(id);
270
1256
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
271
1257
  return class PushService {
272
1258
  static id = id;
273
1259
  static service = service;
274
- static make = (sink, fx) => Layer.effect(service, Effect.services().pipe(Effect.map((services) => make(Sink.make((cause) => Effect.provideServices(sink.onFailure(cause), services), (value) => Effect.provideServices(sink.onSuccess(value), services)), Fx.make((sink) => Effect.services().pipe(Effect.flatMap((services2) => Effect.provideServices(fx.run(sink), ServiceMap.merge(services, services2)))))))));
1260
+ static make = (sink, fx) => Layer.effect(service, Effect.context().pipe(Effect.map((services) => make(Sink.make((cause) => Effect.provideContext(sink.onFailure(cause), services), (value) => Effect.provideContext(sink.onSuccess(value), services)), Fx.make((sink) => Effect.context().pipe(Effect.flatMap((services2) => Effect.provideContext(fx.run(sink), Context.merge(services, services2)))))))));
275
1261
  static [FxTypeId] = VARIANCE;
276
1262
  static pipe = function () {
277
1263
  return pipeArguments(this, arguments);
278
1264
  };
279
1265
  // Fx methods
280
- static run = (sink) => Effect.flatMap(service.asEffect(), (push) => push.run(sink));
1266
+ static run = (sink) => Effect.flatMap(service, (push) => push.run(sink));
281
1267
  // Sink methods
282
- static onSuccess = (value) => Effect.flatMap(service.asEffect(), (push) => push.onSuccess(value));
283
- static onFailure = (cause) => Effect.flatMap(service.asEffect(), (push) => push.onFailure(cause));
1268
+ static onSuccess = (value) => Effect.flatMap(service, (push) => push.onSuccess(value));
1269
+ static onFailure = (cause) => Effect.flatMap(service, (push) => push.onFailure(cause));
284
1270
  constructor() {
285
1271
  return PushService;
286
1272
  }