@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
@@ -1,2545 +0,0 @@
1
- /** @effect-diagnostics missingEffectError:skip-file */
2
- /** @effect-diagnostics missingEffectContext:skip-file */
3
-
4
- import * as Array from "effect/Array";
5
- import type * as Cause from "effect/Cause";
6
- import * as Effect from "effect/Effect";
7
- import { equals } from "effect/Equal";
8
- import type { Equivalence } from "effect/Equivalence";
9
- import * as Exit from "effect/Exit";
10
- import * as Fiber from "effect/Fiber";
11
- import { dual, identity } from "effect/Function";
12
- import * as Layer from "effect/Layer";
13
- import * as MutableRef from "effect/MutableRef";
14
- import { sum } from "effect/Number";
15
- import * as Option from "effect/Option";
16
- import { pipeArguments } from "effect/Pipeable";
17
- import * as Scope from "effect/Scope";
18
- import * as ServiceMap from "effect/ServiceMap";
19
- import * as Stream from "effect/Stream";
20
- import { compact as fxCompact } from "../Fx/combinators/compact.js";
21
- import { continueWith } from "../Fx/combinators/continueWith.js";
22
- import { filterMapEffect as fxFilterMapEffect } from "../Fx/combinators/filterMapEffect.js";
23
- import { mapEffect as fxMapEffect } from "../Fx/combinators/mapEffect.js";
24
- import { skipRepeats } from "../Fx/combinators/skipRepeats.js";
25
- import type { Bounds } from "../Fx/combinators/slice.js";
26
- import { slice as fxSlice } from "../Fx/combinators/slice.js";
27
- import { unwrap } from "../Fx/combinators/unwrap.js";
28
- import { fromEffect as fxFromEffect } from "../Fx/constructors/fromEffect.js";
29
- import { fromYieldable } from "../Fx/constructors/fromYieldable.js";
30
- import type { Error as FxError, Fx } from "../Fx/index.js";
31
- import * as DeferredRef from "../Fx/internal/DeferredRef.js";
32
- import { getExitEquivalence } from "../Fx/internal/equivalence.js";
33
- import type { UnionToTuple } from "../Fx/internal/UnionToTuple.js";
34
- import { YieldableFx } from "../Fx/internal/yieldable.js";
35
- import { FxTypeId, isFx } from "../Fx/TypeId.js";
36
- import * as Sink from "../Sink/Sink.js";
37
- import * as Subject from "../Subject/Subject.js";
38
- import * as Versioned from "../Versioned/Versioned.js";
39
-
40
- export const RefSubjectTypeId = Symbol.for("@typed/fx/RefSubject");
41
- export type RefSubjectTypeId = typeof RefSubjectTypeId;
42
-
43
- export const ComputedTypeId = Symbol.for("@typed/fx/Computed");
44
- export type ComputedTypeId = typeof ComputedTypeId;
45
-
46
- export const FilteredTypeId = Symbol.for("@typed/fx/Filtered");
47
- export type FilteredTypeId = typeof FilteredTypeId;
48
-
49
- /**
50
- * A `Computed` is a read-only view of a value that can change over time.
51
- * It is an `Fx` that emits the current value and subsequent updates.
52
- * It is also an `Effect` that samples the current value.
53
- *
54
- * @example
55
- * ```ts
56
- * import { Effect } from "effect"
57
- * import * as RefSubject from "@typed/fx/RefSubject"
58
- * import { Fx } from "@typed/fx"
59
- *
60
- * // Create a RefSubject and derive a Computed from it
61
- * const program = Effect.gen(function* () {
62
- * const count = yield* RefSubject.make(0)
63
- *
64
- * // Create a computed that doubles the count
65
- * const doubled = RefSubject.map(count, (n) => n * 2)
66
- *
67
- * // Sample the computed value
68
- * const value = yield* doubled
69
- * console.log(value) // 0
70
- *
71
- * // Update the source
72
- * yield* RefSubject.set(count, 5)
73
- *
74
- * // The computed automatically reflects the change
75
- * const newValue = yield* doubled
76
- * console.log(newValue) // 10
77
- * })
78
- * ```
79
- *
80
- * @since 1.0.0
81
- * @category models
82
- */
83
- export interface Computed<out A, out E = never, out R = never> extends Versioned.Versioned<
84
- R,
85
- E,
86
- A,
87
- E,
88
- R | Scope.Scope,
89
- A,
90
- E,
91
- R
92
- > {
93
- readonly [ComputedTypeId]: ComputedTypeId;
94
- }
95
-
96
- export declare namespace Computed {
97
- export type Any =
98
- | Computed<any, any, any>
99
- | Computed<never, any, any>
100
- | Computed<any, never, any>
101
- | Computed<never, never, any>;
102
- }
103
-
104
- /**
105
- * A `Filtered` is a `Computed` that may not always have a value.
106
- * It is essentially a `Computed<Option<A>>` with helper methods.
107
- *
108
- * @example
109
- * ```ts
110
- * import { Effect, Option } from "effect"
111
- * import * as RefSubject from "@typed/fx/RefSubject"
112
- *
113
- * // Create a RefSubject and filter it
114
- * const program = Effect.gen(function* () {
115
- * const numbers = yield* RefSubject.make([1, 2, 3, 4, 5])
116
- *
117
- * // Get the first even number (filtered)
118
- * const firstEven = RefSubject.filterMap(
119
- * numbers,
120
- * (arr) => Option.fromNullable(arr.find((n) => n % 2 === 0))
121
- * )
122
- *
123
- * // Try to get the value (may fail with NoSuchElementError)
124
- * const value = yield* firstEven
125
- * console.log(value) // 2
126
- *
127
- * // Or convert back to Option
128
- * const option = firstEven.asComputed()
129
- * const maybeValue = yield* option
130
- * console.log(Option.isSome(maybeValue)) // true
131
- * })
132
- * ```
133
- *
134
- * @since 1.0.0
135
- * @category models
136
- */
137
- export interface Filtered<out A, out E = never, out R = never> extends Versioned.Versioned<
138
- R,
139
- E,
140
- A,
141
- E,
142
- R | Scope.Scope,
143
- A,
144
- E | Cause.NoSuchElementError,
145
- R
146
- > {
147
- readonly [FilteredTypeId]: FilteredTypeId;
148
-
149
- /**
150
- * Converts the Filtered back to a Computed of Option.
151
- *
152
- * @example
153
- * ```ts
154
- * import { Effect, Option } from "effect"
155
- * import * as RefSubject from "@typed/fx/RefSubject"
156
- *
157
- * const program = Effect.gen(function* () {
158
- * const filtered = RefSubject.filterMap(
159
- * yield* RefSubject.make([1, 2, 3]),
160
- * (arr) => Option.fromNullable(arr.find((n) => n > 5))
161
- * )
162
- *
163
- * // Convert to Computed<Option<number>>
164
- * const computed = filtered.asComputed()
165
- * const option = yield* computed
166
- * console.log(Option.isNone(option)) // true (no number > 5)
167
- * })
168
- * ```
169
- */
170
- asComputed(): Computed<Option.Option<A>, E, R>;
171
- }
172
-
173
- export declare namespace Filtered {
174
- export type Any =
175
- | Filtered<any, any, any>
176
- | Filtered<never, any, any>
177
- | Filtered<any, never, any>
178
- | Filtered<never, never, any>;
179
- }
180
-
181
- /**
182
- * Interface for basic RefSubject operations: get, set, delete.
183
- * @since 1.0.0
184
- * @category models
185
- */
186
- export interface GetSetDelete<A, E = never, R = never> {
187
- readonly get: Effect.Effect<A, E, R>;
188
- readonly set: (a: A) => Effect.Effect<A, E, R>;
189
- readonly delete: Effect.Effect<Option.Option<A>, E, R>;
190
- }
191
-
192
- /**
193
- * A `RefSubject` is a mutable reference that can be observed as an Fx.
194
- * It combines the capabilities of a `Ref` (get/set/update) with a `Subject` (subscribe).
195
- *
196
- * @example
197
- * ```ts
198
- * import { Effect } from "effect"
199
- * import * as RefSubject from "@typed/fx/RefSubject"
200
- * import { Fx } from "@typed/fx"
201
- *
202
- * // Create a RefSubject with an initial value
203
- * const program = Effect.gen(function* () {
204
- * const count = yield* RefSubject.make(0)
205
- *
206
- * // Get the current value
207
- * const current = yield* count
208
- * console.log(current) // 0
209
- *
210
- * // Update the value
211
- * yield* RefSubject.set(count, 5)
212
- * const updated = yield* count
213
- * console.log(updated) // 5
214
- *
215
- * // Use as an Fx to observe changes
216
- * yield* Fx.observe(
217
- * count,
218
- * (value) => Effect.sync(() => console.log("Count changed:", value))
219
- * )
220
- *
221
- * // Increment
222
- * yield* RefSubject.increment(count)
223
- * // Output: "Count changed: 6"
224
- * })
225
- * ```
226
- *
227
- * @since 1.0.0
228
- * @category models
229
- */
230
- export interface RefSubject<A, E = never, R = never>
231
- extends Computed<A, E, R>, Subject.Subject<A, E, R> {
232
- readonly [RefSubjectTypeId]: RefSubjectTypeId;
233
-
234
- /**
235
- * Runs an effect that can modify the RefSubject transactionally.
236
- * All operations within the transaction are atomic and serialized.
237
- *
238
- * @example
239
- * ```ts
240
- * import { Effect } from "effect"
241
- * import * as RefSubject from "@typed/fx/RefSubject"
242
- *
243
- * const program = Effect.gen(function* () {
244
- * const balance = yield* RefSubject.make(100)
245
- *
246
- * // Transfer money atomically
247
- * yield* balance.updates((ref) =>
248
- * Effect.gen(function* () {
249
- * const current = yield* ref.get
250
- * if (current >= 50) {
251
- * yield* ref.set(current - 50)
252
- * return "Transfer successful"
253
- * }
254
- * return "Insufficient funds"
255
- * })
256
- * )
257
- * })
258
- * ```
259
- */
260
- readonly updates: <B, E2, R2>(
261
- f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>,
262
- ) => Effect.Effect<B, E | E2, R | R2>;
263
-
264
- /**
265
- * Interrupts the RefSubject, stopping all subscriptions and cleaning up resources.
266
- *
267
- * @example
268
- * ```ts
269
- * import { Effect } from "effect"
270
- * import * as RefSubject from "@typed/fx/RefSubject"
271
- *
272
- * const program = Effect.gen(function* () {
273
- * const ref = yield* RefSubject.make(0)
274
- *
275
- * // Later, clean up
276
- * yield* ref.interrupt
277
- * })
278
- * ```
279
- */
280
- readonly interrupt: Effect.Effect<void, never, R>;
281
- }
282
-
283
- export declare namespace RefSubject {
284
- export type Any =
285
- | RefSubject<any, any, any>
286
- | RefSubject<any, any>
287
- | RefSubject<any, never, any>
288
- | RefSubject<any>;
289
-
290
- export interface Service<Self, Id extends string, A, E> extends RefSubject<A, E, Self> {
291
- readonly id: Id;
292
-
293
- readonly service: ServiceMap.Service<Self, RefSubject<A, E>>;
294
-
295
- readonly make: <R = never>(
296
- value: A | Effect.Effect<A, E, R> | Fx<A, E, R>,
297
- options?: RefSubjectOptions<A> & { readonly skip?: number; readonly take?: number },
298
- ) => Layer.Layer<Self, never, Exclude<R, Scope.Scope>>;
299
-
300
- readonly layer: <E2, R2>(
301
- make: Effect.Effect<RefSubject<A, E>, E2, R2 | Scope.Scope>,
302
- ) => Layer.Layer<Self, E2, Exclude<R2, Scope.Scope>>;
303
- }
304
-
305
- export interface Class<Self, Id extends string, A, E> extends RefSubject.Service<Self, Id, A, E> {
306
- new (): RefSubject.Service<Self, Id, A, E>;
307
- }
308
- }
309
- export const CurrentComputedBehavior = ServiceMap.Reference("@typed/fx/CurrentComputedBehavior", {
310
- defaultValue: (): "one" | "multiple" => "multiple",
311
- });
312
-
313
- const checkIsMultiple = (
314
- ctx: ServiceMap.ServiceMap<any>,
315
- ): ctx is ServiceMap.ServiceMap<"multiple"> =>
316
- ServiceMap.getReferenceUnsafe(ctx, CurrentComputedBehavior) === "multiple";
317
-
318
- class ComputedImpl<R0, E0, A, E, R, E2, R2, C, E3, R3>
319
- extends Versioned.VersionedTransform<
320
- R0,
321
- E0,
322
- A,
323
- E,
324
- R,
325
- A,
326
- E2,
327
- R2,
328
- C,
329
- E0 | E | E2 | E3,
330
- R0 | Exclude<R, Scope.Scope> | R2 | R3 | Scope.Scope,
331
- C,
332
- E0 | E | E2 | E3,
333
- R0 | Exclude<R, Scope.Scope> | R2 | R3
334
- >
335
- implements Computed<C, E0 | E | E2 | E3, R0 | Exclude<R, Scope.Scope> | R2 | R3>
336
- {
337
- readonly [ComputedTypeId]: ComputedTypeId = ComputedTypeId;
338
- private _computed: Fx<C, E0 | E | E2 | E3, R0 | R | Scope.Scope | R2 | R3>;
339
-
340
- override input: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>;
341
- readonly f: (a: A) => Effect.Effect<C, E3, R3>;
342
-
343
- constructor(
344
- input: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
345
- f: (a: A) => Effect.Effect<C, E3, R3>,
346
- ) {
347
- super(input, (fx) => fxMapEffect(fx, f) as any, Effect.flatMap(f));
348
-
349
- this.input = input;
350
- this.f = f;
351
-
352
- this._computed = Subject.hold(
353
- unwrap(
354
- Effect.map(Effect.services(), (ctx) => {
355
- if (checkIsMultiple(ctx)) {
356
- return fromYieldable(input).pipe(
357
- continueWith(() => input),
358
- skipRepeats,
359
- fxMapEffect(f),
360
- );
361
- }
362
-
363
- return fxFromEffect(Effect.flatMap(input.asEffect(), f));
364
- }),
365
- ),
366
- );
367
- }
368
-
369
- override run<RSink>(sink: Sink.Sink<C, E0 | E | E2 | E3, RSink>) {
370
- return this._computed.run(sink) as any;
371
- }
372
- }
373
-
374
- export function makeComputed<R0, E0, A, E, R, E2, R2, C, E3, R3>(
375
- input: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
376
- f: (a: A) => Effect.Effect<C, E3, R3>,
377
- ): Computed<C, E0 | E | E2 | E3, R0 | R2 | R3 | Exclude<R, Scope.Scope>> {
378
- return new ComputedImpl(input, f);
379
- }
380
-
381
- export function makeFiltered<R0, E0, A, E, R, E2, R2, C, E3, R3>(
382
- input: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
383
- f: (a: A) => Effect.Effect<Option.Option<C>, E3, R3>,
384
- ): Filtered<C, E0 | E | E2 | E3, R0 | Exclude<R, Scope.Scope> | R2 | R3> {
385
- return new FilteredImpl(input, f);
386
- }
387
-
388
- class FilteredImpl<R0, E0, A, E, R, E2, R2, C, E3, R3>
389
- extends Versioned.VersionedTransform<
390
- R0,
391
- E0,
392
- A,
393
- E,
394
- R,
395
- A,
396
- E2,
397
- R2,
398
- C,
399
- E0 | E | E2 | E3,
400
- R0 | Exclude<R, Scope.Scope> | R2 | R3 | Scope.Scope,
401
- C,
402
- E0 | E | E2 | E3 | Cause.NoSuchElementError,
403
- R0 | Exclude<R, Scope.Scope> | R2 | R3
404
- >
405
- implements Filtered<C, E0 | E | E2 | E3, R0 | Exclude<R, Scope.Scope> | R2 | R3>
406
- {
407
- readonly [FilteredTypeId]: FilteredTypeId = FilteredTypeId;
408
- private _computed: Fx<C, E0 | E | E2 | E3, R0 | R | Scope.Scope | R2 | R3>;
409
-
410
- override input: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>;
411
- readonly f: (a: A) => Effect.Effect<Option.Option<C>, E3, R3>;
412
-
413
- constructor(
414
- input: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
415
- f: (a: A) => Effect.Effect<Option.Option<C>, E3, R3>,
416
- ) {
417
- super(
418
- input,
419
- (fx) => fxFilterMapEffect(fx, f) as any,
420
- (effect) => Effect.flatMap(Effect.flatMap(effect, f), (option) => option.asEffect()),
421
- );
422
-
423
- this.input = input;
424
- this.f = f;
425
-
426
- this._computed = Subject.hold(
427
- unwrap(
428
- Effect.map(Effect.services(), (ctx) => {
429
- if (checkIsMultiple(ctx)) {
430
- return fromYieldable(input).pipe(
431
- continueWith(() => input),
432
- skipRepeats,
433
- fxFilterMapEffect(f),
434
- );
435
- }
436
-
437
- return fxCompact(fxFromEffect(Effect.flatMap(input.asEffect(), f)));
438
- }),
439
- ),
440
- );
441
- }
442
-
443
- override run<RSink>(sink: Sink.Sink<C, E0 | E | E2 | E3, RSink>) {
444
- return this._computed.run(sink) as any;
445
- }
446
-
447
- asComputed(): Computed<
448
- Option.Option<C>,
449
- E0 | E | E2 | E3,
450
- R0 | R2 | R3 | Exclude<R, Scope.Scope>
451
- > {
452
- return new ComputedImpl(this.input, this.f);
453
- }
454
- }
455
-
456
- class RefSubjectCore<A, E, R, R2> {
457
- readonly initial: Effect.Effect<A, E, R>;
458
- readonly subject: Subject.HoldSubjectImpl<A, E>;
459
- readonly services: ServiceMap.ServiceMap<R2>;
460
- readonly scope: Scope.Closeable;
461
- readonly deferredRef: DeferredRef.DeferredRef<E, A>;
462
- readonly semaphore: Effect.Semaphore;
463
- constructor(
464
- initial: Effect.Effect<A, E, R>,
465
- subject: Subject.HoldSubjectImpl<A, E>,
466
- services: ServiceMap.ServiceMap<R2>,
467
- scope: Scope.Closeable,
468
- deferredRef: DeferredRef.DeferredRef<E, A>,
469
- semaphore: Effect.Semaphore,
470
- ) {
471
- this.initial = initial;
472
- this.subject = subject;
473
- this.services = services;
474
- this.scope = scope;
475
- this.deferredRef = deferredRef;
476
- this.semaphore = semaphore;
477
- }
478
-
479
- public _fiber: Fiber.Fiber<A, E> | undefined = undefined;
480
- }
481
-
482
- export interface RefSubjectOptions<A> {
483
- readonly eq?: Equivalence<A>;
484
- }
485
-
486
- function getSetDelete<A, E, R, R2>(
487
- ref: RefSubjectCore<A, E, R, R2>,
488
- ): GetSetDelete<A, E, Exclude<R, R2>> {
489
- return {
490
- get: getOrInitializeCore(ref, false),
491
- set: (a) => setCore(ref, a),
492
- delete: deleteCore(ref),
493
- };
494
- }
495
- class RefSubjectImpl<A, E, R, R2>
496
- extends YieldableFx<A, E, Exclude<R, R2> | Scope.Scope, A, E, Exclude<R, R2>>
497
- implements RefSubject<A, E, Exclude<R, R2>>
498
- {
499
- readonly [ComputedTypeId]: ComputedTypeId = ComputedTypeId;
500
- readonly [RefSubjectTypeId]: RefSubjectTypeId = RefSubjectTypeId;
501
-
502
- readonly version: Effect.Effect<number>;
503
- readonly interrupt: Effect.Effect<void, never, Exclude<R, R2>>;
504
- readonly subscriberCount: Effect.Effect<number, never, Exclude<R, R2>>;
505
-
506
- readonly getSetDelete: GetSetDelete<A, E, Exclude<R, R2>>;
507
-
508
- readonly core: RefSubjectCore<A, E, R, R2>;
509
-
510
- constructor(core: RefSubjectCore<A, E, R, R2>) {
511
- super();
512
-
513
- this.core = core;
514
- this.version = Effect.sync(() => core.deferredRef.version);
515
- this.interrupt = Effect.provide(interruptCore(core), core.services);
516
- this.subscriberCount = Effect.provide(core.subject.subscriberCount, core.services);
517
- this.getSetDelete = getSetDelete(core);
518
-
519
- this.updates = this.updates.bind(this);
520
- this.onSuccess = this.onSuccess.bind(this);
521
- this.onFailure = this.onFailure.bind(this);
522
- }
523
-
524
- run<R3>(
525
- sink: Sink.Sink<A, E, R3>,
526
- ): Effect.Effect<unknown, never, Exclude<R, R2> | R3 | Scope.Scope> {
527
- return Effect.matchCauseEffect(getOrInitializeCore(this.core, true), {
528
- onFailure: (cause) => sink.onFailure(cause),
529
- onSuccess: () => Effect.provide(this.core.subject.run(sink), this.core.services),
530
- });
531
- }
532
-
533
- updates<R3, E3, B>(run: (ref: GetSetDelete<A, E, Exclude<R, R2>>) => Effect.Effect<B, E3, R3>) {
534
- return this.core.semaphore.withPermits(1)(run(this.getSetDelete));
535
- }
536
-
537
- onSuccess(value: A): Effect.Effect<unknown, never, Exclude<R, R2>> {
538
- return setCore(this.core, value);
539
- }
540
-
541
- onFailure(cause: Cause.Cause<E>): Effect.Effect<unknown, never, Exclude<R, R2>> {
542
- return onFailureCore(this.core, cause);
543
- }
544
-
545
- toEffect(): Effect.Effect<A, E, Exclude<R, R2>> {
546
- return getOrInitializeCore(this.core, true);
547
- }
548
- }
549
-
550
- /**
551
- * Creates a new `RefSubject` from a value, `Effect`, or `Fx`.
552
- *
553
- * @example
554
- * ```ts
555
- * import { Effect } from "effect"
556
- * import * as RefSubject from "@typed/fx/RefSubject"
557
- * import { Fx } from "@typed/fx"
558
- *
559
- * // From a plain value
560
- * const program1 = Effect.gen(function* () {
561
- * const ref = yield* RefSubject.make(42)
562
- * const value = yield* ref
563
- * console.log(value) // 42
564
- * })
565
- *
566
- * // From an Effect
567
- * const program2 = Effect.gen(function* () {
568
- * const ref = yield* RefSubject.make(
569
- * Effect.succeed("Hello")
570
- * )
571
- * const value = yield* ref
572
- * console.log(value) // "Hello"
573
- * })
574
- *
575
- * // From an Fx (tracks the latest value)
576
- * const program3 = Effect.gen(function* () {
577
- * const ref = yield* RefSubject.make(
578
- * Fx.fromIterable([1, 2, 3])
579
- * )
580
- * const value = yield* ref
581
- * console.log(value) // 3 (latest value)
582
- * })
583
- * ```
584
- *
585
- * @since 1.0.0
586
- * @category constructors
587
- */
588
- export function make<A, E = never, R = never>(
589
- effect: A | Effect.Effect<A, E, R> | Stream.Stream<A, E, R> | Fx<A, E, R>,
590
- options?: RefSubjectOptions<A>,
591
- ): Effect.Effect<RefSubject<A, E>, never, R | Scope.Scope> {
592
- if (isFx(effect)) {
593
- return fromFx(effect, options);
594
- } else if (Effect.isEffect(effect)) {
595
- return fromEffect(effect, options);
596
- } else if (Stream.isStream(effect)) {
597
- return fromStream(effect, options);
598
- } else {
599
- return fromEffect<A, E, R>(Effect.succeed(effect), options);
600
- }
601
- }
602
-
603
- /**
604
- * Creates a `RefSubject` from an `Effect`.
605
- *
606
- * @example
607
- * ```ts
608
- * import { Effect } from "effect"
609
- * import * as RefSubject from "@typed/fx/RefSubject"
610
- *
611
- * const program = Effect.gen(function* () {
612
- * const ref = yield* RefSubject.fromEffect(
613
- * Effect.succeed("Initial value")
614
- * )
615
- *
616
- * const value = yield* ref
617
- * console.log(value) // "Initial value"
618
- * })
619
- * ```
620
- *
621
- * @since 1.0.0
622
- * @category constructors
623
- */
624
- export function fromEffect<A, E, R>(
625
- effect: Effect.Effect<A, E, R>,
626
- options?: RefSubjectOptions<A>,
627
- ): Effect.Effect<RefSubject<A, E>, never, R | Scope.Scope> {
628
- return Effect.map(makeCore(effect, options), (core) => new RefSubjectImpl(core));
629
- }
630
-
631
- /**
632
- * Creates a `RefSubject` from an `Fx`, tracking the latest emitted value.
633
- *
634
- * @example
635
- * ```ts
636
- * import { Effect } from "effect"
637
- * import * as RefSubject from "@typed/fx/RefSubject"
638
- * import { Fx } from "@typed/fx"
639
- *
640
- * const program = Effect.gen(function* () {
641
- * // Create an Fx that emits multiple values
642
- * const numbers = Fx.fromIterable([1, 2, 3, 4, 5])
643
- *
644
- * // Create a RefSubject that tracks the latest value
645
- * const ref = yield* RefSubject.fromFx(numbers)
646
- *
647
- * // Get the latest value
648
- * const latest = yield* ref
649
- * console.log(latest) // 5
650
- * })
651
- * ```
652
- *
653
- * @since 1.0.0
654
- * @category constructors
655
- */
656
- export function fromFx<A, E, R>(
657
- fx: Fx<A, E, R>,
658
- options?: RefSubjectOptions<A>,
659
- ): Effect.Effect<RefSubject<A, E>, never, R | Scope.Scope> {
660
- return Effect.gen(function* () {
661
- const core = yield* makeDeferredCore<A, E, R>(options);
662
- const ref = new RefSubjectImpl(core);
663
- yield* Effect.forkIn(
664
- fx.run(
665
- Sink.make(
666
- (cause) => onFailureCore(core, cause),
667
- (value) => setCore(core, value),
668
- ),
669
- ),
670
- core.scope,
671
- { startImmediately: true },
672
- );
673
- return ref;
674
- });
675
- }
676
-
677
- export function fromStream<A, E, R>(
678
- stream: Stream.Stream<A, E, R>,
679
- options?: RefSubjectOptions<A>,
680
- ): Effect.Effect<RefSubject<A, E>, never, R | Scope.Scope> {
681
- return Effect.gen(function* () {
682
- const core = yield* makeDeferredCore<A, E, R>(options);
683
- const ref = new RefSubjectImpl(core);
684
- yield* Effect.forkIn(
685
- stream.pipe(
686
- redirectCause(core),
687
- Stream.runForEach((value) => setCore(core, value)),
688
- ),
689
- core.scope,
690
- { startImmediately: true },
691
- );
692
- return ref;
693
- });
694
- }
695
-
696
- function redirectCause<A, E, R>(core: RefSubjectCore<A, E, R, R | Scope.Scope>) {
697
- return Stream.catchCause((cause: Cause.Cause<E>) =>
698
- Stream.unwrap(Effect.as(onFailureCore(core, cause), Stream.empty)),
699
- );
700
- }
701
-
702
- function makeCore<A, E, R>(
703
- initial: Effect.Effect<A, E, R>,
704
- options?: RefSubjectOptions<A>,
705
- deferredRef?: DeferredRef.DeferredRef<E, A>,
706
- ) {
707
- return Effect.gen(function* () {
708
- const services = yield* Effect.services<R | Scope.Scope>();
709
- const scope = yield* Scope.fork(ServiceMap.get(services, Scope.Scope));
710
- const id = yield* Effect.withFiber((fiber) => Effect.succeed(fiber.id));
711
- const subject = new Subject.HoldSubjectImpl<A, E>();
712
- const core = new RefSubjectCore(
713
- initial,
714
- subject,
715
- services,
716
- scope,
717
- deferredRef ??
718
- DeferredRef.unsafeMake(id, getExitEquivalence(options?.eq ?? equals), subject.lastValue),
719
- Effect.makeSemaphoreUnsafe(1),
720
- );
721
- yield* Scope.addFinalizer(scope, core.subject.interrupt);
722
- return core;
723
- });
724
- }
725
-
726
- function makeDeferredCore<A, E = never, R = never>(options?: RefSubjectOptions<A>) {
727
- return Effect.gen(function* () {
728
- const deferredRef = yield* DeferredRef.make<E, A>(getExitEquivalence(options?.eq ?? equals));
729
- return yield* makeCore<A, E, R>(deferredRef.asEffect(), options, deferredRef);
730
- });
731
- }
732
-
733
- function getOrInitializeCore<A, E, R, R2>(
734
- core: RefSubjectCore<A, E, R, R2>,
735
- lockInitialize: boolean,
736
- ): Effect.Effect<A, E, Exclude<R, R2>> {
737
- return Effect.suspend(() => {
738
- if (core._fiber === undefined && Option.isNone(MutableRef.get(core.deferredRef.current))) {
739
- return initializeCoreAndTap(core, lockInitialize);
740
- } else {
741
- return core.deferredRef.asEffect();
742
- }
743
- });
744
- }
745
-
746
- function initializeCoreEffect<A, E, R, R2>(
747
- core: RefSubjectCore<A, E, R, R2>,
748
- lock: boolean,
749
- ): Effect.Effect<Fiber.Fiber<A, E>, never, Exclude<R, R2>> {
750
- const initialize = Effect.onExit(Effect.provide(core.initial, core.services), (exit) =>
751
- Effect.sync(() => {
752
- core._fiber = undefined;
753
- core.deferredRef.done(exit);
754
- }),
755
- );
756
-
757
- return Effect.flatMap(
758
- Effect.forkIn(lock ? core.semaphore.withPermits(1)(initialize) : initialize, core.scope),
759
- (fiber) => Effect.sync(() => (core._fiber = fiber)),
760
- );
761
- }
762
-
763
- function initializeCoreAndTap<A, E, R, R2>(
764
- core: RefSubjectCore<A, E, R, R2>,
765
- lock: boolean,
766
- ): Effect.Effect<A, E, Exclude<R, R2>> {
767
- return Effect.flatMapEager(initializeCoreEffect(core, lock), () =>
768
- tapEventCore(core, core.deferredRef.asEffect()),
769
- );
770
- }
771
-
772
- function setCore<A, E, R, R2>(
773
- core: RefSubjectCore<A, E, R, R2>,
774
- a: A,
775
- ): Effect.Effect<A, never, Exclude<R, R2>> {
776
- return Effect.suspend(() => {
777
- const exit = Exit.succeed(a);
778
-
779
- if (core.deferredRef.done(exit)) {
780
- // If the value changed, send an event
781
- return Effect.as(sendEvent(core, exit), a);
782
- } else {
783
- // Otherwise, just return the current value
784
- return Effect.succeed(a);
785
- }
786
- });
787
- }
788
-
789
- function onFailureCore<A, E, R, R2>(core: RefSubjectCore<A, E, R, R2>, cause: Cause.Cause<E>) {
790
- const exit = Exit.failCause(cause);
791
-
792
- return Effect.suspend(() => {
793
- if (core.deferredRef.done(exit)) {
794
- return sendEvent(core, exit);
795
- } else {
796
- return Effect.void;
797
- }
798
- });
799
- }
800
-
801
- function interruptCore<A, E, R, R2>(
802
- core: RefSubjectCore<A, E, R, R2>,
803
- ): Effect.Effect<void, never, R> {
804
- return Effect.withFiber((fiber) => {
805
- core.deferredRef.reset();
806
-
807
- const closeScope = Scope.close(core.scope, Exit.interrupt(fiber.id));
808
- const interruptFiber = core._fiber ? Fiber.interrupt(core._fiber) : Effect.void;
809
- const interruptSubject = core.subject.interrupt;
810
-
811
- return Effect.all([closeScope, interruptFiber, interruptSubject], { discard: true });
812
- });
813
- }
814
-
815
- function deleteCore<A, E, R, R2>(
816
- core: RefSubjectCore<A, E, R, R2>,
817
- ): Effect.Effect<Option.Option<A>, E, Exclude<R, R2>> {
818
- return Effect.suspend(() => {
819
- const current = MutableRef.get(core.deferredRef.current);
820
- core.deferredRef.reset();
821
-
822
- if (Option.isNone(current)) {
823
- return Effect.succeed(Option.none());
824
- }
825
-
826
- return core.subject.subscriberCount.pipe(
827
- Effect.flatMap((count: number) =>
828
- count > 0 && !core._fiber ? initializeCoreEffect(core, false) : Effect.void,
829
- ),
830
- Effect.flatMap(() => Effect.asSome(current.value)),
831
- );
832
- });
833
- }
834
-
835
- function tapEventCore<A, E, R, R2, R3>(
836
- core: RefSubjectCore<A, E, R, R2>,
837
- effect: Effect.Effect<A, E, R3>,
838
- ) {
839
- return effect.pipe(Effect.onExit((exit) => sendEvent(core, exit)));
840
- }
841
-
842
- function sendEvent<A, E, R, R2>(
843
- core: RefSubjectCore<A, E, R, R2>,
844
- exit: Exit.Exit<A, E>,
845
- ): Effect.Effect<unknown, never, Exclude<R, R2>> {
846
- if (Exit.isSuccess(exit)) {
847
- return core.subject.onSuccess(exit.value);
848
- } else {
849
- return core.subject.onFailure(exit.cause);
850
- }
851
- }
852
-
853
- /**
854
- * Sets the value of a `RefSubject`.
855
- *
856
- * @example
857
- * ```ts
858
- * import { Effect } from "effect"
859
- * import * as RefSubject from "@typed/fx/RefSubject"
860
- *
861
- * const program = Effect.gen(function* () {
862
- * const count = yield* RefSubject.make(0)
863
- *
864
- * // Set the value
865
- * yield* RefSubject.set(count, 10)
866
- * const value = yield* count
867
- * console.log(value) // 10
868
- *
869
- * // Can also use pipe syntax
870
- * yield* count.pipe(RefSubject.set(20))
871
- * const newValue = yield* count
872
- * console.log(newValue) // 20
873
- * })
874
- * ```
875
- *
876
- * @since 1.0.0
877
- * @category combinators
878
- */
879
- export const set: {
880
- <A>(value: A): <E, R>(ref: RefSubject<A, E, R>) => Effect.Effect<A, E, R>;
881
- <A, E, R>(ref: RefSubject<A, E, R>, a: A): Effect.Effect<A, E, R>;
882
- } = dual(2, function set<A, E, R>(ref: RefSubject<A, E, R>, a: A): Effect.Effect<A, E, R> {
883
- return ref.updates((ref) => ref.set(a));
884
- });
885
-
886
- /**
887
- * Resets a `RefSubject` to its initial value, returning the previous value if it existed.
888
- *
889
- * @example
890
- * ```ts
891
- * import { Effect, Option } from "effect"
892
- * import * as RefSubject from "@typed/fx/RefSubject"
893
- *
894
- * const program = Effect.gen(function* () {
895
- * const count = yield* RefSubject.make(0)
896
- *
897
- * yield* RefSubject.set(count, 5)
898
- * const before = yield* count
899
- * console.log(before) // 5
900
- *
901
- * // Reset to initial value
902
- * const previous = yield* RefSubject.reset(count)
903
- * console.log(Option.isSome(previous)) // true
904
- * console.log(previous.value) // 5
905
- *
906
- * const after = yield* count
907
- * console.log(after) // 0
908
- * })
909
- * ```
910
- *
911
- * @since 1.0.0
912
- * @category combinators
913
- */
914
- export function reset<A, E, R>(ref: RefSubject<A, E, R>): Effect.Effect<Option.Option<A>, E, R> {
915
- return ref.updates((ref) => ref.delete);
916
- }
917
-
918
- export {
919
- /**
920
- * Deletes the current value of a `RefSubject`, resetting it to its initial state.
921
- *
922
- * @example
923
- * ```ts
924
- * import { Effect, Option } from "effect"
925
- * import * as RefSubject from "@typed/fx/RefSubject"
926
- *
927
- * const program = Effect.gen(function* () {
928
- * const ref = yield* RefSubject.make(10)
929
- * yield* RefSubject.set(ref, 20)
930
- *
931
- * // Delete the current value
932
- * const deleted = yield* RefSubject.delete(ref)
933
- * console.log(Option.isSome(deleted)) // true
934
- * console.log(deleted.value) // 20
935
- *
936
- * // Value is reset to initial
937
- * const current = yield* ref
938
- * console.log(current) // 10
939
- * })
940
- * ```
941
- *
942
- * @since 1.20.0
943
- * @category combinators
944
- */
945
- reset as delete,
946
- };
947
-
948
- /**
949
- * Updates a `RefSubject` using an `Effect`ful function.
950
- *
951
- * @example
952
- * ```ts
953
- * import { Effect } from "effect"
954
- * import * as RefSubject from "@typed/fx/RefSubject"
955
- *
956
- * const program = Effect.gen(function* () {
957
- * const count = yield* RefSubject.make(5)
958
- *
959
- * // Update with an async operation
960
- * yield* RefSubject.updateEffect(count, (value) =>
961
- * Effect.succeed(value * 2)
962
- * )
963
- *
964
- * const result = yield* count
965
- * console.log(result) // 10
966
- * })
967
- * ```
968
- *
969
- * @since 1.0.0
970
- * @category combinators
971
- */
972
- export const updateEffect: {
973
- <A, E2, R2>(
974
- f: (value: A) => Effect.Effect<A, E2, R2>,
975
- ): <E, R>(ref: RefSubject<A, E, R>) => Effect.Effect<A, E | E2, R | R2>;
976
- <A, E, R, E2, R2>(
977
- ref: RefSubject<A, E, R>,
978
- f: (value: A) => Effect.Effect<A, E2, R2>,
979
- ): Effect.Effect<A, E | E2, R | R2>;
980
- } = dual(2, function updateEffect<
981
- A,
982
- E,
983
- R,
984
- E2,
985
- R2,
986
- >(ref: RefSubject<A, E, R>, f: (value: A) => Effect.Effect<A, E2, R2>) {
987
- return ref.updates((ref) => Effect.flatMap(Effect.flatMap(ref.get, f), ref.set));
988
- });
989
-
990
- /**
991
- * Updates a `RefSubject` using a pure function.
992
- *
993
- * @example
994
- * ```ts
995
- * import { Effect } from "effect"
996
- * import * as RefSubject from "@typed/fx/RefSubject"
997
- *
998
- * const program = Effect.gen(function* () {
999
- * const count = yield* RefSubject.make(5)
1000
- *
1001
- * // Increment by 1
1002
- * yield* RefSubject.update(count, (n) => n + 1)
1003
- * const value = yield* count
1004
- * console.log(value) // 6
1005
- *
1006
- * // Can also use pipe syntax
1007
- * yield* count.pipe(RefSubject.update((n) => n * 2))
1008
- * const doubled = yield* count
1009
- * console.log(doubled) // 12
1010
- * })
1011
- * ```
1012
- *
1013
- * @since 1.0.0
1014
- * @category combinators
1015
- */
1016
- export const update: {
1017
- <A>(f: (value: A) => A): <E, R>(ref: RefSubject<A, E, R>) => Effect.Effect<A, E, R>;
1018
- <A, E, R>(ref: RefSubject<A, E, R>, f: (value: A) => A): Effect.Effect<A, E, R>;
1019
- } = dual(2, function update<A, E, R>(ref: RefSubject<A, E, R>, f: (value: A) => A) {
1020
- return updateEffect(ref, (value) => Effect.succeed(f(value)));
1021
- });
1022
-
1023
- /**
1024
- * Modifies a `RefSubject` using an `Effect`ful function that returns both a result and a new value.
1025
- *
1026
- * @example
1027
- * ```ts
1028
- * import { Effect } from "effect"
1029
- * import * as RefSubject from "@typed/fx/RefSubject"
1030
- *
1031
- * const program = Effect.gen(function* () {
1032
- * const count = yield* RefSubject.make(5)
1033
- *
1034
- * // Get the old value and set a new one, returning the old value
1035
- * const oldValue = yield* RefSubject.modifyEffect(count, (value) =>
1036
- * Effect.succeed([value, value + 10] as const)
1037
- * )
1038
- *
1039
- * console.log(oldValue) // 5
1040
- * const newValue = yield* count
1041
- * console.log(newValue) // 15
1042
- * })
1043
- * ```
1044
- *
1045
- * @since 1.0.0
1046
- * @category combinators
1047
- */
1048
- export const modifyEffect: {
1049
- <A, B, E2, R2>(
1050
- f: (value: A) => Effect.Effect<readonly [B, A], E2, R2>,
1051
- ): <E, R>(ref: RefSubject<A, E, R>) => Effect.Effect<B, E | E2, R | R2>;
1052
- <A, E, R, B, E2, R2>(
1053
- ref: RefSubject<A, E, R>,
1054
- f: (value: A) => Effect.Effect<readonly [B, A], E2, R2>,
1055
- ): Effect.Effect<B, E | E2, R | R2>;
1056
- } = dual(2, function modifyEffect<
1057
- A,
1058
- E,
1059
- R,
1060
- B,
1061
- E2,
1062
- R2,
1063
- >(ref: RefSubject<A, E, R>, f: (value: A) => Effect.Effect<readonly [B, A], E2, R2>) {
1064
- return ref.updates((ref) =>
1065
- Effect.flatMap(ref.get, (value) =>
1066
- Effect.flatMap(f(value), ([b, a]) => Effect.flatMap(ref.set(a), () => Effect.succeed(b))),
1067
- ),
1068
- );
1069
- });
1070
-
1071
- /**
1072
- * Modifies a `RefSubject` using a pure function that returns both a result and a new value.
1073
- *
1074
- * @example
1075
- * ```ts
1076
- * import { Effect } from "effect"
1077
- * import * as RefSubject from "@typed/fx/RefSubject"
1078
- *
1079
- * const program = Effect.gen(function* () {
1080
- * const count = yield* RefSubject.make(5)
1081
- *
1082
- * // Get the old value and increment, returning the old value
1083
- * const oldValue = yield* RefSubject.modify(count, (value) => [value, value + 1] as const)
1084
- *
1085
- * console.log(oldValue) // 5
1086
- * const newValue = yield* count
1087
- * console.log(newValue) // 6
1088
- * })
1089
- * ```
1090
- *
1091
- * @since 1.0.0
1092
- * @category combinators
1093
- */
1094
- export const modify: {
1095
- <A, B>(
1096
- f: (value: A) => readonly [B, A],
1097
- ): <E, R>(ref: RefSubject<A, E, R>) => Effect.Effect<B, E, R>;
1098
- <A, E, R, B>(ref: RefSubject<A, E, R>, f: (value: A) => readonly [B, A]): Effect.Effect<B, E, R>;
1099
- } = dual(2, function modify<
1100
- A,
1101
- E,
1102
- R,
1103
- B,
1104
- >(ref: RefSubject<A, E, R>, f: (value: A) => readonly [B, A]) {
1105
- return modifyEffect(ref, (value) => Effect.succeed(f(value)));
1106
- });
1107
-
1108
- /**
1109
- * Checks if a value is a `RefSubject`.
1110
- *
1111
- * @example
1112
- * ```ts
1113
- * import { Effect } from "effect"
1114
- * import * as RefSubject from "@typed/fx/RefSubject"
1115
- *
1116
- * const program = Effect.gen(function* () {
1117
- * const ref = yield* RefSubject.make(42)
1118
- * const isRef = RefSubject.isRefSubject(ref)
1119
- * console.log(isRef) // true
1120
- *
1121
- * const notRef = { value: 42 }
1122
- * const isNotRef = RefSubject.isRefSubject(notRef)
1123
- * console.log(isNotRef) // false
1124
- * })
1125
- * ```
1126
- *
1127
- * @since 1.0.0
1128
- * @category guards
1129
- */
1130
- export function isRefSubject(value: any): value is RefSubject<any, any, any> {
1131
- return value && typeof value === "object" && value[RefSubjectTypeId] === RefSubjectTypeId;
1132
- }
1133
-
1134
- const isRefSubjectDataFirst = (args: IArguments) => isRefSubject(args[0]);
1135
-
1136
- /**
1137
- * Runs an effect that can modify a `RefSubject` transactionally, with optional interrupt handling.
1138
- *
1139
- * @example
1140
- * ```ts
1141
- * import { Effect } from "effect"
1142
- * import * as RefSubject from "@typed/fx/RefSubject"
1143
- *
1144
- * const program = Effect.gen(function* () {
1145
- * const balance = yield* RefSubject.make(100)
1146
- *
1147
- * // Transfer money atomically with interrupt handling
1148
- * yield* RefSubject.runUpdates(
1149
- * balance,
1150
- * (ref) =>
1151
- * Effect.gen(function* () {
1152
- * const current = yield* ref.get
1153
- * if (current >= 50) {
1154
- * yield* ref.set(current - 50)
1155
- * return "Transfer successful"
1156
- * }
1157
- * return "Insufficient funds"
1158
- * }),
1159
- * {
1160
- * onInterrupt: (value) => Effect.sync(() => console.log(`Interrupted at balance: ${value}`)),
1161
- * value: "initial"
1162
- * }
1163
- * )
1164
- * })
1165
- * ```
1166
- *
1167
- * @since 1.0.0
1168
- * @category combinators
1169
- */
1170
- export const runUpdates: {
1171
- <A, E, R, B, E2, R2, R3 = never, E3 = never, C = never>(
1172
- f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>,
1173
- options?: {
1174
- readonly onInterrupt: (value: A) => Effect.Effect<C, E3, R3>;
1175
- readonly value?: "initial" | "current";
1176
- },
1177
- ): (ref: RefSubject<A, E, R>) => Effect.Effect<B, E | E2 | E3, R | R2 | R3>;
1178
-
1179
- <A, E, R, B, E2, R2, R3 = never, E3 = never, C = never>(
1180
- ref: RefSubject<A, E, R>,
1181
- f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>,
1182
- options?:
1183
- | {
1184
- readonly onInterrupt: (value: A) => Effect.Effect<C, E3, R3>;
1185
- readonly value?: "initial" | "current";
1186
- }
1187
- | undefined,
1188
- ): Effect.Effect<B, E | E2 | E3, R | R2 | R3>;
1189
- } = dual(
1190
- isRefSubjectDataFirst,
1191
- function runUpdates<A, E, R, B, E2, R2, R3 = never, E3 = never, C = never>(
1192
- ref: RefSubject<A, E, R>,
1193
- f: (ref: GetSetDelete<A, E, R>) => Effect.Effect<B, E2, R2>,
1194
- options?: {
1195
- readonly onInterrupt: (value: A) => Effect.Effect<C, E3, R3>;
1196
- readonly value?: "initial" | "current";
1197
- },
1198
- ) {
1199
- if (options === undefined) {
1200
- return ref.updates(f);
1201
- } else if (options.value === "initial") {
1202
- return ref.updates((ref) =>
1203
- Effect.flatMap(ref.get, (initial) =>
1204
- f(ref).pipe(Effect.onInterrupt(() => options.onInterrupt(initial))),
1205
- ),
1206
- );
1207
- } else {
1208
- return ref.updates((ref) =>
1209
- f(ref).pipe(Effect.onInterrupt(() => Effect.flatMap(ref.get, options.onInterrupt))),
1210
- );
1211
- }
1212
- },
1213
- );
1214
-
1215
- /**
1216
- * Increments a numeric `RefSubject` by 1.
1217
- *
1218
- * @example
1219
- * ```ts
1220
- * import { Effect } from "effect"
1221
- * import * as RefSubject from "@typed/fx/RefSubject"
1222
- *
1223
- * const program = Effect.gen(function* () {
1224
- * const count = yield* RefSubject.make(0)
1225
- *
1226
- * yield* RefSubject.increment(count)
1227
- * const value = yield* count
1228
- * console.log(value) // 1
1229
- *
1230
- * yield* RefSubject.increment(count)
1231
- * const newValue = yield* count
1232
- * console.log(newValue) // 2
1233
- * })
1234
- * ```
1235
- *
1236
- * @since 1.0.0
1237
- * @category combinators
1238
- */
1239
- export function increment<E, R>(ref: RefSubject<number, E, R>): Effect.Effect<number, E, R> {
1240
- return update(ref, (value) => value + 1);
1241
- }
1242
-
1243
- /**
1244
- * Decrements a numeric `RefSubject` by 1.
1245
- *
1246
- * @example
1247
- * ```ts
1248
- * import { Effect } from "effect"
1249
- * import * as RefSubject from "@typed/fx/RefSubject"
1250
- *
1251
- * const program = Effect.gen(function* () {
1252
- * const count = yield* RefSubject.make(10)
1253
- *
1254
- * yield* RefSubject.decrement(count)
1255
- * const value = yield* count
1256
- * console.log(value) // 9
1257
- *
1258
- * yield* RefSubject.decrement(count)
1259
- * const newValue = yield* count
1260
- * console.log(newValue) // 8
1261
- * })
1262
- * ```
1263
- *
1264
- * @since 1.0.0
1265
- * @category combinators
1266
- */
1267
- export function decrement<E, R>(ref: RefSubject<number, E, R>): Effect.Effect<number, E, R> {
1268
- return update(ref, (value) => value - 1);
1269
- }
1270
-
1271
- const Variance: Fx.Variance<any, any, any> = {
1272
- _A: identity,
1273
- _E: identity,
1274
- _R: identity,
1275
- };
1276
-
1277
- export function Service<Self, A, E = never>() {
1278
- return <const Id extends string>(id: Id): RefSubject.Class<Self, Id, A, E> => {
1279
- const service = ServiceMap.Service<Self, RefSubject<A, E>>(id);
1280
-
1281
- // eslint-disable-next-line @typescript-eslint/no-extraneous-class
1282
- return class RefSubjectService {
1283
- /// Service
1284
-
1285
- static readonly id = id;
1286
- static readonly service = service;
1287
-
1288
- static readonly layer = <E2, R2>(
1289
- make: Effect.Effect<RefSubject<A, E>, E2, R2 | Scope.Scope>,
1290
- ) => Layer.effect(service, make);
1291
-
1292
- static readonly make = <R = never>(
1293
- value: A | Effect.Effect<A, E, R> | Fx<A, E, R>,
1294
- options?: RefSubjectOptions<A> & Partial<Bounds>,
1295
- ): Layer.Layer<Self, never, R> => {
1296
- const bounds = getDefaultBounds(options);
1297
- return make(value, options).pipe(
1298
- Effect.map((ref) => (bounds ? slice(ref, bounds.skip, bounds.take) : ref)),
1299
- this.layer,
1300
- );
1301
- };
1302
-
1303
- // Fx
1304
- static readonly [FxTypeId]: Fx.Variance<A, E, Self> = Variance;
1305
- static readonly run = <RSink>(sink: Sink.Sink<A, E, RSink>) =>
1306
- Effect.flatMap(service.asEffect(), (ref) => ref.run(sink));
1307
-
1308
- // Sink
1309
- static readonly onSuccess = (value: A) =>
1310
- Effect.flatMap(service.asEffect(), (ref) => ref.onSuccess(value));
1311
- static readonly onFailure = (cause: Cause.Cause<E>) =>
1312
- Effect.flatMap(service.asEffect(), (ref) => ref.onFailure(cause));
1313
-
1314
- /// Computed
1315
- static readonly [ComputedTypeId]: ComputedTypeId = ComputedTypeId;
1316
- static readonly version = Effect.flatMap(service.asEffect(), (ref) => ref.version);
1317
-
1318
- // Subject
1319
- static readonly subscriberCount = Effect.flatMap(
1320
- service.asEffect(),
1321
- (ref) => ref.subscriberCount,
1322
- );
1323
- static readonly interrupt = Effect.flatMap(service.asEffect(), (ref) => ref.interrupt);
1324
-
1325
- // RefSubject
1326
- static readonly [RefSubjectTypeId]: RefSubjectTypeId = RefSubjectTypeId;
1327
- static readonly updates = <B, E2, R2>(
1328
- f: (ref: GetSetDelete<A, E, never>) => Effect.Effect<B, E2, R2>,
1329
- ) => Effect.flatMap(service.asEffect(), (ref) => ref.updates(f));
1330
-
1331
- // Yieldable
1332
- static readonly asEffect = () => Effect.flatMap(service.asEffect(), Effect.fromYieldable);
1333
- static readonly [Symbol.iterator] = function* () {
1334
- const ref = yield* service;
1335
- return yield* ref;
1336
- };
1337
- static readonly pipe: RefSubject.Service<Self, Id, A, E>["pipe"] = function pipe(
1338
- this: RefSubject.Service<Self, Id, A, E>,
1339
- ) {
1340
- return pipeArguments(this, arguments);
1341
- };
1342
-
1343
- constructor() {
1344
- return RefSubjectService;
1345
- }
1346
- } as unknown as RefSubject.Class<Self, Id, A, E>;
1347
- };
1348
- }
1349
-
1350
- function getDefaultBounds(options?: Partial<Bounds>): Bounds | undefined {
1351
- if (options === undefined || (options.skip === undefined && options.take === undefined)) {
1352
- return { skip: 0, take: Infinity };
1353
- }
1354
-
1355
- return { skip: options.skip ?? 0, take: options.take ?? Infinity };
1356
- }
1357
-
1358
- /**
1359
- * Extract all values from an object using a Proxy.
1360
- * Allows accessing nested properties of a `Computed` or `Filtered` object/array as individual computed values.
1361
- *
1362
- * @example
1363
- * ```ts
1364
- * import { Effect } from "effect"
1365
- * import * as RefSubject from "@typed/fx/RefSubject"
1366
- *
1367
- * const program = Effect.gen(function* () {
1368
- * const user = yield* RefSubject.make({ name: "Alice", age: 30 })
1369
- *
1370
- * // Create a proxy to access nested properties
1371
- * const proxied = RefSubject.proxy(user)
1372
- *
1373
- * // Access individual properties as Computed values
1374
- * const name = yield* proxied.name
1375
- * console.log(name) // "Alice"
1376
- *
1377
- * const age = yield* proxied.age
1378
- * console.log(age) // 30
1379
- *
1380
- * // Update the source
1381
- * yield* RefSubject.set(user, { name: "Bob", age: 25 })
1382
- *
1383
- * // Proxied values automatically update
1384
- * const newName = yield* proxied.name
1385
- * console.log(newName) // "Bob"
1386
- * })
1387
- * ```
1388
- *
1389
- * @since 2.0.0
1390
- * @category combinators
1391
- */
1392
- export const proxy: {
1393
- <A extends ReadonlyArray<any> | Readonly<Record<PropertyKey, any>>, E, R>(
1394
- source: Computed<A, E, R>,
1395
- ): { readonly [K in keyof A]: Computed<A[K], E, R> };
1396
-
1397
- <A extends ReadonlyArray<any> | Readonly<Record<PropertyKey, any>>, E, R>(
1398
- source: Filtered<A, E, R>,
1399
- ): { readonly [K in keyof A]: Filtered<A[K], E, R> };
1400
- } = <A extends Readonly<Record<PropertyKey, any>> | ReadonlyArray<any>, E, R>(
1401
- source: Computed<A, E, R> | Filtered<A, E, R>,
1402
- ): any => {
1403
- const target: any = {};
1404
- return new Proxy(target, {
1405
- get(self, prop) {
1406
- if (prop in self) return self[prop];
1407
- return (self[prop] = map(source, (a) => a[prop as keyof A]));
1408
- },
1409
- });
1410
- };
1411
-
1412
- export type Services<T> =
1413
- T extends RefSubject<infer _A, infer _E, infer R>
1414
- ? R
1415
- : T extends Computed<infer _A, infer _E, infer R>
1416
- ? R
1417
- : T extends Filtered<infer _A, infer _E, infer R>
1418
- ? R
1419
- : never;
1420
-
1421
- export type Error<T> =
1422
- T extends RefSubject<infer _A, infer E, infer _R>
1423
- ? E
1424
- : T extends Computed<infer _A, infer E, infer _R>
1425
- ? E
1426
- : T extends Filtered<infer _A, infer E, infer _R>
1427
- ? E
1428
- : never;
1429
-
1430
- export type Success<T> =
1431
- T extends RefSubject<infer A, infer _E, infer _R>
1432
- ? A
1433
- : T extends Computed<infer A, infer _E, infer _R>
1434
- ? A
1435
- : T extends Filtered<infer A, infer _E, infer _R>
1436
- ? A
1437
- : never;
1438
-
1439
- export type Identifier<T> =
1440
- T extends RefSubject.Service<infer R, infer _Id, infer _A, infer _E> ? R : never;
1441
-
1442
- /**
1443
- * Transforms a `RefSubject`, `Computed`, or `Filtered` using an `Effect`ful function.
1444
- *
1445
- * @example
1446
- * ```ts
1447
- * import { Effect } from "effect"
1448
- * import * as RefSubject from "@typed/fx/RefSubject"
1449
- *
1450
- * const program = Effect.gen(function* () {
1451
- * const count = yield* RefSubject.make(5)
1452
- *
1453
- * // Transform with an async operation
1454
- * const doubled = RefSubject.mapEffect(count, (n) =>
1455
- * Effect.succeed(n * 2)
1456
- * )
1457
- *
1458
- * const value = yield* doubled
1459
- * console.log(value) // 10
1460
- *
1461
- * // Update source
1462
- * yield* RefSubject.set(count, 7)
1463
- *
1464
- * // Computed automatically updates
1465
- * const newValue = yield* doubled
1466
- * console.log(newValue) // 14
1467
- * })
1468
- * ```
1469
- *
1470
- * @since 1.0.0
1471
- * @category combinators
1472
- */
1473
- export const mapEffect: {
1474
- <T extends RefSubject.Any | Computed.Any | Filtered.Any, B, E2, R2>(
1475
- f: (a: Success<T>) => Effect.Effect<B, E2, R2>,
1476
- ): (
1477
- ref: T,
1478
- ) => T extends Filtered.Any
1479
- ? Filtered<B, Error<T> | E2, Services<T> | R2>
1480
- : Computed<B, Error<T> | E2, Services<T> | R2>;
1481
-
1482
- <A, E, R, B, E2, R2>(
1483
- ref: RefSubject<A, E, R> | Computed<A, E, R>,
1484
- f: (a: A) => Effect.Effect<B, E2, R2>,
1485
- ): Computed<B, E | E2, R | R2>;
1486
-
1487
- <A, E, R, B, E2, R2>(
1488
- ref: Filtered<A, E, R>,
1489
- f: (a: A) => Effect.Effect<B, E2, R2>,
1490
- ): Filtered<B, E | E2, R | R2>;
1491
-
1492
- <R0, E0, A, E, R, E2, R2, C, E3, R3>(
1493
- versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
1494
- f: (a: A) => Effect.Effect<C, E3, R3>,
1495
- ): Computed<C, E0 | E | E2 | E3, R0 | R2 | R3 | Exclude<R, Scope.Scope>>;
1496
- } = dual(2, function mapEffect<
1497
- R0,
1498
- E0,
1499
- A,
1500
- E,
1501
- R,
1502
- E2,
1503
- R2,
1504
- C,
1505
- E3,
1506
- R3,
1507
- >(versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>, f: (a: A) => Effect.Effect<C, E3, R3>):
1508
- | Computed<C, E0 | E | E2 | E3, R0 | Exclude<R, Scope.Scope> | R2 | R3>
1509
- | Filtered<C, E0 | E | E2 | E3, R0 | Exclude<R, Scope.Scope> | R2 | R3> {
1510
- return FilteredTypeId in versioned
1511
- ? new FilteredImpl(versioned, (a) => Effect.asSome(f(a)))
1512
- : new ComputedImpl(versioned, f);
1513
- });
1514
-
1515
- /**
1516
- * Transforms a `RefSubject`, `Computed`, or `Filtered` using a pure function.
1517
- *
1518
- * @example
1519
- * ```ts
1520
- * import { Effect } from "effect"
1521
- * import * as RefSubject from "@typed/fx/RefSubject"
1522
- *
1523
- * const program = Effect.gen(function* () {
1524
- * const count = yield* RefSubject.make(5)
1525
- *
1526
- * // Create a computed that doubles the count
1527
- * const doubled = RefSubject.map(count, (n) => n * 2)
1528
- *
1529
- * const value = yield* doubled
1530
- * console.log(value) // 10
1531
- *
1532
- * // Update source
1533
- * yield* RefSubject.set(count, 7)
1534
- *
1535
- * // Computed automatically updates
1536
- * const newValue = yield* doubled
1537
- * console.log(newValue) // 14
1538
- * })
1539
- * ```
1540
- *
1541
- * @since 1.0.0
1542
- * @category combinators
1543
- */
1544
- export const map: {
1545
- <T extends RefSubject.Any | Computed.Any | Filtered.Any, B>(
1546
- f: (a: Success<T>) => B,
1547
- ): (
1548
- ref: T,
1549
- ) => T extends Filtered.Any
1550
- ? Filtered<B, Error<T>, Services<T>>
1551
- : Computed<B, Error<T>, Services<T>>;
1552
-
1553
- <A, E, R, B>(ref: RefSubject<A, E, R> | Computed<A, E, R>, f: (a: A) => B): Computed<B, E, R>;
1554
- <A, E, R, B>(filtered: Filtered<A, E, R>, f: (a: A) => B): Filtered<B, E, R>;
1555
-
1556
- <R0, E0, A, E, R, B, E2, R2>(
1557
- versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
1558
- f: (a: A) => B,
1559
- ):
1560
- | Computed<B, E0 | E | E2, R0 | R2 | Exclude<R, Scope.Scope>>
1561
- | Filtered<B, E0 | E | E2, R0 | R2 | Exclude<R, Scope.Scope>>;
1562
- } = dual(2, function map<
1563
- R0,
1564
- E0,
1565
- A,
1566
- E,
1567
- R,
1568
- B,
1569
- E2,
1570
- R2,
1571
- >(versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>, f: (a: A) => B):
1572
- | Computed<B, E0 | E | E2, R0 | Exclude<R, Scope.Scope> | R2>
1573
- | Filtered<B, E0 | E | E2, R0 | Exclude<R, Scope.Scope> | R2> {
1574
- return mapEffect(versioned, (a) => Effect.succeed(f(a)));
1575
- });
1576
-
1577
- /**
1578
- * Filters and transforms a `RefSubject`, `Computed`, or `Filtered` using an `Effect`ful function that returns an `Option`.
1579
- *
1580
- * @example
1581
- * ```ts
1582
- * import { Effect, Option } from "effect"
1583
- * import * as RefSubject from "@typed/fx/RefSubject"
1584
- *
1585
- * const program = Effect.gen(function* () {
1586
- * const numbers = yield* RefSubject.make([1, 2, 3, 4, 5])
1587
- *
1588
- * // Find the first even number
1589
- * const firstEven = RefSubject.filterMapEffect(numbers, (arr) =>
1590
- * Effect.succeed(Option.fromNullable(arr.find((n) => n % 2 === 0)))
1591
- * )
1592
- *
1593
- * const value = yield* firstEven
1594
- * console.log(value) // 2
1595
- * })
1596
- * ```
1597
- *
1598
- * @since 1.0.0
1599
- * @category combinators
1600
- */
1601
- export const filterMapEffect: {
1602
- <A, B, E2, R2>(
1603
- f: (a: A) => Effect.Effect<Option.Option<B>, E2, R2>,
1604
- ): {
1605
- <E, R>(ref: RefSubject<A, E, R> | Computed<A, E, R>): Filtered<B, E | E2, R | R2>;
1606
- <E, R>(ref: Filtered<A, E, R>): Filtered<B, E | E2, R | R2>;
1607
- <R0, E0, B, E, R, E2, R2>(
1608
- versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
1609
- f: (a: A) => Effect.Effect<Option.Option<B>, E2, R2>,
1610
- ): Filtered<B, E0 | E | E2, R0 | R2>;
1611
- };
1612
-
1613
- <A, E, R, B, E2, R2>(
1614
- ref: RefSubject<A, E, R> | Computed<A, E, R> | Filtered<A, E, R>,
1615
- f: (a: A) => Effect.Effect<Option.Option<B>, E2, R2>,
1616
- ): Filtered<B, E | E2, R | R2>;
1617
- <R0, E0, A, E, R, B, E2, R2, R3, E3>(
1618
- versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
1619
- f: (a: A) => Effect.Effect<Option.Option<B>, E3, R3>,
1620
- ): Filtered<B, E0 | E | E2 | E3, R0 | R2 | R3 | Exclude<R, Scope.Scope>>;
1621
- } = dual(2, function filterMapEffect<
1622
- R0,
1623
- E0,
1624
- A,
1625
- E,
1626
- R,
1627
- B,
1628
- E2,
1629
- R2,
1630
- R3,
1631
- E3,
1632
- >(versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>, f: (a: A) => Effect.Effect<Option.Option<B>, E3, R3>): Filtered<
1633
- B,
1634
- E0 | E | E2 | E3,
1635
- R0 | Exclude<R, Scope.Scope> | R2 | R3
1636
- > {
1637
- return new FilteredImpl(versioned, f);
1638
- });
1639
-
1640
- /**
1641
- * Filters and transforms a `RefSubject`, `Computed`, or `Filtered` using a pure function that returns an `Option`.
1642
- *
1643
- * @example
1644
- * ```ts
1645
- * import { Effect, Option } from "effect"
1646
- * import * as RefSubject from "@typed/fx/RefSubject"
1647
- *
1648
- * const program = Effect.gen(function* () {
1649
- * const numbers = yield* RefSubject.make([1, 2, 3, 4, 5])
1650
- *
1651
- * // Get the first even number
1652
- * const firstEven = RefSubject.filterMap(numbers, (arr) =>
1653
- * Option.fromNullable(arr.find((n) => n % 2 === 0))
1654
- * )
1655
- *
1656
- * const value = yield* firstEven
1657
- * console.log(value) // 2
1658
- * })
1659
- * ```
1660
- *
1661
- * @since 1.0.0
1662
- * @category combinators
1663
- */
1664
- export const filterMap: {
1665
- <A, B>(
1666
- f: (a: A) => Option.Option<B>,
1667
- ): {
1668
- <E, R>(ref: RefSubject<A, E, R> | Computed<A, E, R> | Filtered<A, E, R>): Filtered<B, E, R>;
1669
- <R0, E0, B, E, R, E2, R2>(
1670
- versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
1671
- f: (a: A) => Option.Option<B>,
1672
- ): Filtered<B, E0 | E | E2, R0 | R2>;
1673
- };
1674
-
1675
- <R0, E0, A, E, R, B, E2, R2>(
1676
- versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>,
1677
- f: (a: A) => Option.Option<B>,
1678
- ): Filtered<B, E0 | E | E2, R0 | R2 | Exclude<R, Scope.Scope>>;
1679
-
1680
- <A, E, R, B>(
1681
- ref: RefSubject<A, E, R> | Computed<A, E, R> | Filtered<A, E, R>,
1682
- f: (a: A) => Option.Option<B>,
1683
- ): Filtered<B, E, R>;
1684
- } = dual(2, function filterMap<
1685
- R0,
1686
- E0,
1687
- A,
1688
- E,
1689
- R,
1690
- B,
1691
- E2,
1692
- R2,
1693
- >(versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>, f: (a: A) => Option.Option<B>): Filtered<
1694
- B,
1695
- E0 | E | E2,
1696
- R0 | Exclude<R, Scope.Scope> | R2
1697
- > {
1698
- return new FilteredImpl(versioned, (a) => Effect.succeed(f(a)));
1699
- });
1700
-
1701
- /**
1702
- * Converts a `Computed` or `Filtered` of `Option<A>` into a `Filtered<A>`, filtering out `None` values.
1703
- *
1704
- * @example
1705
- * ```ts
1706
- * import { Effect, Option } from "effect"
1707
- * import * as RefSubject from "@typed/fx/RefSubject"
1708
- *
1709
- * const program = Effect.gen(function* () {
1710
- * const maybeValue = yield* RefSubject.make(Option.some(42))
1711
- *
1712
- * // Compact the Option
1713
- * const filtered = RefSubject.compact(maybeValue)
1714
- *
1715
- * const value = yield* filtered
1716
- * console.log(value) // 42
1717
- *
1718
- * // If the Option becomes None, the Filtered will fail
1719
- * yield* RefSubject.set(maybeValue, Option.none())
1720
- * // yield* filtered would fail with NoSuchElementError
1721
- * })
1722
- * ```
1723
- *
1724
- * @since 1.0.0
1725
- * @category combinators
1726
- */
1727
- export const compact: {
1728
- <A, E, R>(ref: Computed<Option.Option<A>, E, R>): Filtered<A>;
1729
- <A, E, R>(ref: Filtered<Option.Option<A>, E, R>): Filtered<A>;
1730
-
1731
- <R0, E0, A, E, R, E2, R2>(
1732
- versioned: Versioned.Versioned<R0, E0, Option.Option<A>, E, R, Option.Option<A>, E2, R2>,
1733
- ): Filtered<
1734
- A,
1735
- E0 | E | Exclude<E, Cause.NoSuchElementError> | Exclude<E2, Cause.NoSuchElementError>,
1736
- R0 | R2 | Exclude<R, Scope.Scope>
1737
- >;
1738
- } = function compact<R0, E0, A, E, R, E2, R2>(
1739
- versioned: Versioned.Versioned<R0, E0, Option.Option<A>, E, R, Option.Option<A>, E2, R2>,
1740
- ): any {
1741
- return new FilteredImpl(versioned, Effect.succeed);
1742
- };
1743
-
1744
- class RefSubjectSimpleTransform<A, E, R, R2, R3>
1745
- extends YieldableFx<A, E, R | R2 | Scope.Scope, A, E, R | R3>
1746
- implements RefSubject<A, E, R | R2 | R3>
1747
- {
1748
- readonly [ComputedTypeId]: ComputedTypeId = ComputedTypeId;
1749
- readonly [RefSubjectTypeId]: RefSubjectTypeId = RefSubjectTypeId;
1750
-
1751
- readonly version: Effect.Effect<number, E, R>;
1752
- readonly interrupt: Effect.Effect<void, never, R>;
1753
- readonly subscriberCount: Effect.Effect<number, never, R>;
1754
- private _fx: Fx<A, E, Scope.Scope | R | R2>;
1755
-
1756
- readonly ref: RefSubject<A, E, R>;
1757
- readonly transformFx: (fx: Fx<A, E, Scope.Scope | R>) => Fx<A, E, Scope.Scope | R | R2>;
1758
- readonly transformEffect: (effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | R3>;
1759
-
1760
- constructor(
1761
- ref: RefSubject<A, E, R>,
1762
- transformFx: (fx: Fx<A, E, Scope.Scope | R>) => Fx<A, E, Scope.Scope | R | R2>,
1763
- transformEffect: (effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | R3>,
1764
- ) {
1765
- super();
1766
-
1767
- this.ref = ref;
1768
- this.transformFx = transformFx;
1769
- this.transformEffect = transformEffect;
1770
- this.version = ref.version;
1771
- this.interrupt = ref.interrupt;
1772
- this.subscriberCount = ref.subscriberCount;
1773
-
1774
- this._fx = transformFx(ref);
1775
- }
1776
-
1777
- run<R4>(sink: Sink.Sink<A, E, R4>) {
1778
- return this._fx.run(sink);
1779
- }
1780
-
1781
- toEffect(): Effect.Effect<A, E, R | R3> {
1782
- return this.transformEffect(this.ref.asEffect());
1783
- }
1784
-
1785
- updates<E2, R2, C>(
1786
- run: (ref: GetSetDelete<A, E, R>) => Effect.Effect<C, E2, R2>,
1787
- ): Effect.Effect<C, E | E2, R | R2> {
1788
- return this.ref.updates(run);
1789
- }
1790
-
1791
- onFailure(cause: Cause.Cause<E>): Effect.Effect<unknown, never, R> {
1792
- return this.ref.onFailure(cause);
1793
- }
1794
-
1795
- onSuccess(value: A): Effect.Effect<unknown, never, R> {
1796
- return this.ref.onSuccess(value);
1797
- }
1798
- }
1799
-
1800
- export const slice: {
1801
- (skip: number, take: number): <A, E, R>(ref: RefSubject<A, E, R>) => RefSubject<A, E, R>;
1802
- <A, E, R>(ref: RefSubject<A, E, R>, skip: number, take: number): RefSubject<A, E, R>;
1803
- } = dual(3, function slice<
1804
- A,
1805
- E,
1806
- R,
1807
- >(ref: RefSubject<A, E, R>, skip: number, take: number): RefSubject<A, E, R> {
1808
- return new RefSubjectSimpleTransform(ref, (_) => fxSlice(_, { skip, take }), identity);
1809
- });
1810
-
1811
- class RefSubjectTransform<A, B, E, R>
1812
- extends YieldableFx<B, E, R | Scope.Scope, B, E, R>
1813
- implements RefSubject<B, E, R>
1814
- {
1815
- readonly [ComputedTypeId]: ComputedTypeId = ComputedTypeId;
1816
- readonly [RefSubjectTypeId]: RefSubjectTypeId = RefSubjectTypeId;
1817
-
1818
- readonly version: Effect.Effect<number, E, R>;
1819
- readonly interrupt: Effect.Effect<void, never, R>;
1820
- readonly subscriberCount: Effect.Effect<number, never, R>;
1821
- private _fx: Fx<B, E, Scope.Scope | R>;
1822
-
1823
- readonly ref: RefSubject<A, E, R>;
1824
- readonly toB: (a: A) => B;
1825
- readonly toA: (b: B) => A;
1826
-
1827
- constructor(ref: RefSubject<A, E, R>, toB: (a: A) => B, toA: (b: B) => A) {
1828
- super();
1829
-
1830
- this.ref = ref;
1831
- this.toB = toB;
1832
- this.toA = toA;
1833
- this.version = ref.version;
1834
- this.interrupt = ref.interrupt;
1835
- this.subscriberCount = ref.subscriberCount;
1836
-
1837
- this._fx = fxMapEffect(ref, (a) => Effect.succeed(toB(a)));
1838
- }
1839
-
1840
- run<R2>(sink: Sink.Sink<B, E, R2>) {
1841
- return this._fx.run(sink);
1842
- }
1843
-
1844
- toEffect(): Effect.Effect<B, E, R> {
1845
- return Effect.map(this.ref.asEffect(), this.toB);
1846
- }
1847
-
1848
- updates<E2, R2, C>(
1849
- run: (ref: GetSetDelete<B, E, R>) => Effect.Effect<C, E2, R2>,
1850
- ): Effect.Effect<C, E | E2, R | R2> {
1851
- return this.ref.updates((innerRef) => {
1852
- const getSetDelete: GetSetDelete<B, E, R> = {
1853
- get: Effect.map(innerRef.get, this.toB),
1854
- set: (b: B) => Effect.map(innerRef.set(this.toA(b)), this.toB),
1855
- delete: Effect.map(innerRef.delete, Option.map(this.toB)),
1856
- };
1857
- return run(getSetDelete);
1858
- });
1859
- }
1860
-
1861
- onFailure(cause: Cause.Cause<E>): Effect.Effect<unknown, never, R> {
1862
- return this.ref.onFailure(cause);
1863
- }
1864
-
1865
- onSuccess(value: B): Effect.Effect<unknown, never, R> {
1866
- return this.ref.onSuccess(this.toA(value));
1867
- }
1868
- }
1869
-
1870
- /**
1871
- * Transforms a `RefSubject` invariantly using bidirectional mapping functions.
1872
- *
1873
- * @example
1874
- * ```ts
1875
- * import { Effect } from "effect"
1876
- * import * as RefSubject from "@typed/fx/RefSubject"
1877
- *
1878
- * const program = Effect.gen(function* () {
1879
- * const count = yield* RefSubject.make(5)
1880
- *
1881
- * // Transform to string and back
1882
- * const countStr = RefSubject.transform(
1883
- * count,
1884
- * (n) => n.toString(),
1885
- * (s) => parseInt(s, 10)
1886
- * )
1887
- *
1888
- * const value = yield* countStr
1889
- * console.log(value) // "5"
1890
- *
1891
- * // Set using the transformed type
1892
- * yield* RefSubject.set(countStr, "10")
1893
- *
1894
- * // Original reflects the change
1895
- * const original = yield* count
1896
- * console.log(original) // 10
1897
- * })
1898
- * ```
1899
- *
1900
- * @since 1.0.0
1901
- * @category combinators
1902
- */
1903
- export const transform: {
1904
- <A, B>(
1905
- toB: (a: A) => B,
1906
- toA: (b: B) => A,
1907
- ): <E, R>(ref: RefSubject<A, E, R>) => RefSubject<B, E, R>;
1908
- <A, E, R, B>(ref: RefSubject<A, E, R>, toB: (a: A) => B, toA: (b: B) => A): RefSubject<B, E, R>;
1909
- } = dual(3, function transform<
1910
- A,
1911
- E,
1912
- R,
1913
- B,
1914
- >(ref: RefSubject<A, E, R>, toB: (a: A) => B, toA: (b: B) => A): RefSubject<B, E, R> {
1915
- return new RefSubjectTransform(ref, toB, toA);
1916
- });
1917
-
1918
- type RefKind = "r" | "c" | "f";
1919
-
1920
- const join = (a: RefKind, b: RefKind) => {
1921
- if (a === "r") return b;
1922
- if (b === "r") return a;
1923
- if (a === "f") return a;
1924
- if (b === "f") return b;
1925
- return "c";
1926
- };
1927
-
1928
- function getRefKind<
1929
- const Refs extends ReadonlyArray<
1930
- RefSubject<any, any, any> | Computed<any, any, any> | Filtered<any, any, any>
1931
- >,
1932
- >(refs: Refs): RefKind {
1933
- let kind: RefKind = "r";
1934
-
1935
- for (const ref of refs) {
1936
- if (FilteredTypeId in ref) {
1937
- kind = "f";
1938
- break;
1939
- } else if (!(RefSubjectTypeId in ref)) {
1940
- kind = join(kind, "c");
1941
- }
1942
- }
1943
-
1944
- return kind;
1945
- }
1946
-
1947
- type StructFrom<
1948
- Refs extends Readonly<Record<string, RefSubject.Any | Computed.Any | Filtered.Any>>,
1949
- > = {
1950
- c: [ComputedStructFrom<Refs>] extends [Computed<infer A, infer E, infer R>]
1951
- ? Computed<A, E, R>
1952
- : never;
1953
- f: [FilteredStructFrom<Refs>] extends [Filtered<infer A, infer E, infer R>]
1954
- ? Filtered<A, E, R>
1955
- : never;
1956
- r: [RefSubjectStructFrom<Refs>] extends [RefSubject<infer A, infer E, infer R>]
1957
- ? RefSubject<A, E, R>
1958
- : never;
1959
- }[GetStructKind<Refs>];
1960
-
1961
- type GetStructKind<
1962
- Refs extends Readonly<Record<string, RefSubject.Any | Computed.Any | Filtered.Any>>,
1963
- > = MergeKinds<
1964
- UnionToTuple<
1965
- {
1966
- [K in keyof Refs]: MatchKind<Refs[K]>;
1967
- }[keyof Refs]
1968
- >
1969
- >;
1970
-
1971
- type Ref = RefSubject.Any | Computed.Any | Filtered.Any;
1972
-
1973
- type MatchKind<T extends Ref> = [T] extends [Filtered.Any]
1974
- ? "f"
1975
- : [T] extends [RefSubject.Any]
1976
- ? "r"
1977
- : "c";
1978
-
1979
- type MergeKind<A extends RefKind, B extends RefKind> = A extends "f"
1980
- ? A
1981
- : B extends "f"
1982
- ? B
1983
- : A extends "r"
1984
- ? B
1985
- : B extends "r"
1986
- ? A
1987
- : "c";
1988
-
1989
- type MergeKinds<Kinds extends ReadonlyArray<any>> = Kinds extends readonly [
1990
- infer Head extends RefKind,
1991
- ...infer Tail extends ReadonlyArray<RefKind>,
1992
- ]
1993
- ? MergeKind<Head, MergeKinds<Tail>>
1994
- : "r";
1995
-
1996
- type FilteredStructFrom<
1997
- Refs extends Readonly<Record<string, RefSubject.Any | Computed.Any | Filtered.Any>>,
1998
- > = Filtered<
1999
- {
2000
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2001
- },
2002
- FxError<Refs[keyof Refs]>,
2003
- Effect.Services<Refs[keyof Refs]>
2004
- >;
2005
-
2006
- type ComputedStructFrom<
2007
- Refs extends Readonly<Record<string, RefSubject.Any | Computed.Any | Filtered.Any>>,
2008
- > = Computed<
2009
- {
2010
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2011
- },
2012
- Effect.Error<Refs[keyof Refs]>,
2013
- Effect.Services<Refs[keyof Refs]>
2014
- >;
2015
-
2016
- type RefSubjectStructFrom<
2017
- Refs extends Readonly<Record<string, RefSubject.Any | Computed.Any | Filtered.Any>>,
2018
- > = RefSubject<
2019
- {
2020
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2021
- },
2022
- Effect.Error<Refs[keyof Refs]>,
2023
- Effect.Services<Refs[keyof Refs]>
2024
- >;
2025
-
2026
- type TupleFrom<
2027
- Refs extends ReadonlyArray<
2028
- RefSubject<any, any, any> | Computed<any, any, any> | Filtered<any, any, any>
2029
- >,
2030
- > = {
2031
- c: [ComputedTupleFrom<Refs>] extends [Computed<infer A, infer E, infer R>]
2032
- ? Computed<A, E, R>
2033
- : never;
2034
- f: [FilteredTupleFrom<Refs>] extends [Filtered<infer A, infer E, infer R>]
2035
- ? Filtered<A, E, R>
2036
- : never;
2037
- r: [RefSubjectTupleFrom<Refs>] extends [RefSubject<infer A, infer E, infer R>]
2038
- ? RefSubject<A, E, R>
2039
- : never;
2040
- }[GetTupleKind<Refs>];
2041
-
2042
- type GetTupleKind<
2043
- Refs extends ReadonlyArray<Ref>,
2044
- Kind extends RefKind = "r",
2045
- > = Refs extends readonly [infer Head extends Ref, ...infer Tail extends ReadonlyArray<Ref>]
2046
- ? GetTupleKind<Tail, MergeKind<Kind, MatchKind<Head>>>
2047
- : Kind;
2048
-
2049
- type FilteredTupleFrom<
2050
- Refs extends ReadonlyArray<
2051
- RefSubject<any, any, any> | Computed<any, any, any> | Filtered<any, any, any>
2052
- >,
2053
- > = Filtered<
2054
- {
2055
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2056
- },
2057
- FxError<Refs[number]>,
2058
- Effect.Services<Refs[number]>
2059
- >;
2060
-
2061
- type ComputedTupleFrom<
2062
- Refs extends ReadonlyArray<
2063
- RefSubject<any, any, any> | Computed<any, any, any> | Filtered<any, any, any>
2064
- >,
2065
- > = Computed<
2066
- {
2067
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2068
- },
2069
- Effect.Error<Refs[number]>,
2070
- Effect.Services<Refs[number]>
2071
- >;
2072
-
2073
- type RefSubjectTupleFrom<
2074
- Refs extends ReadonlyArray<
2075
- RefSubject<any, any, any> | Computed<any, any, any> | Filtered<any, any, any>
2076
- >,
2077
- > = RefSubject<
2078
- {
2079
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2080
- },
2081
- Effect.Error<Refs[number]>,
2082
- Effect.Services<Refs[number]>
2083
- >;
2084
-
2085
- /**
2086
- * Combines multiple `RefSubject`, `Computed`, or `Filtered` instances into a single struct.
2087
- *
2088
- * @example
2089
- * ```ts
2090
- * import { Effect } from "effect"
2091
- * import * as RefSubject from "@typed/fx/RefSubject"
2092
- *
2093
- * const program = Effect.gen(function* () {
2094
- * const firstName = yield* RefSubject.make("Alice")
2095
- * const lastName = yield* RefSubject.make("Smith")
2096
- * const age = yield* RefSubject.make(30)
2097
- *
2098
- * // Combine into a struct
2099
- * const person = RefSubject.struct({
2100
- * firstName,
2101
- * lastName,
2102
- * age
2103
- * })
2104
- *
2105
- * const fullPerson = yield* person
2106
- * console.log(fullPerson) // { firstName: "Alice", lastName: "Smith", age: 30 }
2107
- *
2108
- * // Update one field
2109
- * yield* RefSubject.set(firstName, "Bob")
2110
- *
2111
- * // Struct automatically updates
2112
- * const updated = yield* person
2113
- * console.log(updated.firstName) // "Bob"
2114
- * })
2115
- * ```
2116
- *
2117
- * @since 1.0.0
2118
- * @category combinators
2119
- */
2120
- export function struct<
2121
- const Refs extends Readonly<Record<string, RefSubject.Any | Computed.Any | Filtered.Any>>,
2122
- >(refs: Refs): StructFrom<Refs> {
2123
- const kind = getRefKind(Object.values(refs));
2124
- switch (kind) {
2125
- case "r":
2126
- return makeStructRef(refs as any) as StructFrom<Refs>;
2127
- case "c":
2128
- return makeStructComputed(refs as any) as StructFrom<Refs>;
2129
- case "f":
2130
- return makeStructFiltered(refs as any) as any as StructFrom<Refs>;
2131
- }
2132
- }
2133
- /**
2134
- * Combines multiple `RefSubject`, `Computed`, or `Filtered` instances into a single tuple.
2135
- *
2136
- * @example
2137
- * ```ts
2138
- * import { Effect } from "effect"
2139
- * import * as RefSubject from "@typed/fx/RefSubject"
2140
- *
2141
- * const program = Effect.gen(function* () {
2142
- * const x = yield* RefSubject.make(10)
2143
- * const y = yield* RefSubject.make(20)
2144
- * const z = yield* RefSubject.make(30)
2145
- *
2146
- * // Combine into a tuple
2147
- * const point = RefSubject.tuple([x, y, z])
2148
- *
2149
- * const coords = yield* point
2150
- * console.log(coords) // [10, 20, 30]
2151
- *
2152
- * // Update one value
2153
- * yield* RefSubject.set(x, 15)
2154
- *
2155
- * // Tuple automatically updates
2156
- * const updated = yield* point
2157
- * console.log(updated) // [15, 20, 30]
2158
- * })
2159
- * ```
2160
- *
2161
- * @since 1.0.0
2162
- * @category combinators
2163
- */
2164
- export function tuple<const Refs extends ReadonlyArray<Ref>>(refs: Refs): TupleFrom<Refs> {
2165
- const kind = getRefKind(refs);
2166
- switch (kind) {
2167
- case "r":
2168
- return makeTupleRef(refs as any) as TupleFrom<Refs>;
2169
- case "c":
2170
- return makeTupleComputed(refs as any) as TupleFrom<Refs>;
2171
- case "f":
2172
- return makeTupleFiltered(refs as any) as any as TupleFrom<Refs>;
2173
- }
2174
- }
2175
-
2176
- function makeTupleRef<const Refs extends ReadonlyArray<RefSubject<any, any, any>>>(
2177
- refs: Refs,
2178
- ): RefSubjectTupleFrom<Refs> {
2179
- return new RefSubjectTuple(refs);
2180
- }
2181
-
2182
- const UNBOUNDED = { concurrency: "unbounded" } as const;
2183
-
2184
- class RefSubjectTuple<const Refs extends ReadonlyArray<RefSubject<any, any, any>>>
2185
- extends YieldableFx<
2186
- {
2187
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2188
- },
2189
- Effect.Error<Refs[number]>,
2190
- Effect.Services<Refs[number]>,
2191
- {
2192
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2193
- },
2194
- Effect.Error<Refs[number]>,
2195
- Effect.Services<Refs[number]>
2196
- >
2197
- implements RefSubjectTupleFrom<Refs>
2198
- {
2199
- readonly [ComputedTypeId]: ComputedTypeId = ComputedTypeId;
2200
- readonly [RefSubjectTypeId]: RefSubjectTypeId = RefSubjectTypeId;
2201
-
2202
- readonly version: Effect.Effect<
2203
- number,
2204
- Effect.Error<Refs[number]>,
2205
- Effect.Services<Refs[number]>
2206
- >;
2207
- readonly interrupt: Effect.Effect<void, never, Effect.Services<Refs[number]>>;
2208
- readonly subscriberCount: Effect.Effect<number, never, Effect.Services<Refs[number]>>;
2209
-
2210
- private versioned: Versioned.Versioned<
2211
- Effect.Services<Refs[number]>,
2212
- Effect.Error<Refs[number]>,
2213
- { readonly [K in keyof Refs]: Effect.Success<Refs[K]> },
2214
- Effect.Error<Refs[number]>,
2215
- Effect.Services<Refs[number]>,
2216
- { readonly [K in keyof Refs]: Effect.Success<Refs[K]> },
2217
- Effect.Error<Refs[number]>,
2218
- Effect.Services<Refs[number]>
2219
- >;
2220
-
2221
- private getSetDelete: GetSetDelete<
2222
- { readonly [K in keyof Refs]: Effect.Success<Refs[K]> },
2223
- Effect.Error<Refs[number]>,
2224
- Effect.Services<Refs[number]>
2225
- >;
2226
-
2227
- readonly refs: Refs;
2228
-
2229
- constructor(refs: Refs) {
2230
- super();
2231
-
2232
- this.refs = refs;
2233
- this.versioned = Versioned.hold(Versioned.tuple(refs)) as any;
2234
- this.version = this.versioned.version;
2235
- this.interrupt = Effect.all(
2236
- refs.map((r) => r.interrupt),
2237
- UNBOUNDED,
2238
- );
2239
- this.subscriberCount = Effect.map(
2240
- Effect.all(
2241
- refs.map((r) => r.subscriberCount),
2242
- UNBOUNDED,
2243
- ),
2244
- Array.reduce(0, sum),
2245
- );
2246
-
2247
- this.getSetDelete = {
2248
- get: this.versioned.asEffect(),
2249
- set: (a) =>
2250
- Effect.all(
2251
- refs.map((r, i) => set(r, a[i])),
2252
- UNBOUNDED,
2253
- ) as any,
2254
- delete: Effect.map(
2255
- Effect.all(
2256
- refs.map((r) => reset(r)),
2257
- UNBOUNDED,
2258
- ),
2259
- Option.all,
2260
- ) as any,
2261
- };
2262
-
2263
- this.updates = this.updates.bind(this);
2264
- this.onFailure = this.onFailure.bind(this);
2265
- this.onSuccess = this.onSuccess.bind(this);
2266
- }
2267
-
2268
- run<R2 = never>(
2269
- sink: Sink.Sink<
2270
- {
2271
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2272
- },
2273
- Effect.Error<Refs[number]>,
2274
- R2
2275
- >,
2276
- ): Effect.Effect<unknown, never, Effect.Services<Refs[number]> | R2> {
2277
- return this.versioned.run(sink);
2278
- }
2279
-
2280
- override toEffect(): Effect.Effect<
2281
- { readonly [K in keyof Refs]: Effect.Success<Refs[K]> },
2282
- Effect.Error<Refs[number]>,
2283
- Effect.Services<Refs[number]>
2284
- > {
2285
- return this.versioned.asEffect();
2286
- }
2287
-
2288
- updates<E2, R2, C>(
2289
- run: (
2290
- ref: GetSetDelete<
2291
- {
2292
- readonly [K in keyof Refs]: Effect.Success<Refs[K]>;
2293
- },
2294
- Effect.Error<Refs[number]>,
2295
- Effect.Services<Refs[number]>
2296
- >,
2297
- ) => Effect.Effect<C, E2, R2>,
2298
- ) {
2299
- return run(this.getSetDelete);
2300
- }
2301
-
2302
- onFailure(
2303
- cause: Cause.Cause<Effect.Error<Refs[number]>>,
2304
- ): Effect.Effect<unknown, never, Effect.Services<Refs[number]>> {
2305
- return Effect.all(this.refs.map((ref) => ref.onFailure(cause)));
2306
- }
2307
-
2308
- onSuccess(value: { readonly [K in keyof Refs]: Effect.Success<Refs[K]> }): Effect.Effect<
2309
- unknown,
2310
- never,
2311
- Effect.Services<Refs[number]>
2312
- > {
2313
- return Effect.catchCause(this.getSetDelete.set(value), (c) => this.onFailure(c));
2314
- }
2315
- }
2316
-
2317
- function makeTupleComputed<const Refs extends ReadonlyArray<Computed<any, any, any>>>(
2318
- refs: Refs,
2319
- ): ComputedTupleFrom<Refs> {
2320
- return new ComputedImpl(Versioned.tuple(refs) as any, Effect.succeed) as any;
2321
- }
2322
-
2323
- function makeTupleFiltered<
2324
- const Refs extends ReadonlyArray<Computed<any, any, any> | Filtered<any, any, any>>,
2325
- >(refs: Refs): FilteredTupleFrom<Refs> {
2326
- return new FilteredImpl(Versioned.tuple(refs) as any, Effect.succeedSome) as any;
2327
- }
2328
-
2329
- function makeStructRef<const Refs extends Readonly<Record<string, RefSubject.Any>>>(
2330
- refs: Refs,
2331
- ): RefSubjectStructFrom<Refs> {
2332
- return new RefSubjectStruct(refs) as any;
2333
- }
2334
-
2335
- class RefSubjectStruct<const Refs extends Readonly<Record<string, RefSubject.Any>>>
2336
- extends YieldableFx<
2337
- {
2338
- readonly [K in keyof Refs]: Success<Refs[K]>;
2339
- },
2340
- Error<Refs[keyof Refs]>,
2341
- Services<Refs[keyof Refs]> | Scope.Scope,
2342
- {
2343
- readonly [K in keyof Refs]: Success<Refs[K]>;
2344
- },
2345
- Error<Refs[keyof Refs]>,
2346
- Services<Refs[keyof Refs]>
2347
- >
2348
- implements
2349
- RefSubject<
2350
- {
2351
- readonly [K in keyof Refs]: Success<Refs[K]>;
2352
- },
2353
- Error<Refs[keyof Refs]>,
2354
- Services<Refs[keyof Refs]>
2355
- >
2356
- {
2357
- readonly [ComputedTypeId]: ComputedTypeId = ComputedTypeId;
2358
- readonly [RefSubjectTypeId]: RefSubjectTypeId = RefSubjectTypeId;
2359
-
2360
- readonly version: Effect.Effect<number, Error<Refs[keyof Refs]>, Services<Refs[keyof Refs]>>;
2361
- readonly interrupt: Effect.Effect<void, never, Services<Refs[keyof Refs]>>;
2362
- readonly subscriberCount: Effect.Effect<number, never, Services<Refs[keyof Refs]>>;
2363
-
2364
- private versioned: Versioned.Versioned<
2365
- Services<Refs[keyof Refs]>,
2366
- Error<Refs[keyof Refs]>,
2367
- { readonly [K in keyof Refs]: Success<Refs[K]> },
2368
- Error<Refs[keyof Refs]>,
2369
- Services<Refs[keyof Refs]>,
2370
- { readonly [K in keyof Refs]: Success<Refs[K]> },
2371
- Error<Refs[keyof Refs]>,
2372
- Services<Refs[keyof Refs]>
2373
- >;
2374
-
2375
- private getSetDelete: GetSetDelete<
2376
- { readonly [K in keyof Refs]: Success<Refs[K]> },
2377
- Error<Refs[keyof Refs]>,
2378
- Services<Refs[keyof Refs]>
2379
- >;
2380
-
2381
- readonly refs: Refs;
2382
-
2383
- constructor(refs: Refs) {
2384
- super();
2385
-
2386
- this.refs = refs;
2387
- this.versioned = Versioned.hold(Versioned.struct(refs)) as any;
2388
- this.version = this.versioned.version;
2389
- this.interrupt = Effect.all(
2390
- Object.values(refs).map((r) => r.interrupt),
2391
- UNBOUNDED,
2392
- );
2393
- this.subscriberCount = Effect.map(
2394
- Effect.all(
2395
- Object.values(refs).map((r) => r.subscriberCount),
2396
- UNBOUNDED,
2397
- ),
2398
- Array.reduce(0, sum),
2399
- );
2400
-
2401
- this.getSetDelete = {
2402
- get: this.versioned.asEffect(),
2403
- set: (a) =>
2404
- Effect.all(
2405
- Object.keys(refs).map((k) => set(refs[k] as any, a[k])),
2406
- UNBOUNDED,
2407
- ) as any,
2408
- delete: Effect.map(
2409
- Effect.all(
2410
- Object.values(refs).map((r) => reset(r as any)),
2411
- UNBOUNDED,
2412
- ),
2413
- Option.all,
2414
- ) as any,
2415
- };
2416
-
2417
- this.updates = this.updates.bind(this);
2418
- this.onFailure = this.onFailure.bind(this);
2419
- this.onSuccess = this.onSuccess.bind(this);
2420
- }
2421
-
2422
- run<R3 = never>(
2423
- sink: Sink.Sink<{ readonly [K in keyof Refs]: Success<Refs[K]> }, Error<Refs[keyof Refs]>, R3>,
2424
- ): Effect.Effect<unknown, never, Services<Refs[keyof Refs]> | Scope.Scope | R3> {
2425
- return this.versioned.run(sink as any) as any;
2426
- }
2427
-
2428
- toEffect() {
2429
- return this.versioned.asEffect();
2430
- }
2431
-
2432
- updates<E2, R2, C>(
2433
- run: (
2434
- ref: GetSetDelete<
2435
- {
2436
- readonly [K in keyof Refs]: Success<Refs[K]>;
2437
- },
2438
- Error<Refs[keyof Refs]>,
2439
- Services<Refs[keyof Refs]>
2440
- >,
2441
- ) => Effect.Effect<C, E2, R2>,
2442
- ) {
2443
- return run(this.getSetDelete);
2444
- }
2445
-
2446
- onFailure(
2447
- cause: Cause.Cause<Error<Refs[keyof Refs]>>,
2448
- ): Effect.Effect<unknown, never, Services<Refs[keyof Refs]>> {
2449
- return Effect.all(Object.values(this.refs).map((ref) => ref.onFailure(cause as any)));
2450
- }
2451
-
2452
- onSuccess(value: { readonly [K in keyof Refs]: Success<Refs[K]> }): Effect.Effect<
2453
- unknown,
2454
- never,
2455
- Services<Refs[keyof Refs]>
2456
- > {
2457
- return Effect.catchCause(this.getSetDelete.set(value), (c) => this.onFailure(c));
2458
- }
2459
- }
2460
-
2461
- function makeStructComputed<const Refs extends Readonly<Record<string, Computed<any, any, any>>>>(
2462
- refs: Refs,
2463
- ): ComputedStructFrom<Refs> {
2464
- return new ComputedImpl(Versioned.struct(refs) as any, Effect.succeed) as any;
2465
- }
2466
-
2467
- function makeStructFiltered<
2468
- const Refs extends Readonly<Record<string, Computed<any, any, any> | Filtered<any, any, any>>>,
2469
- >(refs: Refs): FilteredStructFrom<Refs> {
2470
- return new FilteredImpl(Versioned.struct(refs) as any, Effect.succeedSome) as any;
2471
- }
2472
-
2473
- export function computedFromService<R, A, E, R2>(
2474
- effect: Effect.Effect<Computed<A, E, R2>, never, R>,
2475
- ): Computed<A, E, R | R2> {
2476
- return new ComputedFromService(effect);
2477
- }
2478
-
2479
- class ComputedFromService<R, A, E, R2>
2480
- extends YieldableFx<A, E, R | R2 | Scope.Scope, A, E, R | R2>
2481
- implements Computed<A, E, R | R2>
2482
- {
2483
- readonly [ComputedTypeId]: ComputedTypeId = ComputedTypeId;
2484
-
2485
- private readonly effect: Effect.Effect<Computed<A, E, R2>, never, R>;
2486
- readonly version: Effect.Effect<number, E, R | R2>;
2487
- readonly interrupt: Effect.Effect<void, never, R | R2>;
2488
-
2489
- constructor(effect: Effect.Effect<Computed<A, E, R2>, never, R>) {
2490
- super();
2491
- this.effect = effect;
2492
- this.version = Effect.flatMap(this.effect, (c) => c.version);
2493
- this.interrupt = Effect.flatMap(this.effect, (c) => c.interrupt);
2494
- }
2495
-
2496
- run<RSink>(
2497
- sink: Sink.Sink<A, E, RSink>,
2498
- ): Effect.Effect<unknown, never, R | R2 | RSink | Scope.Scope> {
2499
- return Effect.flatMap(this.effect, (c) => c.run(sink));
2500
- }
2501
-
2502
- toEffect(): Effect.Effect<A, E, R | R2> {
2503
- return Effect.flatMap(this.effect, (c) => c.asEffect());
2504
- }
2505
- }
2506
-
2507
- export function filteredFromService<R, A, E, R2>(
2508
- effect: Effect.Effect<Filtered<A, E, R2>, never, R>,
2509
- ): Filtered<A, E, R | R2> {
2510
- return new FilteredFromService(effect);
2511
- }
2512
-
2513
- class FilteredFromService<R, A, E, R2>
2514
- extends YieldableFx<A, E, R | R2 | Scope.Scope, A, E | Cause.NoSuchElementError, R | R2>
2515
- implements Filtered<A, E, R | R2>
2516
- {
2517
- readonly [FilteredTypeId]: FilteredTypeId = FilteredTypeId;
2518
-
2519
- private readonly effect: Effect.Effect<Filtered<A, E, R2>, never, R>;
2520
- readonly version: Effect.Effect<number, E, R | R2>;
2521
- readonly interrupt: Effect.Effect<void, never, R | R2>;
2522
-
2523
- constructor(effect: Effect.Effect<Filtered<A, E, R2>, never, R>) {
2524
- super();
2525
- this.effect = effect;
2526
- this.version = Effect.flatMap(this.effect, (c) => c.version);
2527
- this.interrupt = Effect.flatMap(this.effect, (c) => c.interrupt);
2528
- }
2529
-
2530
- run<RSink>(
2531
- sink: Sink.Sink<A, E, RSink>,
2532
- ): Effect.Effect<unknown, never, R | R2 | RSink | Scope.Scope> {
2533
- return Effect.flatMap(this.effect, (c) => c.run(sink));
2534
- }
2535
-
2536
- toEffect(): Effect.Effect<A, E | Cause.NoSuchElementError, R | R2> {
2537
- return Effect.flatMap(this.effect, (c) => c.asEffect());
2538
- }
2539
-
2540
- asComputed(): Computed<Option.Option<A>, E, R | R2> {
2541
- return computedFromService<R, Option.Option<A>, E, R2>(
2542
- Effect.map(this.effect, (c) => c.asComputed()),
2543
- );
2544
- }
2545
- }