@typed/fx 2.0.0-beta.3 → 2.0.0-beta.5
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.
- package/README.md +34 -20
- package/dist/Fx/Fx.d.ts +364 -12
- package/dist/Fx/Fx.d.ts.map +1 -1
- package/dist/Fx/Fx.js +37 -6
- package/dist/Fx/TypeId.d.ts +49 -3
- package/dist/Fx/TypeId.d.ts.map +1 -1
- package/dist/Fx/TypeId.js +39 -2
- package/dist/Fx/combinators/additive.d.ts +156 -5
- package/dist/Fx/combinators/additive.d.ts.map +1 -1
- package/dist/Fx/combinators/additive.js +156 -5
- package/dist/Fx/combinators/catch.d.ts +195 -22
- package/dist/Fx/combinators/catch.d.ts.map +1 -1
- package/dist/Fx/combinators/catch.js +186 -16
- package/dist/Fx/combinators/causes.d.ts +24 -1
- package/dist/Fx/combinators/causes.d.ts.map +1 -1
- package/dist/Fx/combinators/causes.js +24 -1
- package/dist/Fx/combinators/changesWithEffect.d.ts +20 -0
- package/dist/Fx/combinators/changesWithEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/changesWithEffect.js +20 -0
- package/dist/Fx/combinators/compact.d.ts +17 -0
- package/dist/Fx/combinators/compact.d.ts.map +1 -1
- package/dist/Fx/combinators/compact.js +17 -0
- package/dist/Fx/combinators/concatMap.d.ts +86 -0
- package/dist/Fx/combinators/concatMap.d.ts.map +1 -0
- package/dist/Fx/combinators/concatMap.js +86 -0
- package/dist/Fx/combinators/continueWith.d.ts +109 -1
- package/dist/Fx/combinators/continueWith.d.ts.map +1 -1
- package/dist/Fx/combinators/continueWith.js +109 -1
- package/dist/Fx/combinators/debounce.d.ts +34 -0
- package/dist/Fx/combinators/debounce.d.ts.map +1 -0
- package/dist/Fx/combinators/debounce.js +35 -0
- package/dist/Fx/combinators/delay.d.ts +34 -0
- package/dist/Fx/combinators/delay.d.ts.map +1 -0
- package/dist/Fx/combinators/delay.js +31 -0
- package/dist/Fx/combinators/dropUntil.d.ts +42 -0
- package/dist/Fx/combinators/dropUntil.d.ts.map +1 -1
- package/dist/Fx/combinators/dropUntil.js +42 -0
- package/dist/Fx/combinators/during.d.ts +38 -0
- package/dist/Fx/combinators/during.d.ts.map +1 -0
- package/dist/Fx/combinators/during.js +85 -0
- package/dist/Fx/combinators/ensuring.d.ts +33 -3
- package/dist/Fx/combinators/ensuring.d.ts.map +1 -1
- package/dist/Fx/combinators/ensuring.js +33 -3
- package/dist/Fx/combinators/exhaustLatestMap.d.ts +40 -4
- package/dist/Fx/combinators/exhaustLatestMap.d.ts.map +1 -1
- package/dist/Fx/combinators/exhaustLatestMap.js +40 -4
- package/dist/Fx/combinators/exhaustLatestMapEffect.d.ts +39 -3
- package/dist/Fx/combinators/exhaustLatestMapEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/exhaustLatestMapEffect.js +39 -3
- package/dist/Fx/combinators/exhaustMap.d.ts +37 -0
- package/dist/Fx/combinators/exhaustMap.d.ts.map +1 -1
- package/dist/Fx/combinators/exhaustMap.js +37 -0
- package/dist/Fx/combinators/exhaustMapEffect.d.ts +32 -0
- package/dist/Fx/combinators/exhaustMapEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/exhaustMapEffect.js +32 -0
- package/dist/Fx/combinators/exit.d.ts +22 -1
- package/dist/Fx/combinators/exit.d.ts.map +1 -1
- package/dist/Fx/combinators/exit.js +22 -1
- package/dist/Fx/combinators/filter.d.ts +16 -0
- package/dist/Fx/combinators/filter.d.ts.map +1 -1
- package/dist/Fx/combinators/filter.js +16 -0
- package/dist/Fx/combinators/filterEffect.d.ts +21 -0
- package/dist/Fx/combinators/filterEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/filterEffect.js +21 -0
- package/dist/Fx/combinators/filterMap.d.ts +19 -0
- package/dist/Fx/combinators/filterMap.d.ts.map +1 -1
- package/dist/Fx/combinators/filterMap.js +19 -0
- package/dist/Fx/combinators/filterMapEffect.d.ts +20 -0
- package/dist/Fx/combinators/filterMapEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/filterMapEffect.js +20 -0
- package/dist/Fx/combinators/filterMapLoop.d.ts +19 -0
- package/dist/Fx/combinators/filterMapLoop.d.ts.map +1 -1
- package/dist/Fx/combinators/filterMapLoop.js +19 -0
- package/dist/Fx/combinators/filterMapLoopCause.d.ts +20 -0
- package/dist/Fx/combinators/filterMapLoopCause.d.ts.map +1 -1
- package/dist/Fx/combinators/filterMapLoopCause.js +20 -0
- package/dist/Fx/combinators/filterMapLoopCauseEffect.d.ts +20 -0
- package/dist/Fx/combinators/filterMapLoopCauseEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/filterMapLoopCauseEffect.js +20 -0
- package/dist/Fx/combinators/filterMapLoopEffect.d.ts +20 -0
- package/dist/Fx/combinators/filterMapLoopEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/filterMapLoopEffect.js +20 -0
- package/dist/Fx/combinators/flatMap.d.ts +48 -3
- package/dist/Fx/combinators/flatMap.d.ts.map +1 -1
- package/dist/Fx/combinators/flatMap.js +35 -2
- package/dist/Fx/combinators/flatMapConcurrently.d.ts +50 -3
- package/dist/Fx/combinators/flatMapConcurrently.d.ts.map +1 -1
- package/dist/Fx/combinators/flatMapConcurrently.js +47 -1
- package/dist/Fx/combinators/flatMapConcurrentlyEffect.d.ts +47 -3
- package/dist/Fx/combinators/flatMapConcurrentlyEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/flatMapConcurrentlyEffect.js +39 -1
- package/dist/Fx/combinators/flatMapEffect.d.ts +44 -2
- package/dist/Fx/combinators/flatMapEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/flatMapEffect.js +31 -1
- package/dist/Fx/combinators/flip.d.ts +33 -1
- package/dist/Fx/combinators/flip.d.ts.map +1 -1
- package/dist/Fx/combinators/flip.js +33 -1
- package/dist/Fx/combinators/gen.d.ts +28 -9
- package/dist/Fx/combinators/gen.d.ts.map +1 -1
- package/dist/Fx/combinators/gen.js +27 -3
- package/dist/Fx/combinators/genScoped.d.ts +32 -9
- package/dist/Fx/combinators/genScoped.d.ts.map +1 -1
- package/dist/Fx/combinators/genScoped.js +30 -2
- package/dist/Fx/combinators/grouped.d.ts +89 -0
- package/dist/Fx/combinators/grouped.d.ts.map +1 -0
- package/dist/Fx/combinators/grouped.js +146 -0
- package/dist/Fx/combinators/index.d.ts +35 -0
- package/dist/Fx/combinators/index.d.ts.map +1 -1
- package/dist/Fx/combinators/index.js +35 -0
- package/dist/Fx/combinators/keyed.d.ts +121 -7
- package/dist/Fx/combinators/keyed.d.ts.map +1 -1
- package/dist/Fx/combinators/keyed.js +68 -10
- package/dist/Fx/combinators/loop.d.ts +16 -0
- package/dist/Fx/combinators/loop.d.ts.map +1 -1
- package/dist/Fx/combinators/loop.js +16 -0
- package/dist/Fx/combinators/loopCause.d.ts +17 -0
- package/dist/Fx/combinators/loopCause.d.ts.map +1 -1
- package/dist/Fx/combinators/loopCause.js +17 -0
- package/dist/Fx/combinators/loopCauseEffect.d.ts +18 -0
- package/dist/Fx/combinators/loopCauseEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/loopCauseEffect.js +18 -0
- package/dist/Fx/combinators/loopEffect.d.ts +23 -0
- package/dist/Fx/combinators/loopEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/loopEffect.js +23 -0
- package/dist/Fx/combinators/map.d.ts +45 -0
- package/dist/Fx/combinators/map.d.ts.map +1 -1
- package/dist/Fx/combinators/map.js +42 -0
- package/dist/Fx/combinators/mapBoth.d.ts +19 -0
- package/dist/Fx/combinators/mapBoth.d.ts.map +1 -1
- package/dist/Fx/combinators/mapBoth.js +19 -0
- package/dist/Fx/combinators/mapEffect.d.ts +24 -0
- package/dist/Fx/combinators/mapEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/mapEffect.js +24 -0
- package/dist/Fx/combinators/mapError.d.ts +20 -4
- package/dist/Fx/combinators/mapError.d.ts.map +1 -1
- package/dist/Fx/combinators/mapError.js +20 -4
- package/dist/Fx/combinators/mergeAll.d.ts +34 -0
- package/dist/Fx/combinators/mergeAll.d.ts.map +1 -1
- package/dist/Fx/combinators/mergeAll.js +34 -0
- package/dist/Fx/combinators/mergeOrdered.d.ts +35 -3
- package/dist/Fx/combinators/mergeOrdered.d.ts.map +1 -1
- package/dist/Fx/combinators/mergeOrdered.js +35 -3
- package/dist/Fx/combinators/onError.d.ts +33 -3
- package/dist/Fx/combinators/onError.d.ts.map +1 -1
- package/dist/Fx/combinators/onError.js +33 -3
- package/dist/Fx/combinators/onExit.d.ts +28 -2
- package/dist/Fx/combinators/onExit.d.ts.map +1 -1
- package/dist/Fx/combinators/onExit.js +28 -2
- package/dist/Fx/combinators/onInterrupt.d.ts +48 -3
- package/dist/Fx/combinators/onInterrupt.d.ts.map +1 -1
- package/dist/Fx/combinators/onInterrupt.js +48 -3
- package/dist/Fx/combinators/pairwise.d.ts +28 -0
- package/dist/Fx/combinators/pairwise.d.ts.map +1 -0
- package/dist/Fx/combinators/pairwise.js +31 -0
- package/dist/Fx/combinators/provide.d.ts +138 -17
- package/dist/Fx/combinators/provide.d.ts.map +1 -1
- package/dist/Fx/combinators/provide.js +134 -13
- package/dist/Fx/combinators/race.d.ts +92 -0
- package/dist/Fx/combinators/race.d.ts.map +1 -0
- package/dist/Fx/combinators/race.js +149 -0
- package/dist/Fx/combinators/repeat.d.ts +41 -0
- package/dist/Fx/combinators/repeat.d.ts.map +1 -0
- package/dist/Fx/combinators/repeat.js +57 -0
- package/dist/Fx/combinators/result.d.ts +22 -0
- package/dist/Fx/combinators/result.d.ts.map +1 -1
- package/dist/Fx/combinators/result.js +26 -12
- package/dist/Fx/combinators/retry.d.ts +53 -0
- package/dist/Fx/combinators/retry.d.ts.map +1 -0
- package/dist/Fx/combinators/retry.js +71 -0
- package/dist/Fx/combinators/sample.d.ts +31 -0
- package/dist/Fx/combinators/sample.d.ts.map +1 -0
- package/dist/Fx/combinators/sample.js +42 -0
- package/dist/Fx/combinators/scan.d.ts +39 -0
- package/dist/Fx/combinators/scan.d.ts.map +1 -1
- package/dist/Fx/combinators/scan.js +41 -2
- package/dist/Fx/combinators/since.d.ts +30 -0
- package/dist/Fx/combinators/since.d.ts.map +1 -0
- package/dist/Fx/combinators/since.js +39 -0
- package/dist/Fx/combinators/skip.d.ts +31 -0
- package/dist/Fx/combinators/skip.d.ts.map +1 -1
- package/dist/Fx/combinators/skip.js +31 -0
- package/dist/Fx/combinators/skipRepeats.d.ts +16 -0
- package/dist/Fx/combinators/skipRepeats.d.ts.map +1 -1
- package/dist/Fx/combinators/skipRepeats.js +16 -0
- package/dist/Fx/combinators/skipRepeatsWith.d.ts +17 -0
- package/dist/Fx/combinators/skipRepeatsWith.d.ts.map +1 -1
- package/dist/Fx/combinators/skipRepeatsWith.js +17 -0
- package/dist/Fx/combinators/skipWhile.d.ts +68 -0
- package/dist/Fx/combinators/skipWhile.d.ts.map +1 -1
- package/dist/Fx/combinators/skipWhile.js +68 -0
- package/dist/Fx/combinators/slice.d.ts +82 -0
- package/dist/Fx/combinators/slice.d.ts.map +1 -1
- package/dist/Fx/combinators/slice.js +33 -0
- package/dist/Fx/combinators/switchMap.d.ts +38 -0
- package/dist/Fx/combinators/switchMap.d.ts.map +1 -1
- package/dist/Fx/combinators/switchMap.js +42 -4
- package/dist/Fx/combinators/switchMapEffect.d.ts +37 -0
- package/dist/Fx/combinators/switchMapEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/switchMapEffect.js +37 -0
- package/dist/Fx/combinators/take.d.ts +32 -0
- package/dist/Fx/combinators/take.d.ts.map +1 -1
- package/dist/Fx/combinators/take.js +32 -0
- package/dist/Fx/combinators/takeUntil.d.ts +46 -0
- package/dist/Fx/combinators/takeUntil.d.ts.map +1 -1
- package/dist/Fx/combinators/takeUntil.js +46 -0
- package/dist/Fx/combinators/takeWhile.d.ts +31 -0
- package/dist/Fx/combinators/takeWhile.d.ts.map +1 -1
- package/dist/Fx/combinators/takeWhile.js +31 -0
- package/dist/Fx/combinators/tapEffect.d.ts +16 -0
- package/dist/Fx/combinators/tapEffect.d.ts.map +1 -1
- package/dist/Fx/combinators/tapEffect.js +16 -0
- package/dist/Fx/combinators/throttle.d.ts +79 -0
- package/dist/Fx/combinators/throttle.d.ts.map +1 -0
- package/dist/Fx/combinators/throttle.js +99 -0
- package/dist/Fx/combinators/timeout.d.ts +76 -0
- package/dist/Fx/combinators/timeout.d.ts.map +1 -0
- package/dist/Fx/combinators/timeout.js +110 -0
- package/dist/Fx/combinators/tuple.d.ts +30 -0
- package/dist/Fx/combinators/tuple.d.ts.map +1 -1
- package/dist/Fx/combinators/tuple.js +34 -3
- package/dist/Fx/combinators/until.d.ts +27 -0
- package/dist/Fx/combinators/until.d.ts.map +1 -0
- package/dist/Fx/combinators/until.js +56 -0
- package/dist/Fx/combinators/unwrap.d.ts +29 -0
- package/dist/Fx/combinators/unwrap.d.ts.map +1 -1
- package/dist/Fx/combinators/unwrap.js +29 -0
- package/dist/Fx/combinators/unwrapScoped.d.ts +33 -0
- package/dist/Fx/combinators/unwrapScoped.d.ts.map +1 -1
- package/dist/Fx/combinators/unwrapScoped.js +33 -0
- package/dist/Fx/combinators/when.d.ts +35 -0
- package/dist/Fx/combinators/when.d.ts.map +1 -1
- package/dist/Fx/combinators/when.js +36 -1
- package/dist/Fx/combinators/withLatestFrom.d.ts +58 -0
- package/dist/Fx/combinators/withLatestFrom.d.ts.map +1 -0
- package/dist/Fx/combinators/withLatestFrom.js +68 -0
- package/dist/Fx/combinators/withSpan.d.ts +35 -1
- package/dist/Fx/combinators/withSpan.d.ts.map +1 -1
- package/dist/Fx/combinators/withSpan.js +34 -3
- package/dist/Fx/combinators/zip.d.ts +60 -0
- package/dist/Fx/combinators/zip.d.ts.map +1 -1
- package/dist/Fx/combinators/zip.js +60 -0
- package/dist/Fx/constructors/at.d.ts +20 -0
- package/dist/Fx/constructors/at.d.ts.map +1 -1
- package/dist/Fx/constructors/at.js +20 -0
- package/dist/Fx/constructors/die.d.ts +21 -0
- package/dist/Fx/constructors/die.d.ts.map +1 -1
- package/dist/Fx/constructors/die.js +21 -0
- package/dist/Fx/constructors/empty.d.ts +18 -0
- package/dist/Fx/constructors/empty.d.ts.map +1 -1
- package/dist/Fx/constructors/empty.js +18 -0
- package/dist/Fx/constructors/fail.d.ts +21 -0
- package/dist/Fx/constructors/fail.d.ts.map +1 -1
- package/dist/Fx/constructors/fail.js +21 -0
- package/dist/Fx/constructors/failCause.d.ts +22 -0
- package/dist/Fx/constructors/failCause.d.ts.map +1 -1
- package/dist/Fx/constructors/failCause.js +22 -0
- package/dist/Fx/constructors/fn.d.ts +113 -13
- package/dist/Fx/constructors/fn.d.ts.map +1 -1
- package/dist/Fx/constructors/fn.js +36 -0
- package/dist/Fx/constructors/fromEffect.d.ts +43 -1
- package/dist/Fx/constructors/fromEffect.d.ts.map +1 -1
- package/dist/Fx/constructors/fromEffect.js +43 -1
- package/dist/Fx/constructors/fromFailures.d.ts +24 -0
- package/dist/Fx/constructors/fromFailures.d.ts.map +1 -1
- package/dist/Fx/constructors/fromFailures.js +24 -0
- package/dist/Fx/constructors/fromIterable.d.ts +22 -0
- package/dist/Fx/constructors/fromIterable.d.ts.map +1 -1
- package/dist/Fx/constructors/fromIterable.js +22 -0
- package/dist/Fx/constructors/fromSchedule.d.ts +23 -0
- package/dist/Fx/constructors/fromSchedule.d.ts.map +1 -1
- package/dist/Fx/constructors/fromSchedule.js +25 -2
- package/dist/Fx/constructors/index.d.ts +2 -1
- package/dist/Fx/constructors/index.d.ts.map +1 -1
- package/dist/Fx/constructors/index.js +2 -1
- package/dist/Fx/constructors/interrupt.d.ts +21 -1
- package/dist/Fx/constructors/interrupt.d.ts.map +1 -1
- package/dist/Fx/constructors/interrupt.js +21 -1
- package/dist/Fx/constructors/make.d.ts +146 -1
- package/dist/Fx/constructors/make.d.ts.map +1 -1
- package/dist/Fx/constructors/make.js +56 -5
- package/dist/Fx/constructors/periodic.d.ts +29 -0
- package/dist/Fx/constructors/periodic.d.ts.map +1 -1
- package/dist/Fx/constructors/periodic.js +29 -0
- package/dist/Fx/constructors/succeed.d.ts +75 -3
- package/dist/Fx/constructors/succeed.d.ts.map +1 -1
- package/dist/Fx/constructors/succeed.js +75 -3
- package/dist/Fx/constructors/suspend.d.ts +28 -0
- package/dist/Fx/constructors/suspend.d.ts.map +1 -1
- package/dist/Fx/constructors/suspend.js +28 -0
- package/dist/Fx/constructors/sync.d.ts +32 -0
- package/dist/Fx/constructors/sync.d.ts.map +1 -0
- package/dist/Fx/constructors/sync.js +32 -0
- package/dist/Fx/internal/DeferredRef.d.ts +259 -7
- package/dist/Fx/internal/DeferredRef.d.ts.map +1 -1
- package/dist/Fx/internal/DeferredRef.js +260 -9
- package/dist/Fx/internal/UnionToTuple.d.ts +22 -0
- package/dist/Fx/internal/UnionToTuple.d.ts.map +1 -1
- package/dist/Fx/internal/diff.d.ts +586 -0
- package/dist/Fx/internal/diff.d.ts.map +1 -1
- package/dist/Fx/internal/diff.js +120 -9
- package/dist/Fx/internal/effectableEvaluateKey.d.ts +30 -0
- package/dist/Fx/internal/effectableEvaluateKey.d.ts.map +1 -0
- package/dist/Fx/internal/effectableEvaluateKey.js +29 -0
- package/dist/Fx/internal/effectableWithOverride.d.ts +55 -0
- package/dist/Fx/internal/effectableWithOverride.d.ts.map +1 -0
- package/dist/Fx/internal/effectableWithOverride.js +46 -0
- package/dist/Fx/internal/equivalence.d.ts +29 -0
- package/dist/Fx/internal/equivalence.d.ts.map +1 -1
- package/dist/Fx/internal/equivalence.js +29 -0
- package/dist/Fx/internal/multicast.d.ts +145 -2
- package/dist/Fx/internal/multicast.d.ts.map +1 -1
- package/dist/Fx/internal/multicast.js +146 -4
- package/dist/Fx/internal/ring-buffer.d.ts +149 -0
- package/dist/Fx/internal/ring-buffer.d.ts.map +1 -1
- package/dist/Fx/internal/ring-buffer.js +155 -0
- package/dist/Fx/internal/scope.d.ts +184 -0
- package/dist/Fx/internal/scope.d.ts.map +1 -1
- package/dist/Fx/internal/scope.js +150 -0
- package/dist/Fx/internal/yieldable.d.ts +117 -2
- package/dist/Fx/internal/yieldable.d.ts.map +1 -1
- package/dist/Fx/internal/yieldable.js +86 -3
- package/dist/Fx/run/collect.d.ts +89 -0
- package/dist/Fx/run/collect.d.ts.map +1 -1
- package/dist/Fx/run/collect.js +90 -1
- package/dist/Fx/run/first.d.ts +22 -0
- package/dist/Fx/run/first.d.ts.map +1 -1
- package/dist/Fx/run/first.js +22 -0
- package/dist/Fx/run/fork.d.ts +50 -0
- package/dist/Fx/run/fork.d.ts.map +1 -1
- package/dist/Fx/run/fork.js +50 -0
- package/dist/Fx/run/observe.d.ts +106 -0
- package/dist/Fx/run/observe.d.ts.map +1 -1
- package/dist/Fx/run/observe.js +108 -2
- package/dist/Fx/run/runPromise.d.ts +43 -0
- package/dist/Fx/run/runPromise.d.ts.map +1 -1
- package/dist/Fx/run/runPromise.js +43 -0
- package/dist/Fx/stream.d.ts +92 -0
- package/dist/Fx/stream.d.ts.map +1 -1
- package/dist/Fx/stream.js +60 -1
- package/dist/Push/Push.d.ts +1219 -94
- package/dist/Push/Push.d.ts.map +1 -1
- package/dist/Push/Push.js +1015 -86
- package/dist/RefArray.d.ts +2 -0
- package/dist/RefArray.d.ts.map +1 -0
- package/dist/RefArray.js +1 -0
- package/dist/RefBigDecimal.d.ts +2 -0
- package/dist/RefBigDecimal.d.ts.map +1 -0
- package/dist/RefBigDecimal.js +1 -0
- package/dist/RefBigInt.d.ts +2 -0
- package/dist/RefBigInt.d.ts.map +1 -0
- package/dist/RefBigInt.js +1 -0
- package/dist/RefBoolean.d.ts +2 -0
- package/dist/RefBoolean.d.ts.map +1 -0
- package/dist/RefBoolean.js +1 -0
- package/dist/RefCause.d.ts +2 -0
- package/dist/RefCause.d.ts.map +1 -0
- package/dist/RefCause.js +1 -0
- package/dist/RefChunk.d.ts +2 -0
- package/dist/RefChunk.d.ts.map +1 -0
- package/dist/RefChunk.js +1 -0
- package/dist/RefDateTime.d.ts +2 -0
- package/dist/RefDateTime.d.ts.map +1 -0
- package/dist/RefDateTime.js +1 -0
- package/dist/RefDuration.d.ts +2 -0
- package/dist/RefDuration.d.ts.map +1 -0
- package/dist/RefDuration.js +1 -0
- package/dist/RefGraph.d.ts +2 -0
- package/dist/RefGraph.d.ts.map +1 -0
- package/dist/RefGraph.js +1 -0
- package/dist/RefHashMap.d.ts +2 -0
- package/dist/RefHashMap.d.ts.map +1 -0
- package/dist/RefHashMap.js +1 -0
- package/dist/RefHashRing.d.ts +2 -0
- package/dist/RefHashRing.d.ts.map +1 -0
- package/dist/RefHashRing.js +1 -0
- package/dist/RefHashSet.d.ts +2 -0
- package/dist/RefHashSet.d.ts.map +1 -0
- package/dist/RefHashSet.js +1 -0
- package/dist/RefIterable.d.ts +2 -0
- package/dist/RefIterable.d.ts.map +1 -0
- package/dist/RefIterable.js +1 -0
- package/dist/RefOption.d.ts +2 -0
- package/dist/RefOption.d.ts.map +1 -0
- package/dist/RefOption.js +1 -0
- package/dist/RefRecord.d.ts +2 -0
- package/dist/RefRecord.d.ts.map +1 -0
- package/dist/RefRecord.js +1 -0
- package/dist/RefResult.d.ts +2 -0
- package/dist/RefResult.d.ts.map +1 -0
- package/dist/RefResult.js +1 -0
- package/dist/RefString.d.ts +2 -0
- package/dist/RefString.d.ts.map +1 -0
- package/dist/RefString.js +1 -0
- package/dist/RefStruct.d.ts +2 -0
- package/dist/RefStruct.d.ts.map +1 -0
- package/dist/RefStruct.js +1 -0
- package/dist/RefSubject/Hydration.d.ts +504 -0
- package/dist/RefSubject/Hydration.d.ts.map +1 -0
- package/dist/RefSubject/Hydration.js +300 -0
- package/dist/RefSubject/RefArray.d.ts +351 -4
- package/dist/RefSubject/RefArray.d.ts.map +1 -1
- package/dist/RefSubject/RefArray.js +339 -3
- package/dist/RefSubject/RefBigDecimal.d.ts +221 -1
- package/dist/RefSubject/RefBigDecimal.d.ts.map +1 -1
- package/dist/RefSubject/RefBigDecimal.js +210 -1
- package/dist/RefSubject/RefBigInt.d.ts +166 -1
- package/dist/RefSubject/RefBigInt.d.ts.map +1 -1
- package/dist/RefSubject/RefBigInt.js +155 -1
- package/dist/RefSubject/RefBoolean.d.ts +166 -1
- package/dist/RefSubject/RefBoolean.d.ts.map +1 -1
- package/dist/RefSubject/RefBoolean.js +155 -1
- package/dist/RefSubject/RefCause.d.ts +122 -1
- package/dist/RefSubject/RefCause.d.ts.map +1 -1
- package/dist/RefSubject/RefCause.js +111 -1
- package/dist/RefSubject/RefChunk.d.ts +406 -1
- package/dist/RefSubject/RefChunk.d.ts.map +1 -1
- package/dist/RefSubject/RefChunk.js +394 -0
- package/dist/RefSubject/RefDateTime.d.ts +122 -1
- package/dist/RefSubject/RefDateTime.d.ts.map +1 -1
- package/dist/RefSubject/RefDateTime.js +111 -1
- package/dist/RefSubject/RefDuration.d.ts +155 -1
- package/dist/RefSubject/RefDuration.d.ts.map +1 -1
- package/dist/RefSubject/RefDuration.js +144 -1
- package/dist/RefSubject/RefGraph.d.ts +320 -6
- package/dist/RefSubject/RefGraph.d.ts.map +1 -1
- package/dist/RefSubject/RefGraph.js +303 -0
- package/dist/RefSubject/RefHashMap.d.ts +296 -1
- package/dist/RefSubject/RefHashMap.d.ts.map +1 -1
- package/dist/RefSubject/RefHashMap.js +284 -0
- package/dist/RefSubject/RefHashRing.d.ts +146 -2
- package/dist/RefSubject/RefHashRing.d.ts.map +1 -1
- package/dist/RefSubject/RefHashRing.js +133 -0
- package/dist/RefSubject/RefHashSet.d.ts +230 -1
- package/dist/RefSubject/RefHashSet.d.ts.map +1 -1
- package/dist/RefSubject/RefHashSet.js +218 -0
- package/dist/RefSubject/RefIterable.d.ts +327 -1
- package/dist/RefSubject/RefIterable.d.ts.map +1 -1
- package/dist/RefSubject/RefIterable.js +315 -0
- package/dist/RefSubject/RefOption.d.ts +144 -1
- package/dist/RefSubject/RefOption.d.ts.map +1 -1
- package/dist/RefSubject/RefOption.js +133 -1
- package/dist/RefSubject/RefRecord.d.ts +339 -1
- package/dist/RefSubject/RefRecord.d.ts.map +1 -1
- package/dist/RefSubject/RefRecord.js +327 -0
- package/dist/RefSubject/RefResult.d.ts +155 -23
- package/dist/RefSubject/RefResult.d.ts.map +1 -1
- package/dist/RefSubject/RefResult.js +122 -1
- package/dist/RefSubject/RefString.d.ts +188 -1
- package/dist/RefSubject/RefString.d.ts.map +1 -1
- package/dist/RefSubject/RefString.js +177 -1
- package/dist/RefSubject/RefStruct.d.ts +156 -1
- package/dist/RefSubject/RefStruct.d.ts.map +1 -1
- package/dist/RefSubject/RefStruct.js +145 -1
- package/dist/RefSubject/RefSubject.d.ts +1168 -15
- package/dist/RefSubject/RefSubject.d.ts.map +1 -1
- package/dist/RefSubject/RefSubject.js +850 -58
- package/dist/RefSubject/RefTrie.d.ts +290 -4
- package/dist/RefSubject/RefTrie.d.ts.map +1 -1
- package/dist/RefSubject/RefTrie.js +278 -3
- package/dist/RefSubject/RefTuple.d.ts +117 -1
- package/dist/RefSubject/RefTuple.d.ts.map +1 -1
- package/dist/RefSubject/RefTuple.js +106 -1
- package/dist/RefSubject/index.d.ts +1 -0
- package/dist/RefSubject/index.d.ts.map +1 -1
- package/dist/RefSubject/index.js +1 -0
- package/dist/RefSubject.d.ts +2 -1
- package/dist/RefSubject.d.ts.map +1 -1
- package/dist/RefSubject.js +2 -1
- package/dist/RefTrie.d.ts +2 -0
- package/dist/RefTrie.d.ts.map +1 -0
- package/dist/RefTrie.js +1 -0
- package/dist/RefTuple.d.ts +2 -0
- package/dist/RefTuple.d.ts.map +1 -0
- package/dist/RefTuple.js +1 -0
- package/dist/Sink/Sink.d.ts +385 -14
- package/dist/Sink/Sink.d.ts.map +1 -1
- package/dist/Sink/Sink.js +53 -6
- package/dist/Sink/combinators.d.ts +731 -2
- package/dist/Sink/combinators.d.ts.map +1 -1
- package/dist/Sink/combinators.js +707 -5
- package/dist/Subject/Subject.d.ts +1016 -22
- package/dist/Subject/Subject.d.ts.map +1 -1
- package/dist/Subject/Subject.js +904 -39
- package/dist/Versioned/Versioned.d.ts +426 -9
- package/dist/Versioned/Versioned.d.ts.map +1 -1
- package/dist/Versioned/Versioned.js +241 -15
- package/dist/index.d.ts +22 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/package.json +120 -11
- package/dist/Fx/constructors/fromYieldable.d.ts +0 -12
- package/dist/Fx/constructors/fromYieldable.d.ts.map +0 -1
- package/dist/Fx/constructors/fromYieldable.js +0 -12
- package/src/Fx/Fx.ts +0 -164
- package/src/Fx/TypeId.ts +0 -25
- package/src/Fx/combinators/additive.ts +0 -142
- package/src/Fx/combinators/catch.ts +0 -416
- package/src/Fx/combinators/causes.ts +0 -23
- package/src/Fx/combinators/changesWithEffect.ts +0 -66
- package/src/Fx/combinators/compact.ts +0 -15
- package/src/Fx/combinators/continueWith.ts +0 -78
- package/src/Fx/combinators/dropUntil.ts +0 -47
- package/src/Fx/combinators/ensuring.ts +0 -23
- package/src/Fx/combinators/exhaustLatestMap.ts +0 -74
- package/src/Fx/combinators/exhaustLatestMapEffect.ts +0 -25
- package/src/Fx/combinators/exhaustMap.ts +0 -36
- package/src/Fx/combinators/exhaustMapEffect.ts +0 -23
- package/src/Fx/combinators/exit.ts +0 -15
- package/src/Fx/combinators/filter.ts +0 -22
- package/src/Fx/combinators/filterEffect.ts +0 -31
- package/src/Fx/combinators/filterMap.ts +0 -23
- package/src/Fx/combinators/filterMapEffect.ts +0 -32
- package/src/Fx/combinators/filterMapLoop.ts +0 -35
- package/src/Fx/combinators/filterMapLoopCause.ts +0 -36
- package/src/Fx/combinators/filterMapLoopCauseEffect.ts +0 -46
- package/src/Fx/combinators/filterMapLoopEffect.ts +0 -36
- package/src/Fx/combinators/flatMap.ts +0 -51
- package/src/Fx/combinators/flatMapConcurrently.ts +0 -39
- package/src/Fx/combinators/flatMapConcurrentlyEffect.ts +0 -26
- package/src/Fx/combinators/flatMapEffect.ts +0 -42
- package/src/Fx/combinators/flip.ts +0 -14
- package/src/Fx/combinators/gen.ts +0 -24
- package/src/Fx/combinators/genScoped.ts +0 -24
- package/src/Fx/combinators/index.ts +0 -61
- package/src/Fx/combinators/keyed.ts +0 -369
- package/src/Fx/combinators/loop.ts +0 -27
- package/src/Fx/combinators/loopCause.ts +0 -34
- package/src/Fx/combinators/loopCauseEffect.ts +0 -36
- package/src/Fx/combinators/loopEffect.ts +0 -34
- package/src/Fx/combinators/map.ts +0 -22
- package/src/Fx/combinators/mapBoth.ts +0 -40
- package/src/Fx/combinators/mapEffect.ts +0 -32
- package/src/Fx/combinators/mapError.ts +0 -28
- package/src/Fx/combinators/mergeAll.ts +0 -22
- package/src/Fx/combinators/mergeOrdered.ts +0 -123
- package/src/Fx/combinators/onError.ts +0 -40
- package/src/Fx/combinators/onExit.ts +0 -82
- package/src/Fx/combinators/onInterrupt.ts +0 -87
- package/src/Fx/combinators/provide.ts +0 -124
- package/src/Fx/combinators/result.ts +0 -39
- package/src/Fx/combinators/scan.ts +0 -82
- package/src/Fx/combinators/skip.ts +0 -41
- package/src/Fx/combinators/skipRepeats.ts +0 -15
- package/src/Fx/combinators/skipRepeatsWith.ts +0 -40
- package/src/Fx/combinators/skipWhile.ts +0 -100
- package/src/Fx/combinators/slice.ts +0 -55
- package/src/Fx/combinators/switchMap.ts +0 -55
- package/src/Fx/combinators/switchMapEffect.ts +0 -25
- package/src/Fx/combinators/take.ts +0 -38
- package/src/Fx/combinators/takeUntil.ts +0 -88
- package/src/Fx/combinators/takeWhile.ts +0 -47
- package/src/Fx/combinators/tapEffect.ts +0 -39
- package/src/Fx/combinators/tuple.ts +0 -79
- package/src/Fx/combinators/unwrap.ts +0 -21
- package/src/Fx/combinators/unwrapScoped.ts +0 -26
- package/src/Fx/combinators/when.ts +0 -64
- package/src/Fx/combinators/withSpan.ts +0 -24
- package/src/Fx/combinators/zip.ts +0 -175
- package/src/Fx/constructors/at.ts +0 -23
- package/src/Fx/constructors/die.ts +0 -17
- package/src/Fx/constructors/empty.ts +0 -10
- package/src/Fx/constructors/fail.ts +0 -14
- package/src/Fx/constructors/failCause.ts +0 -14
- package/src/Fx/constructors/fn.ts +0 -245
- package/src/Fx/constructors/fromEffect.ts +0 -24
- package/src/Fx/constructors/fromFailures.ts +0 -19
- package/src/Fx/constructors/fromIterable.ts +0 -15
- package/src/Fx/constructors/fromSchedule.ts +0 -18
- package/src/Fx/constructors/fromYieldable.ts +0 -17
- package/src/Fx/constructors/index.ts +0 -15
- package/src/Fx/constructors/interrupt.ts +0 -13
- package/src/Fx/constructors/make.ts +0 -103
- package/src/Fx/constructors/periodic.ts +0 -15
- package/src/Fx/constructors/succeed.ts +0 -37
- package/src/Fx/constructors/suspend.ts +0 -6
- package/src/Fx/index.ts +0 -6
- package/src/Fx/internal/DeferredRef.ts +0 -87
- package/src/Fx/internal/UnionToTuple.ts +0 -12
- package/src/Fx/internal/diff.ts +0 -191
- package/src/Fx/internal/equivalence.ts +0 -12
- package/src/Fx/internal/multicast.ts +0 -51
- package/src/Fx/internal/ring-buffer.ts +0 -60
- package/src/Fx/internal/scope.ts +0 -58
- package/src/Fx/internal/yieldable.ts +0 -31
- package/src/Fx/run/collect.ts +0 -79
- package/src/Fx/run/first.ts +0 -20
- package/src/Fx/run/fork.ts +0 -40
- package/src/Fx/run/index.ts +0 -5
- package/src/Fx/run/observe.ts +0 -114
- package/src/Fx/run/runPromise.ts +0 -32
- package/src/Fx/stream.ts +0 -42
- package/src/Fx.additive-combinators.test.ts +0 -126
- package/src/Fx.catch-additive.test.ts +0 -206
- package/src/Fx.catch.test.ts +0 -60
- package/src/Fx.dropUntil.test.ts +0 -61
- package/src/Fx.fn.test.ts +0 -51
- package/src/Fx.lifecycle.test.ts +0 -79
- package/src/Fx.mapError-mapBoth.test.ts +0 -101
- package/src/Fx.provide-combinators.test.ts +0 -94
- package/src/Fx.result-changesWithEffect.test.ts +0 -112
- package/src/Fx.scan.test.ts +0 -73
- package/src/Fx.takeWhile-skipWhile.test.ts +0 -84
- package/src/Fx.test.ts +0 -71
- package/src/Fx.ts +0 -1
- package/src/Fx.zip-merge-additive.test.ts +0 -171
- package/src/Fx.zip.test.ts +0 -133
- package/src/Push/Push.ts +0 -1072
- package/src/Push/index.ts +0 -1
- package/src/Push.additive.test.ts +0 -256
- package/src/Push.test.ts +0 -26
- package/src/Push.ts +0 -1
- package/src/RefSubject/RefArray.ts +0 -516
- package/src/RefSubject/RefBigDecimal.test.ts +0 -56
- package/src/RefSubject/RefBigDecimal.ts +0 -295
- package/src/RefSubject/RefBigInt.test.ts +0 -56
- package/src/RefSubject/RefBigInt.ts +0 -189
- package/src/RefSubject/RefBoolean.test.ts +0 -57
- package/src/RefSubject/RefBoolean.ts +0 -185
- package/src/RefSubject/RefCause.test.ts +0 -53
- package/src/RefSubject/RefCause.ts +0 -146
- package/src/RefSubject/RefChunk.ts +0 -516
- package/src/RefSubject/RefDateTime.test.ts +0 -43
- package/src/RefSubject/RefDateTime.ts +0 -261
- package/src/RefSubject/RefDuration.test.ts +0 -49
- package/src/RefSubject/RefDuration.ts +0 -188
- package/src/RefSubject/RefGraph.ts +0 -649
- package/src/RefSubject/RefHashMap.ts +0 -474
- package/src/RefSubject/RefHashRing.ts +0 -262
- package/src/RefSubject/RefHashSet.ts +0 -308
- package/src/RefSubject/RefIterable.ts +0 -454
- package/src/RefSubject/RefOption.test.ts +0 -67
- package/src/RefSubject/RefOption.ts +0 -193
- package/src/RefSubject/RefRecord.ts +0 -621
- package/src/RefSubject/RefResult.test.ts +0 -63
- package/src/RefSubject/RefResult.ts +0 -209
- package/src/RefSubject/RefString.test.ts +0 -61
- package/src/RefSubject/RefString.ts +0 -256
- package/src/RefSubject/RefStruct.test.ts +0 -60
- package/src/RefSubject/RefStruct.ts +0 -253
- package/src/RefSubject/RefSubject.ts +0 -2644
- package/src/RefSubject/RefTrie.ts +0 -365
- package/src/RefSubject/RefTuple.test.ts +0 -60
- package/src/RefSubject/RefTuple.ts +0 -231
- package/src/RefSubject/index.ts +0 -21
- package/src/RefSubject.additive-parity.test.ts +0 -101
- package/src/RefSubject.test.ts +0 -65
- package/src/RefSubject.ts +0 -1
- package/src/Sink/Sink.ts +0 -159
- package/src/Sink/combinators.ts +0 -1115
- package/src/Sink/index.ts +0 -2
- package/src/Sink.combinators.test.ts +0 -88
- package/src/Sink.reduce-collect-head-last.test.ts +0 -107
- package/src/Sink.ts +0 -1
- package/src/Subject/Subject.ts +0 -441
- package/src/Subject/index.ts +0 -1
- package/src/Subject.test.ts +0 -47
- package/src/Subject.ts +0 -1
- package/src/Versioned/Versioned.ts +0 -597
- package/src/Versioned/index.ts +0 -1
- package/src/Versioned.filterMap.test.ts +0 -91
- package/src/Versioned.test.ts +0 -23
- package/src/Versioned.ts +0 -1
- package/src/index.ts +0 -7
package/src/Sink/index.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { assert, describe, it } from "vitest";
|
|
2
|
-
import * as Cause from "effect/Cause";
|
|
3
|
-
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as Ref from "effect/Ref";
|
|
5
|
-
import { Fx, Sink } from "./index.js";
|
|
6
|
-
|
|
7
|
-
describe("Sink.mapError", () => {
|
|
8
|
-
it("maps failure cause before passing to inner sink", () =>
|
|
9
|
-
Effect.gen(function* () {
|
|
10
|
-
const failures = yield* Ref.make<Array<number>>([]);
|
|
11
|
-
const sink = Sink.make<unknown, number, never>(
|
|
12
|
-
(cause) =>
|
|
13
|
-
Ref.update(failures, (list) => {
|
|
14
|
-
const f = Cause.findFail(cause);
|
|
15
|
-
if (f._tag === "Success") list.push(f.success.error as number);
|
|
16
|
-
return list;
|
|
17
|
-
}),
|
|
18
|
-
() => Effect.void,
|
|
19
|
-
);
|
|
20
|
-
const mapped = Sink.mapError(sink, (s: string) => s.length);
|
|
21
|
-
yield* Fx.fail("err").run(mapped);
|
|
22
|
-
const list = yield* Ref.get(failures);
|
|
23
|
-
assert.deepStrictEqual(list, [3]);
|
|
24
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
25
|
-
|
|
26
|
-
it("preserves success path", () =>
|
|
27
|
-
Effect.gen(function* () {
|
|
28
|
-
const out = yield* Ref.make<number[]>([]);
|
|
29
|
-
const sink = Sink.make<number, string, never>(
|
|
30
|
-
(_cause) => Effect.void,
|
|
31
|
-
(n: number) => Ref.update(out, (arr) => [...arr, n]),
|
|
32
|
-
);
|
|
33
|
-
const mapped = Sink.mapError(sink, (e: string) => e);
|
|
34
|
-
yield* Fx.fromIterable([1, 2, 3]).run(mapped);
|
|
35
|
-
const list = yield* Ref.get(out);
|
|
36
|
-
assert.deepStrictEqual(list, [1, 2, 3]);
|
|
37
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("Sink.mapInput", () => {
|
|
41
|
-
it("transforms input before sink (same as map)", () =>
|
|
42
|
-
Effect.gen(function* () {
|
|
43
|
-
const out = yield* Ref.make<number[]>([]);
|
|
44
|
-
const sink = Sink.make(
|
|
45
|
-
() => Effect.void,
|
|
46
|
-
(n: number) => Ref.update(out, (arr) => [...arr, n]),
|
|
47
|
-
);
|
|
48
|
-
const mapped = Sink.mapInput(sink, (s: string) => parseInt(s, 10));
|
|
49
|
-
yield* Fx.fromIterable(["1", "2", "3"]).run(mapped);
|
|
50
|
-
const list = yield* Ref.get(out);
|
|
51
|
-
assert.deepStrictEqual(list, [1, 2, 3]);
|
|
52
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("Sink.mapInputEffect", () => {
|
|
56
|
-
it("transforms input with effect before sink (same as mapEffect)", () =>
|
|
57
|
-
Effect.gen(function* () {
|
|
58
|
-
const out = yield* Ref.make<number[]>([]);
|
|
59
|
-
const sink = Sink.make(
|
|
60
|
-
() => Effect.void,
|
|
61
|
-
(n: number) => Ref.update(out, (arr) => [...arr, n]),
|
|
62
|
-
);
|
|
63
|
-
const mapped = Sink.mapInputEffect(sink, (s: string) => Effect.succeed(parseInt(s, 10)));
|
|
64
|
-
yield* Fx.fromIterable(["1", "2", "3"]).run(mapped);
|
|
65
|
-
const list = yield* Ref.get(out);
|
|
66
|
-
assert.deepStrictEqual(list, [1, 2, 3]);
|
|
67
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
68
|
-
|
|
69
|
-
it("propagates effect failure to sink onFailure", () =>
|
|
70
|
-
Effect.gen(function* () {
|
|
71
|
-
const failures = yield* Ref.make<Array<string>>([]);
|
|
72
|
-
const sink = Sink.make<number, string, never>(
|
|
73
|
-
(cause) =>
|
|
74
|
-
Ref.update(failures, (list) => {
|
|
75
|
-
const f = Cause.findFail(cause);
|
|
76
|
-
if (f._tag === "Success") list.push(f.success.error as string);
|
|
77
|
-
return list;
|
|
78
|
-
}),
|
|
79
|
-
(_n: number) => Effect.void,
|
|
80
|
-
);
|
|
81
|
-
const mapped = Sink.mapInputEffect(sink, (s: string) =>
|
|
82
|
-
s === "bad" ? Effect.fail("parse failed") : Effect.succeed(parseInt(s, 10)),
|
|
83
|
-
);
|
|
84
|
-
yield* Fx.fromIterable(["1", "bad", "3"]).run(mapped);
|
|
85
|
-
const list = yield* Ref.get(failures);
|
|
86
|
-
assert.deepStrictEqual(list, ["parse failed"]);
|
|
87
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
88
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { assert, describe, it } from "vitest";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as Option from "effect/Option";
|
|
4
|
-
import * as Ref from "effect/Ref";
|
|
5
|
-
import { Fx, Sink } from "./index.js";
|
|
6
|
-
|
|
7
|
-
describe("Sink.reduce", () => {
|
|
8
|
-
it("reduces values with pure function", () =>
|
|
9
|
-
Effect.gen(function* () {
|
|
10
|
-
const ref = yield* Ref.make(0);
|
|
11
|
-
const sink = Sink.reduce(ref, (acc: number, n: number) => acc + n);
|
|
12
|
-
yield* Fx.fromIterable([1, 2, 3]).run(sink);
|
|
13
|
-
const result = yield* Ref.get(ref);
|
|
14
|
-
assert.strictEqual(result, 6);
|
|
15
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
16
|
-
|
|
17
|
-
it("uses initial value when no elements", () =>
|
|
18
|
-
Effect.gen(function* () {
|
|
19
|
-
const ref = yield* Ref.make(10);
|
|
20
|
-
const sink = Sink.reduce(ref, (acc: number, n: number) => acc + n);
|
|
21
|
-
yield* Fx.fromIterable<number>([]).run(sink);
|
|
22
|
-
const result = yield* Ref.get(ref);
|
|
23
|
-
assert.strictEqual(result, 10);
|
|
24
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe("Sink.reduceEffect", () => {
|
|
28
|
-
it("reduces values with effectful function", () =>
|
|
29
|
-
Effect.gen(function* () {
|
|
30
|
-
const ref = yield* Ref.make(0);
|
|
31
|
-
const sink = Sink.reduceEffect(ref, (acc: number, n: number) => Effect.succeed(acc + n));
|
|
32
|
-
yield* Fx.fromIterable([1, 2, 3]).run(sink);
|
|
33
|
-
const result = yield* Ref.get(ref);
|
|
34
|
-
assert.strictEqual(result, 6);
|
|
35
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
36
|
-
|
|
37
|
-
it("skips step when reducer effect fails, continues with rest", () =>
|
|
38
|
-
Effect.gen(function* () {
|
|
39
|
-
const ref = yield* Ref.make(0);
|
|
40
|
-
const sink = Sink.reduceEffect(ref, (acc: number, n: number) =>
|
|
41
|
-
n === 2 ? Effect.fail("skip") : Effect.succeed(acc + n),
|
|
42
|
-
);
|
|
43
|
-
yield* Fx.fromIterable([1, 2, 3]).run(sink);
|
|
44
|
-
const result = yield* Ref.get(ref);
|
|
45
|
-
assert.strictEqual(result, 4);
|
|
46
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe("Sink.collect", () => {
|
|
50
|
-
it("collects all values into array", () =>
|
|
51
|
-
Effect.gen(function* () {
|
|
52
|
-
const ref = yield* Ref.make<ReadonlyArray<number>>([]);
|
|
53
|
-
const sink = Sink.collect(ref);
|
|
54
|
-
yield* Fx.fromIterable([1, 2, 3]).run(sink);
|
|
55
|
-
const result = yield* Ref.get(ref);
|
|
56
|
-
assert.deepStrictEqual(result, [1, 2, 3]);
|
|
57
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
58
|
-
|
|
59
|
-
it("returns empty array when no elements", () =>
|
|
60
|
-
Effect.gen(function* () {
|
|
61
|
-
const ref = yield* Ref.make<ReadonlyArray<number>>([]);
|
|
62
|
-
const sink = Sink.collect(ref);
|
|
63
|
-
yield* Fx.fromIterable<number>([]).run(sink);
|
|
64
|
-
const result = yield* Ref.get(ref);
|
|
65
|
-
assert.deepStrictEqual(result, []);
|
|
66
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe("Sink.head", () => {
|
|
70
|
-
it("keeps only first value", () =>
|
|
71
|
-
Effect.gen(function* () {
|
|
72
|
-
const ref = yield* Ref.make(Option.none<number>());
|
|
73
|
-
const sink = Sink.head(ref);
|
|
74
|
-
yield* Fx.fromIterable([1, 2, 3]).run(sink);
|
|
75
|
-
const result = yield* Ref.get(ref);
|
|
76
|
-
assert.deepStrictEqual(result, Option.some(1));
|
|
77
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
78
|
-
|
|
79
|
-
it("remains none when no elements", () =>
|
|
80
|
-
Effect.gen(function* () {
|
|
81
|
-
const ref = yield* Ref.make(Option.none<number>());
|
|
82
|
-
const sink = Sink.head(ref);
|
|
83
|
-
yield* Fx.fromIterable<number>([]).run(sink);
|
|
84
|
-
const result = yield* Ref.get(ref);
|
|
85
|
-
assert.deepStrictEqual(result, Option.none());
|
|
86
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("Sink.last", () => {
|
|
90
|
-
it("keeps only last value", () =>
|
|
91
|
-
Effect.gen(function* () {
|
|
92
|
-
const ref = yield* Ref.make(Option.none<number>());
|
|
93
|
-
const sink = Sink.last(ref);
|
|
94
|
-
yield* Fx.fromIterable([1, 2, 3]).run(sink);
|
|
95
|
-
const result = yield* Ref.get(ref);
|
|
96
|
-
assert.deepStrictEqual(result, Option.some(3));
|
|
97
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
98
|
-
|
|
99
|
-
it("remains none when no elements", () =>
|
|
100
|
-
Effect.gen(function* () {
|
|
101
|
-
const ref = yield* Ref.make(Option.none<number>());
|
|
102
|
-
const sink = Sink.last(ref);
|
|
103
|
-
yield* Fx.fromIterable<number>([]).run(sink);
|
|
104
|
-
const result = yield* Ref.get(ref);
|
|
105
|
-
assert.deepStrictEqual(result, Option.none());
|
|
106
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
107
|
-
});
|
package/src/Sink.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Sink/index.js";
|
package/src/Subject/Subject.ts
DELETED
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
import type * as Cause from "effect/Cause";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as Exit from "effect/Exit";
|
|
4
|
-
import * as Fiber from "effect/Fiber";
|
|
5
|
-
import { dual, identity } from "effect/Function";
|
|
6
|
-
import * as Layer from "effect/Layer";
|
|
7
|
-
import * as MutableRef from "effect/MutableRef";
|
|
8
|
-
import * as Option from "effect/Option";
|
|
9
|
-
import { pipeArguments } from "effect/Pipeable";
|
|
10
|
-
import * as Scope from "effect/Scope";
|
|
11
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
12
|
-
import type * as Fx from "../Fx/index.js";
|
|
13
|
-
import { RingBuffer } from "../Fx/internal/ring-buffer.js";
|
|
14
|
-
import { awaitScopeClose, withExtendedScope } from "../Fx/internal/scope.js";
|
|
15
|
-
import { FxTypeId } from "../Fx/TypeId.js";
|
|
16
|
-
import type * as Sink from "../Sink/Sink.js";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A `Subject` is an `Fx` that allows for imperative pushing of values.
|
|
20
|
-
* It also acts as a `Sink`, meaning you can `run` another `Fx` into it.
|
|
21
|
-
*
|
|
22
|
-
* @since 1.0.0
|
|
23
|
-
* @category models
|
|
24
|
-
*/
|
|
25
|
-
export interface Subject<A, E = never, R = never>
|
|
26
|
-
extends Fx.Fx<A, E, R | Scope.Scope>, Sink.Sink<A, E, R> {
|
|
27
|
-
/**
|
|
28
|
-
* The number of current subscribers to this Subject.
|
|
29
|
-
*/
|
|
30
|
-
readonly subscriberCount: Effect.Effect<number, never, R>;
|
|
31
|
-
/**
|
|
32
|
-
* Interrupts all subscribers and clears the subject.
|
|
33
|
-
*/
|
|
34
|
-
readonly interrupt: Effect.Effect<void, never, R>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export declare namespace Subject {
|
|
38
|
-
export interface Service<Self, Id extends string, A, E> extends Subject<A, E, Self> {
|
|
39
|
-
readonly id: Id;
|
|
40
|
-
readonly service: ServiceMap.Service<Self, Subject<A, E>>;
|
|
41
|
-
readonly make: (replay?: number) => Layer.Layer<Self, never, Scope.Scope>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface Class<Self, Id extends string, A, E> extends Service<Self, Id, A, E> {
|
|
45
|
-
new (): Service<Self, Id, A, E>;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Shares the execution of an Fx among multiple subscribers using a Subject.
|
|
51
|
-
* The source Fx is started when the first subscriber arrives and stopped when the last one leaves.
|
|
52
|
-
*
|
|
53
|
-
* @param fx - The source Fx.
|
|
54
|
-
* @param subject - The subject to use for multicasting.
|
|
55
|
-
* @returns A shared `Fx`.
|
|
56
|
-
* @since 1.0.0
|
|
57
|
-
* @category combinators
|
|
58
|
-
*/
|
|
59
|
-
export function share<A, E, R, R2>(
|
|
60
|
-
fx: Fx.Fx<A, E, R>,
|
|
61
|
-
subject: Subject<A, E, R2>,
|
|
62
|
-
): Fx.Fx<A, E, R | R2 | Scope.Scope> {
|
|
63
|
-
return new Share(fx, subject);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
class RefCounter {
|
|
67
|
-
_RefCount: MutableRef.MutableRef<number> = MutableRef.make(0);
|
|
68
|
-
|
|
69
|
-
increment() {
|
|
70
|
-
return MutableRef.updateAndGet(this._RefCount, (n) => n + 1);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
decrement() {
|
|
74
|
-
return MutableRef.updateAndGet(this._RefCount, (n) => Math.max(0, n - 1));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const VARIANCE: Fx.Fx.Variance<any, any, any> = {
|
|
79
|
-
_A: identity,
|
|
80
|
-
_E: identity,
|
|
81
|
-
_R: identity,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export class Share<A, E, R, R2> implements Fx.Fx<A, E, R | R2 | Scope.Scope> {
|
|
85
|
-
readonly [FxTypeId]: Fx.Fx.Variance<A, E, R | R2 | Scope.Scope> = VARIANCE;
|
|
86
|
-
|
|
87
|
-
_FxFiber: MutableRef.MutableRef<Option.Option<Fiber.Fiber<unknown>>> = MutableRef.make(
|
|
88
|
-
Option.none(),
|
|
89
|
-
);
|
|
90
|
-
_RefCount = new RefCounter();
|
|
91
|
-
|
|
92
|
-
readonly i0: Fx.Fx<A, E, R>;
|
|
93
|
-
readonly i1: Subject<A, E, R2>;
|
|
94
|
-
|
|
95
|
-
constructor(i0: Fx.Fx<A, E, R>, i1: Subject<A, E, R2>) {
|
|
96
|
-
this.i0 = i0;
|
|
97
|
-
this.i1 = i1;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
pipe() {
|
|
101
|
-
return pipeArguments(this, arguments);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
run<R3>(sink: Sink.Sink<A, E, R3>): Effect.Effect<unknown, never, R | R2 | R3 | Scope.Scope> {
|
|
105
|
-
return Effect.flatMap(this.initialize(), () =>
|
|
106
|
-
Effect.onExit(this.i1.run(sink), () =>
|
|
107
|
-
this._RefCount.decrement() === 0 ? this.interrupt() : Effect.void,
|
|
108
|
-
),
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private initialize(): Effect.Effect<unknown, never, R | R2> {
|
|
113
|
-
return Effect.suspend((): Effect.Effect<unknown, never, R | R2> => {
|
|
114
|
-
if (this._RefCount.increment() === 1) {
|
|
115
|
-
return this.i0.run(this.i1).pipe(
|
|
116
|
-
Effect.ensuring(
|
|
117
|
-
Effect.suspend(() => {
|
|
118
|
-
MutableRef.set(this._FxFiber, Option.none());
|
|
119
|
-
return this.i1.interrupt;
|
|
120
|
-
}),
|
|
121
|
-
),
|
|
122
|
-
Effect.interruptible,
|
|
123
|
-
Effect.forkDetach,
|
|
124
|
-
Effect.tap((fiber) =>
|
|
125
|
-
Effect.sync(() => MutableRef.set(this._FxFiber, Option.some(fiber))),
|
|
126
|
-
),
|
|
127
|
-
);
|
|
128
|
-
} else {
|
|
129
|
-
return Effect.void;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private interrupt(): Effect.Effect<void, never, R | R2> {
|
|
135
|
-
return Option.match(MutableRef.getAndSet(this._FxFiber, Option.none()), {
|
|
136
|
-
onNone: () => Effect.void,
|
|
137
|
-
onSome: Fiber.interrupt,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Multicasts an Fx to multiple subscribers.
|
|
144
|
-
* The source Fx is shared, so side effects only happen once per active session (ref count > 0).
|
|
145
|
-
*
|
|
146
|
-
* @param fx - The source Fx.
|
|
147
|
-
* @returns A multicasted `Fx`.
|
|
148
|
-
* @since 1.0.0
|
|
149
|
-
* @category combinators
|
|
150
|
-
*/
|
|
151
|
-
export function multicast<A, E, R>(fx: Fx.Fx<A, E, R>): Fx.Fx<A, E, R | Scope.Scope> {
|
|
152
|
-
return new Share(fx, unsafeMake<A, E>(0));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Holds the latest value emitted by the Fx and replays it to new subscribers.
|
|
157
|
-
*
|
|
158
|
-
* @param fx - The source Fx.
|
|
159
|
-
* @returns A shared `Fx` that replays the latest value.
|
|
160
|
-
* @since 1.0.0
|
|
161
|
-
* @category combinators
|
|
162
|
-
*/
|
|
163
|
-
export function hold<A, E, R>(fx: Fx.Fx<A, E, R>): Fx.Fx<A, E, R | Scope.Scope> {
|
|
164
|
-
return new Share(fx, unsafeMake<A, E>(1));
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Replays the last `capacity` values emitted by the Fx to new subscribers.
|
|
169
|
-
*
|
|
170
|
-
* @param capacity - The number of values to buffer and replay.
|
|
171
|
-
* @param fx - The source Fx.
|
|
172
|
-
* @returns A shared `Fx` that replays values.
|
|
173
|
-
* @since 1.0.0
|
|
174
|
-
* @category combinators
|
|
175
|
-
*/
|
|
176
|
-
export const replay: {
|
|
177
|
-
(capacity: number): <A, E, R>(fx: Fx.Fx<A, E, R>) => Fx.Fx<A, E, R>;
|
|
178
|
-
<A, E, R>(fx: Fx.Fx<A, E, R>, capacity: number): Fx.Fx<A, E, R>;
|
|
179
|
-
} = dual(2, function replay<A, E, R>(fx: Fx.Fx<A, E, R>, capacity: number): Fx.Fx<
|
|
180
|
-
A,
|
|
181
|
-
E,
|
|
182
|
-
R | Scope.Scope
|
|
183
|
-
> {
|
|
184
|
-
return new Share(fx, unsafeMake<A, E>(capacity));
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
const DISCARD = { discard: true } as const;
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* @internal
|
|
191
|
-
*/
|
|
192
|
-
export class SubjectImpl<A, E> implements Subject<A, E> {
|
|
193
|
-
readonly [FxTypeId]: Fx.Fx.Variance<A, E, Scope.Scope> = VARIANCE;
|
|
194
|
-
protected sinks: Set<
|
|
195
|
-
readonly [Sink.Sink<A, E, any>, ServiceMap.ServiceMap<any>, Scope.Closeable]
|
|
196
|
-
> = new Set();
|
|
197
|
-
|
|
198
|
-
constructor() {
|
|
199
|
-
this.onFailure = this.onFailure.bind(this);
|
|
200
|
-
this.onSuccess = this.onSuccess.bind(this);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
pipe() {
|
|
204
|
-
return pipeArguments(this, arguments);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
run<R2>(sink: Sink.Sink<A, E, R2>): Effect.Effect<unknown, never, R2 | Scope.Scope> {
|
|
208
|
-
return this.addSink(sink, awaitScopeClose);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
onFailure(cause: Cause.Cause<E>) {
|
|
212
|
-
return this.onCause(cause);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
onSuccess(a: A) {
|
|
216
|
-
return this.onEvent(a);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
protected interruptScopes = Effect.withFiber((fiber) =>
|
|
220
|
-
Effect.forEach(
|
|
221
|
-
Array.from(this.sinks),
|
|
222
|
-
([, , scope]) => Scope.close(scope, Exit.interrupt(fiber.id)),
|
|
223
|
-
DISCARD,
|
|
224
|
-
),
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
readonly interrupt = this.interruptScopes;
|
|
228
|
-
|
|
229
|
-
protected addSink<R, B, R2>(
|
|
230
|
-
sink: Sink.Sink<A, E, R>,
|
|
231
|
-
f: (scope: Scope.Scope) => Effect.Effect<B, never, R2>,
|
|
232
|
-
): Effect.Effect<B, never, R2 | Scope.Scope> {
|
|
233
|
-
return withExtendedScope(
|
|
234
|
-
(innerScope) =>
|
|
235
|
-
Effect.servicesWith((ctx) => {
|
|
236
|
-
const entry = [sink, ctx, innerScope] as const;
|
|
237
|
-
this.sinks.add(entry);
|
|
238
|
-
const remove = Effect.sync(() => this.sinks.delete(entry));
|
|
239
|
-
|
|
240
|
-
return Effect.flatMap(Scope.addFinalizer(innerScope, remove), () => f(innerScope));
|
|
241
|
-
}),
|
|
242
|
-
"sequential",
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
readonly subscriberCount: Effect.Effect<number> = Effect.sync(() => this.sinks.size);
|
|
247
|
-
|
|
248
|
-
protected onEvent(a: A): Effect.Effect<void, never, never> {
|
|
249
|
-
if (this.sinks.size === 0) return Effect.void;
|
|
250
|
-
else if (this.sinks.size === 1) {
|
|
251
|
-
const [sink, ctx] = this.sinks.values().next().value!;
|
|
252
|
-
return runSinkEvent(sink, ctx, a);
|
|
253
|
-
} else {
|
|
254
|
-
return Effect.forEach(this.sinks, ([sink, ctx]) => runSinkEvent(sink, ctx, a), DISCARD);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
protected onCause(cause: Cause.Cause<E>) {
|
|
259
|
-
if (this.sinks.size === 0) return Effect.void;
|
|
260
|
-
else if (this.sinks.size === 1) {
|
|
261
|
-
const [sink, ctx, scope] = this.sinks.values().next().value!;
|
|
262
|
-
return runSinkCause(sink, ctx, scope, cause);
|
|
263
|
-
} else {
|
|
264
|
-
return Effect.forEach(
|
|
265
|
-
this.sinks,
|
|
266
|
-
([sink, ctx, scope]) => runSinkCause(sink, ctx, scope, cause),
|
|
267
|
-
DISCARD,
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function runSinkEvent<A, E>(
|
|
274
|
-
sink: Sink.Sink<A, E, any>,
|
|
275
|
-
ctx: ServiceMap.ServiceMap<any>,
|
|
276
|
-
a: A,
|
|
277
|
-
): Effect.Effect<void, never, never> {
|
|
278
|
-
return Effect.provide(Effect.catchCause(sink.onSuccess(a), sink.onFailure), ctx);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function runSinkCause<A, E>(
|
|
282
|
-
sink: Sink.Sink<A, E, any>,
|
|
283
|
-
ctx: ServiceMap.ServiceMap<any>,
|
|
284
|
-
scope: Scope.Closeable,
|
|
285
|
-
cause: Cause.Cause<E>,
|
|
286
|
-
): Effect.Effect<void, never, never> {
|
|
287
|
-
return Effect.provide(
|
|
288
|
-
Effect.catchCause(sink.onFailure(cause), (error) => Scope.close(scope, Exit.failCause(error))),
|
|
289
|
-
ctx,
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* @internal
|
|
295
|
-
*/
|
|
296
|
-
export class HoldSubjectImpl<A, E> extends SubjectImpl<A, E> implements Subject<A, E> {
|
|
297
|
-
readonly lastValue: MutableRef.MutableRef<Option.Option<Exit.Exit<A, E>>> = MutableRef.make(
|
|
298
|
-
Option.none(),
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
override onSuccess = (a: A): Effect.Effect<void, never, never> =>
|
|
302
|
-
Effect.suspend(() => {
|
|
303
|
-
// Keep track of the last value emitted by the subject
|
|
304
|
-
MutableRef.set(this.lastValue, Option.some(Exit.succeed(a)));
|
|
305
|
-
|
|
306
|
-
return this.onEvent(a);
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
override onFailure = (cause: Cause.Cause<E>): Effect.Effect<void, never, never> => {
|
|
310
|
-
return Effect.suspend(() => {
|
|
311
|
-
// Keep track of the last value emitted by the subject
|
|
312
|
-
MutableRef.set(this.lastValue, Option.some(Exit.failCause(cause)));
|
|
313
|
-
|
|
314
|
-
return this.onCause(cause);
|
|
315
|
-
});
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
override run<R2>(sink: Sink.Sink<A, E, R2>): Effect.Effect<unknown, never, R2 | Scope.Scope> {
|
|
319
|
-
return this.addSink(sink, (scope) =>
|
|
320
|
-
Option.match(MutableRef.get(this.lastValue), {
|
|
321
|
-
onNone: () => awaitScopeClose(scope),
|
|
322
|
-
// If we have a previous value, emit it first
|
|
323
|
-
onSome: (exit) => Effect.flatMap(Exit.match(exit, sink), () => awaitScopeClose(scope)),
|
|
324
|
-
}),
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
override readonly interrupt = Effect.tap(
|
|
329
|
-
this.interruptScopes,
|
|
330
|
-
Effect.sync(() => MutableRef.set(this.lastValue, Option.none())),
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* @internal
|
|
336
|
-
*/
|
|
337
|
-
export class ReplaySubjectImpl<A, E> extends SubjectImpl<A, E> {
|
|
338
|
-
readonly buffer: RingBuffer<Exit.Exit<A, E>>;
|
|
339
|
-
|
|
340
|
-
constructor(buffer: RingBuffer<Exit.Exit<A, E>>) {
|
|
341
|
-
super();
|
|
342
|
-
this.buffer = buffer;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
override onSuccess = (a: A): Effect.Effect<void, never, never> =>
|
|
346
|
-
Effect.suspend(() => {
|
|
347
|
-
// Keep track of the last value emitted by the subject
|
|
348
|
-
this.buffer.push(Exit.succeed(a));
|
|
349
|
-
return this.onEvent(a);
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
override onFailure = (cause: Cause.Cause<E>): Effect.Effect<void, never, never> =>
|
|
353
|
-
Effect.suspend(() => {
|
|
354
|
-
this.buffer.push(Exit.failCause(cause));
|
|
355
|
-
return this.onCause(cause);
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
override run<R2>(sink: Sink.Sink<A, E, R2>): Effect.Effect<unknown, never, R2 | Scope.Scope> {
|
|
359
|
-
return this.addSink(sink, (scope) =>
|
|
360
|
-
Effect.flatMap(this.buffer.forEach(Exit.match(sink)), () => awaitScopeClose(scope)),
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
override readonly interrupt = Effect.tap(
|
|
365
|
-
this.interruptScopes,
|
|
366
|
-
Effect.sync(() => this.buffer.clear()),
|
|
367
|
-
);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Creates a `Subject` that replays the last `replay` values. You will need to manually call `interrupt` on the subject to clear resources.
|
|
372
|
-
* @param replay - The number of values to replay.
|
|
373
|
-
* @returns A `Subject` that replays the last `replay` values.
|
|
374
|
-
*/
|
|
375
|
-
export function unsafeMake<A, E = never>(replay: number = 0): Subject<A, E> {
|
|
376
|
-
replay = Math.max(0, replay);
|
|
377
|
-
|
|
378
|
-
if (replay === 0) {
|
|
379
|
-
return new SubjectImpl<A, E>();
|
|
380
|
-
} else if (replay === 1) {
|
|
381
|
-
return new HoldSubjectImpl<A, E>();
|
|
382
|
-
} else {
|
|
383
|
-
return new ReplaySubjectImpl<A, E>(new RingBuffer(replay));
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Create a Subject which utilizes a Scope to manage the lifecycle of the subject's resources.
|
|
389
|
-
*/
|
|
390
|
-
export function make<A, E = never>(
|
|
391
|
-
replay?: number,
|
|
392
|
-
): Effect.Effect<Subject<A, E>, never, Scope.Scope> {
|
|
393
|
-
return Effect.acquireRelease(
|
|
394
|
-
Effect.sync(() => unsafeMake(replay)),
|
|
395
|
-
(subject) => subject.interrupt,
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
export function Service<Self, A, E = never>() {
|
|
400
|
-
return <const Id extends string>(id: Id): Subject.Class<Self, Id, A, E> => {
|
|
401
|
-
const service = ServiceMap.Service<Self, Subject<A, E>>(id);
|
|
402
|
-
|
|
403
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
404
|
-
return class SubjectService {
|
|
405
|
-
static readonly id = id;
|
|
406
|
-
static readonly service = service;
|
|
407
|
-
|
|
408
|
-
static readonly make = (replay?: number): Layer.Layer<Self, never, Scope.Scope> =>
|
|
409
|
-
Layer.effect(service, make<A, E>(replay));
|
|
410
|
-
|
|
411
|
-
static readonly [FxTypeId] = VARIANCE;
|
|
412
|
-
static readonly pipe = function (this: any) {
|
|
413
|
-
return pipeArguments(this, arguments);
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
// Fx
|
|
417
|
-
static readonly run = <RSink>(sink: Sink.Sink<A, E, RSink>) =>
|
|
418
|
-
Effect.flatMap(service.asEffect(), (subject) => subject.run(sink));
|
|
419
|
-
|
|
420
|
-
// Sink
|
|
421
|
-
static readonly onSuccess = (value: A) =>
|
|
422
|
-
Effect.flatMap(service.asEffect(), (subject) => subject.onSuccess(value));
|
|
423
|
-
static readonly onFailure = (cause: Cause.Cause<E>) =>
|
|
424
|
-
Effect.flatMap(service.asEffect(), (subject) => subject.onFailure(cause));
|
|
425
|
-
|
|
426
|
-
// Subject
|
|
427
|
-
static readonly subscriberCount = Effect.flatMap(
|
|
428
|
-
service.asEffect(),
|
|
429
|
-
(subject) => subject.subscriberCount,
|
|
430
|
-
);
|
|
431
|
-
static readonly interrupt = Effect.flatMap(
|
|
432
|
-
service.asEffect(),
|
|
433
|
-
(subject) => subject.interrupt,
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
constructor() {
|
|
437
|
-
return SubjectService;
|
|
438
|
-
}
|
|
439
|
-
} as unknown as Subject.Class<Self, Id, A, E>;
|
|
440
|
-
};
|
|
441
|
-
}
|
package/src/Subject/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Subject.js";
|
package/src/Subject.test.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as Fiber from "effect/Fiber";
|
|
4
|
-
import * as Fx from "./Fx/index.js";
|
|
5
|
-
import * as Subject from "./Subject.js";
|
|
6
|
-
|
|
7
|
-
describe("Subject", () => {
|
|
8
|
-
it("allows multicasting values", () =>
|
|
9
|
-
Effect.gen(function* () {
|
|
10
|
-
const subject = Subject.unsafeMake<number>();
|
|
11
|
-
const fiber = yield* Fx.collectAllFork(subject);
|
|
12
|
-
yield* Effect.yieldNow;
|
|
13
|
-
|
|
14
|
-
yield* subject.onSuccess(1);
|
|
15
|
-
yield* subject.onSuccess(2);
|
|
16
|
-
yield* subject.onSuccess(3);
|
|
17
|
-
yield* subject.interrupt;
|
|
18
|
-
|
|
19
|
-
expect(yield* Fiber.join(fiber)).toEqual([1, 2, 3]);
|
|
20
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
21
|
-
|
|
22
|
-
it("allows replay of values", () =>
|
|
23
|
-
Effect.gen(function* () {
|
|
24
|
-
const subject = Subject.unsafeMake<number>(2);
|
|
25
|
-
|
|
26
|
-
yield* subject.onSuccess(1);
|
|
27
|
-
yield* subject.onSuccess(2);
|
|
28
|
-
yield* subject.onSuccess(3);
|
|
29
|
-
|
|
30
|
-
expect(yield* Fx.collectAll(Fx.take(subject, 2))).toEqual([2, 3]);
|
|
31
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
32
|
-
|
|
33
|
-
describe("Service", () => {
|
|
34
|
-
it("should allow defining a Subject as a Service", () =>
|
|
35
|
-
Effect.gen(function* () {
|
|
36
|
-
class MySubject extends Subject.Service<MySubject, number>()("MySubject") {}
|
|
37
|
-
|
|
38
|
-
const layer = MySubject.make(1);
|
|
39
|
-
|
|
40
|
-
yield* Effect.gen(function* () {
|
|
41
|
-
yield* MySubject.onSuccess(1);
|
|
42
|
-
const result = yield* Fx.collectAll(Fx.take(MySubject, 1));
|
|
43
|
-
expect(result).toEqual([1]);
|
|
44
|
-
}).pipe(Effect.provide(layer));
|
|
45
|
-
}).pipe(Effect.scoped, Effect.runPromise));
|
|
46
|
-
});
|
|
47
|
-
});
|
package/src/Subject.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Subject/index.js";
|