@fncts/io 0.0.48 → 0.0.49
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/Cached/api.d.ts +1 -1
- package/Channel/api.d.ts +80 -80
- package/Channel/core-api.d.ts +26 -26
- package/Console/definition.d.ts +1 -0
- package/CountdownLatch.d.ts +1 -0
- package/Fiber/FiberMessage.d.ts +6 -28
- package/Fiber/FiberRuntime.d.ts +108 -77
- package/Fiber/api/interruptAs.d.ts +2 -2
- package/Fiber/definition.d.ts +2 -0
- package/FiberScope/definition.d.ts +3 -0
- package/FiberSet.d.ts +2 -1
- package/Future/State.d.ts +59 -0
- package/Future/api.d.ts +8 -3
- package/Future/constructors.d.ts +1 -1
- package/Future/definition.d.ts +1 -17
- package/Future.d.ts +1 -0
- package/Hub/api.d.ts +15 -15
- package/IO/api/array.d.ts +22 -0
- package/IO/api/awaitAllChildren.d.ts +6 -0
- package/IO/api/cachedInvalidate.d.ts +15 -0
- package/IO/api/forkDaemon.d.ts +1 -1
- package/IO/api/onTermination.d.ts +1 -2
- package/IO/api/transplant.d.ts +11 -1
- package/IO/api.d.ts +247 -225
- package/IO/definition.d.ts +12 -25
- package/IO.d.ts +3 -1
- package/Random/definition.d.ts +1 -0
- package/Ref/Synchronized/api.d.ts +1 -1
- package/Semaphore/Reservation.d.ts +15 -0
- package/Semaphore/constructors.d.ts +13 -0
- package/Semaphore/definition.d.ts +29 -0
- package/Semaphore.d.ts +3 -40
- package/Stream/api.d.ts +164 -164
- package/_cjs/Cached/api.cjs +1 -2
- package/_cjs/Cached/api.cjs.map +1 -1
- package/_cjs/Cached/internal.cjs +1 -2
- package/_cjs/Cached/internal.cjs.map +1 -1
- package/_cjs/Channel/api/interruptWhen.cjs +1 -2
- package/_cjs/Channel/api/interruptWhen.cjs.map +1 -1
- package/_cjs/Channel/api/mapOutConcurrentIO.cjs +2 -3
- package/_cjs/Channel/api/mapOutConcurrentIO.cjs.map +1 -1
- package/_cjs/Channel/api/mergeAll.cjs +1 -2
- package/_cjs/Channel/api/mergeAll.cjs.map +1 -1
- package/_cjs/Channel/api/mergeAllUnboundedWith.cjs +1 -2
- package/_cjs/Channel/api/mergeAllUnboundedWith.cjs.map +1 -1
- package/_cjs/Channel/api/mergeAllWith.cjs +2 -3
- package/_cjs/Channel/api/mergeAllWith.cjs.map +1 -1
- package/_cjs/Channel/api/mergeMap.cjs +1 -2
- package/_cjs/Channel/api/mergeMap.cjs.map +1 -1
- package/_cjs/Channel/api/mergeWith.cjs +1 -2
- package/_cjs/Channel/api/mergeWith.cjs.map +1 -1
- package/_cjs/Channel/api/run.cjs +1 -2
- package/_cjs/Channel/api/run.cjs.map +1 -1
- package/_cjs/Channel/api/runCollect.cjs +1 -2
- package/_cjs/Channel/api/runCollect.cjs.map +1 -1
- package/_cjs/Channel/api/runDrain.cjs +1 -2
- package/_cjs/Channel/api/runDrain.cjs.map +1 -1
- package/_cjs/Channel/api/runScoped.cjs +3 -4
- package/_cjs/Channel/api/runScoped.cjs.map +1 -1
- package/_cjs/Channel/api/toPull.cjs +2 -3
- package/_cjs/Channel/api/toPull.cjs.map +1 -1
- package/_cjs/Channel/api/zipConcurrent.cjs +1 -2
- package/_cjs/Channel/api/zipConcurrent.cjs.map +1 -1
- package/_cjs/Channel/api.cjs +206 -207
- package/_cjs/Channel/api.cjs.map +1 -1
- package/_cjs/Channel/core-api.cjs +43 -42
- package/_cjs/Channel/core-api.cjs.map +1 -1
- package/_cjs/Channel/internal/ChannelExecutor.cjs +4 -5
- package/_cjs/Channel/internal/ChannelExecutor.cjs.map +1 -1
- package/_cjs/Channel/internal/ChannelState.cjs +1 -2
- package/_cjs/Channel/internal/ChannelState.cjs.map +1 -1
- package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs +1 -2
- package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs.map +1 -1
- package/_cjs/Clock/api.cjs +1 -2
- package/_cjs/Clock/api.cjs.map +1 -1
- package/_cjs/Clock/definition.cjs +1 -2
- package/_cjs/Clock/definition.cjs.map +1 -1
- package/_cjs/Clock/live.cjs +1 -2
- package/_cjs/Clock/live.cjs.map +1 -1
- package/_cjs/Console/api.cjs +1 -2
- package/_cjs/Console/api.cjs.map +1 -1
- package/_cjs/Console/definition.cjs +2 -2
- package/_cjs/Console/definition.cjs.map +1 -1
- package/_cjs/Console/live.cjs +1 -2
- package/_cjs/Console/live.cjs.map +1 -1
- package/_cjs/CountdownLatch.cjs +3 -3
- package/_cjs/CountdownLatch.cjs.map +1 -1
- package/_cjs/Differ/api.cjs +1 -2
- package/_cjs/Differ/api.cjs.map +1 -1
- package/_cjs/Fiber/FiberMessage.cjs +3 -24
- package/_cjs/Fiber/FiberMessage.cjs.map +1 -1
- package/_cjs/Fiber/FiberRuntime.cjs +879 -636
- package/_cjs/Fiber/FiberRuntime.cjs.map +1 -1
- package/_cjs/Fiber/api/awaitAll.cjs +1 -2
- package/_cjs/Fiber/api/awaitAll.cjs.map +1 -1
- package/_cjs/Fiber/api/collectAll.cjs +2 -3
- package/_cjs/Fiber/api/collectAll.cjs.map +1 -1
- package/_cjs/Fiber/api/fromIO.cjs +1 -2
- package/_cjs/Fiber/api/fromIO.cjs.map +1 -1
- package/_cjs/Fiber/api/interrupt.cjs +2 -3
- package/_cjs/Fiber/api/interrupt.cjs.map +1 -1
- package/_cjs/Fiber/api/interruptAll.cjs +2 -3
- package/_cjs/Fiber/api/interruptAll.cjs.map +1 -1
- package/_cjs/Fiber/api/interruptAs.cjs +5 -10
- package/_cjs/Fiber/api/interruptAs.cjs.map +1 -1
- package/_cjs/Fiber/api/interruptFork.cjs +2 -3
- package/_cjs/Fiber/api/interruptFork.cjs.map +1 -1
- package/_cjs/Fiber/api/join.cjs +1 -2
- package/_cjs/Fiber/api/join.cjs.map +1 -1
- package/_cjs/Fiber/api/joinAll.cjs +1 -2
- package/_cjs/Fiber/api/joinAll.cjs.map +1 -1
- package/_cjs/Fiber/api/mapFiber.cjs +1 -2
- package/_cjs/Fiber/api/mapFiber.cjs.map +1 -1
- package/_cjs/Fiber/api/mapIO.cjs +2 -3
- package/_cjs/Fiber/api/mapIO.cjs.map +1 -1
- package/_cjs/Fiber/api/zipWith.cjs +2 -3
- package/_cjs/Fiber/api/zipWith.cjs.map +1 -1
- package/_cjs/Fiber/constructors.cjs +2 -3
- package/_cjs/Fiber/constructors.cjs.map +1 -1
- package/_cjs/Fiber/definition.cjs +6 -4
- package/_cjs/Fiber/definition.cjs.map +1 -1
- package/_cjs/FiberRef/api/locallyScoped.cjs +1 -2
- package/_cjs/FiberRef/api/locallyScoped.cjs.map +1 -1
- package/_cjs/FiberRef/api/locallyScopedWith.cjs +1 -2
- package/_cjs/FiberRef/api/locallyScopedWith.cjs.map +1 -1
- package/_cjs/FiberRef/constructors.cjs +1 -2
- package/_cjs/FiberRef/constructors.cjs.map +1 -1
- package/_cjs/FiberRef/definition.cjs +1 -2
- package/_cjs/FiberRef/definition.cjs.map +1 -1
- package/_cjs/FiberRef/operations.cjs +1 -2
- package/_cjs/FiberRef/operations.cjs.map +1 -1
- package/_cjs/FiberRef/unsafe.cjs +1 -2
- package/_cjs/FiberRef/unsafe.cjs.map +1 -1
- package/_cjs/FiberRefs/Patch.cjs +1 -2
- package/_cjs/FiberRefs/Patch.cjs.map +1 -1
- package/_cjs/FiberRefs/api.cjs +1 -2
- package/_cjs/FiberRefs/api.cjs.map +1 -1
- package/_cjs/FiberRefs/definition.cjs +1 -2
- package/_cjs/FiberRefs/definition.cjs.map +1 -1
- package/_cjs/FiberScope/definition.cjs +29 -6
- package/_cjs/FiberScope/definition.cjs.map +1 -1
- package/_cjs/FiberSet.cjs +16 -15
- package/_cjs/FiberSet.cjs.map +1 -1
- package/_cjs/FiberStatus/definition.cjs +1 -2
- package/_cjs/FiberStatus/definition.cjs.map +1 -1
- package/_cjs/Future/State.cjs +108 -0
- package/_cjs/Future/State.cjs.map +1 -0
- package/_cjs/Future/api.cjs +71 -64
- package/_cjs/Future/api.cjs.map +1 -1
- package/_cjs/Future/constructors.cjs +3 -4
- package/_cjs/Future/constructors.cjs.map +1 -1
- package/_cjs/Future/definition.cjs +1 -15
- package/_cjs/Future/definition.cjs.map +1 -1
- package/_cjs/Future.cjs +11 -0
- package/_cjs/Future.cjs.map +1 -1
- package/_cjs/Hub/api.cjs +56 -57
- package/_cjs/Hub/api.cjs.map +1 -1
- package/_cjs/Hub/internal.cjs +1 -2
- package/_cjs/Hub/internal.cjs.map +1 -1
- package/_cjs/IO/api/acquireRelease.cjs +1 -2
- package/_cjs/IO/api/acquireRelease.cjs.map +1 -1
- package/_cjs/IO/api/acquireReleaseExit.cjs +1 -2
- package/_cjs/IO/api/acquireReleaseExit.cjs.map +1 -1
- package/_cjs/IO/api/acquireReleaseInterruptible.cjs +1 -2
- package/_cjs/IO/api/acquireReleaseInterruptible.cjs.map +1 -1
- package/_cjs/IO/api/acquireReleaseInterruptibleExit.cjs +1 -2
- package/_cjs/IO/api/acquireReleaseInterruptibleExit.cjs.map +1 -1
- package/_cjs/IO/api/addFinalizer.cjs +1 -2
- package/_cjs/IO/api/addFinalizer.cjs.map +1 -1
- package/_cjs/IO/api/addFinalizerExit.cjs +1 -2
- package/_cjs/IO/api/addFinalizerExit.cjs.map +1 -1
- package/_cjs/IO/api/all.cjs +1 -2
- package/_cjs/IO/api/all.cjs.map +1 -1
- package/_cjs/IO/api/array.cjs +51 -0
- package/_cjs/IO/api/array.cjs.map +1 -0
- package/_cjs/IO/api/asyncIO.cjs +1 -2
- package/_cjs/IO/api/asyncIO.cjs.map +1 -1
- package/_cjs/IO/api/asyncInterrupt.cjs +1 -2
- package/_cjs/IO/api/asyncInterrupt.cjs.map +1 -1
- package/_cjs/IO/api/awaitAllChildren.cjs +17 -0
- package/_cjs/IO/api/awaitAllChildren.cjs.map +1 -0
- package/_cjs/IO/api/blocking.cjs +1 -2
- package/_cjs/IO/api/blocking.cjs.map +1 -1
- package/_cjs/IO/api/bracket.cjs +1 -2
- package/_cjs/IO/api/bracket.cjs.map +1 -1
- package/_cjs/IO/api/bracketExit.cjs +1 -2
- package/_cjs/IO/api/bracketExit.cjs.map +1 -1
- package/_cjs/IO/api/cachedInvalidate.cjs +47 -0
- package/_cjs/IO/api/cachedInvalidate.cjs.map +1 -0
- package/_cjs/IO/api/clockWith.cjs +1 -2
- package/_cjs/IO/api/clockWith.cjs.map +1 -1
- package/_cjs/IO/api/concurrency.cjs +1 -2
- package/_cjs/IO/api/concurrency.cjs.map +1 -1
- package/_cjs/IO/api/concurrentFinalizers.cjs +1 -2
- package/_cjs/IO/api/concurrentFinalizers.cjs.map +1 -1
- package/_cjs/IO/api/consoleWith.cjs +1 -2
- package/_cjs/IO/api/consoleWith.cjs.map +1 -1
- package/_cjs/IO/api/daemonChildren.cjs +1 -2
- package/_cjs/IO/api/daemonChildren.cjs.map +1 -1
- package/_cjs/IO/api/delay.cjs +1 -2
- package/_cjs/IO/api/delay.cjs.map +1 -1
- package/_cjs/IO/api/descriptor.cjs +1 -2
- package/_cjs/IO/api/descriptor.cjs.map +1 -1
- package/_cjs/IO/api/diffFiberRefs.cjs +1 -2
- package/_cjs/IO/api/diffFiberRefs.cjs.map +1 -1
- package/_cjs/IO/api/disconnect.cjs +2 -3
- package/_cjs/IO/api/disconnect.cjs.map +1 -1
- package/_cjs/IO/api/ensuringChildren.cjs +1 -2
- package/_cjs/IO/api/ensuringChildren.cjs.map +1 -1
- package/_cjs/IO/api/environment.cjs +1 -2
- package/_cjs/IO/api/environment.cjs.map +1 -1
- package/_cjs/IO/api/foreachConcurrent.cjs +36 -30
- package/_cjs/IO/api/foreachConcurrent.cjs.map +1 -1
- package/_cjs/IO/api/foreachExec.cjs +1 -2
- package/_cjs/IO/api/foreachExec.cjs.map +1 -1
- package/_cjs/IO/api/fork.cjs +2 -3
- package/_cjs/IO/api/fork.cjs.map +1 -1
- package/_cjs/IO/api/forkAll.cjs +1 -2
- package/_cjs/IO/api/forkAll.cjs.map +1 -1
- package/_cjs/IO/api/forkDaemon.cjs +5 -6
- package/_cjs/IO/api/forkDaemon.cjs.map +1 -1
- package/_cjs/IO/api/forkIn.cjs +1 -2
- package/_cjs/IO/api/forkIn.cjs.map +1 -1
- package/_cjs/IO/api/forkScoped.cjs +1 -2
- package/_cjs/IO/api/forkScoped.cjs.map +1 -1
- package/_cjs/IO/api/fulfill.cjs +1 -2
- package/_cjs/IO/api/fulfill.cjs.map +1 -1
- package/_cjs/IO/api/interrupt.cjs +4 -5
- package/_cjs/IO/api/interrupt.cjs.map +1 -1
- package/_cjs/IO/api/memoize.cjs +1 -2
- package/_cjs/IO/api/memoize.cjs.map +1 -1
- package/_cjs/IO/api/onTermination.cjs +2 -3
- package/_cjs/IO/api/onTermination.cjs.map +1 -1
- package/_cjs/IO/api/once.cjs +1 -2
- package/_cjs/IO/api/once.cjs.map +1 -1
- package/_cjs/IO/api/patchFiberRefs.cjs +1 -2
- package/_cjs/IO/api/patchFiberRefs.cjs.map +1 -1
- package/_cjs/IO/api/provideLayer.cjs +1 -2
- package/_cjs/IO/api/provideLayer.cjs.map +1 -1
- package/_cjs/IO/api/provideScope.cjs +1 -2
- package/_cjs/IO/api/provideScope.cjs.map +1 -1
- package/_cjs/IO/api/provideSomeLayer.cjs +1 -2
- package/_cjs/IO/api/provideSomeLayer.cjs.map +1 -1
- package/_cjs/IO/api/provideSomeRuntime.cjs +1 -2
- package/_cjs/IO/api/provideSomeRuntime.cjs.map +1 -1
- package/_cjs/IO/api/race.cjs +2 -3
- package/_cjs/IO/api/race.cjs.map +1 -1
- package/_cjs/IO/api/raceFirst.cjs +1 -2
- package/_cjs/IO/api/raceFirst.cjs.map +1 -1
- package/_cjs/IO/api/raceWith.cjs +1 -2
- package/_cjs/IO/api/raceWith.cjs.map +1 -1
- package/_cjs/IO/api/randomWith.cjs +1 -2
- package/_cjs/IO/api/randomWith.cjs.map +1 -1
- package/_cjs/IO/api/repeat.cjs +1 -2
- package/_cjs/IO/api/repeat.cjs.map +1 -1
- package/_cjs/IO/api/retry.cjs +1 -2
- package/_cjs/IO/api/retry.cjs.map +1 -1
- package/_cjs/IO/api/schedule.cjs +1 -2
- package/_cjs/IO/api/schedule.cjs.map +1 -1
- package/_cjs/IO/api/scope.cjs +1 -2
- package/_cjs/IO/api/scope.cjs.map +1 -1
- package/_cjs/IO/api/scopeWith.cjs +1 -2
- package/_cjs/IO/api/scopeWith.cjs.map +1 -1
- package/_cjs/IO/api/scoped.cjs +1 -2
- package/_cjs/IO/api/scoped.cjs.map +1 -1
- package/_cjs/IO/api/sleep.cjs +1 -2
- package/_cjs/IO/api/sleep.cjs.map +1 -1
- package/_cjs/IO/api/stateful.cjs +1 -2
- package/_cjs/IO/api/stateful.cjs.map +1 -1
- package/_cjs/IO/api/supervised.cjs +1 -2
- package/_cjs/IO/api/supervised.cjs.map +1 -1
- package/_cjs/IO/api/timeout.cjs +9 -11
- package/_cjs/IO/api/timeout.cjs.map +1 -1
- package/_cjs/IO/api/transplant.cjs +22 -7
- package/_cjs/IO/api/transplant.cjs.map +1 -1
- package/_cjs/IO/api/whenFiberRef.cjs +1 -2
- package/_cjs/IO/api/whenFiberRef.cjs.map +1 -1
- package/_cjs/IO/api/whenRef.cjs +1 -2
- package/_cjs/IO/api/whenRef.cjs.map +1 -1
- package/_cjs/IO/api/withChildren.cjs +1 -2
- package/_cjs/IO/api/withChildren.cjs.map +1 -1
- package/_cjs/IO/api/withEarlyRelease.cjs +1 -2
- package/_cjs/IO/api/withEarlyRelease.cjs.map +1 -1
- package/_cjs/IO/api/withFinalizer.cjs +1 -2
- package/_cjs/IO/api/withFinalizer.cjs.map +1 -1
- package/_cjs/IO/api/withFinalizerExit.cjs +1 -2
- package/_cjs/IO/api/withFinalizerExit.cjs.map +1 -1
- package/_cjs/IO/api/zipConcurrent.cjs +5 -6
- package/_cjs/IO/api/zipConcurrent.cjs.map +1 -1
- package/_cjs/IO/api.cjs +522 -473
- package/_cjs/IO/api.cjs.map +1 -1
- package/_cjs/IO/definition.cjs +2 -3
- package/_cjs/IO/definition.cjs.map +1 -1
- package/_cjs/IO/runtime.cjs +9 -10
- package/_cjs/IO/runtime.cjs.map +1 -1
- package/_cjs/IO.cjs +33 -11
- package/_cjs/IO.cjs.map +1 -1
- package/_cjs/IOEnv/definition.cjs +1 -2
- package/_cjs/IOEnv/definition.cjs.map +1 -1
- package/_cjs/IOEnv/live.cjs +1 -2
- package/_cjs/IOEnv/live.cjs.map +1 -1
- package/_cjs/IOEnv/services.cjs +1 -2
- package/_cjs/IOEnv/services.cjs.map +1 -1
- package/_cjs/Layer/MemoMap.cjs +1 -2
- package/_cjs/Layer/MemoMap.cjs.map +1 -1
- package/_cjs/Layer/api.cjs +1 -2
- package/_cjs/Layer/api.cjs.map +1 -1
- package/_cjs/Logger/api.cjs +1 -2
- package/_cjs/Logger/api.cjs.map +1 -1
- package/_cjs/Logger/constructors.cjs +1 -2
- package/_cjs/Logger/constructors.cjs.map +1 -1
- package/_cjs/MVar/api.cjs +1 -2
- package/_cjs/MVar/api.cjs.map +1 -1
- package/_cjs/Push/api.cjs +2 -3
- package/_cjs/Push/api.cjs.map +1 -1
- package/_cjs/Push/internal.cjs +1 -2
- package/_cjs/Push/internal.cjs.map +1 -1
- package/_cjs/Queue/api/dimapIO.cjs +1 -2
- package/_cjs/Queue/api/dimapIO.cjs.map +1 -1
- package/_cjs/Queue/api/filterInputIO.cjs +1 -2
- package/_cjs/Queue/api/filterInputIO.cjs.map +1 -1
- package/_cjs/Queue/api/filterOutputIO.cjs +1 -2
- package/_cjs/Queue/api/filterOutputIO.cjs.map +1 -1
- package/_cjs/Queue/api/poll.cjs +1 -2
- package/_cjs/Queue/api/poll.cjs.map +1 -1
- package/_cjs/Queue/api/takeBetween.cjs +1 -2
- package/_cjs/Queue/api/takeBetween.cjs.map +1 -1
- package/_cjs/Queue/api/takeN.cjs +1 -2
- package/_cjs/Queue/api/takeN.cjs.map +1 -1
- package/_cjs/Queue/api/zipWithIO.cjs +1 -2
- package/_cjs/Queue/api/zipWithIO.cjs.map +1 -1
- package/_cjs/Queue/constructors.cjs +1 -2
- package/_cjs/Queue/constructors.cjs.map +1 -1
- package/_cjs/Queue/internal.cjs +1 -2
- package/_cjs/Queue/internal.cjs.map +1 -1
- package/_cjs/Queue/strategy.cjs +1 -2
- package/_cjs/Queue/strategy.cjs.map +1 -1
- package/_cjs/Random/api.cjs +1 -2
- package/_cjs/Random/api.cjs.map +1 -1
- package/_cjs/Random/definition.cjs +2 -2
- package/_cjs/Random/definition.cjs.map +1 -1
- package/_cjs/Random/live.cjs +1 -2
- package/_cjs/Random/live.cjs.map +1 -1
- package/_cjs/Ref/Atomic.cjs +1 -2
- package/_cjs/Ref/Atomic.cjs.map +1 -1
- package/_cjs/Ref/Derived.cjs +1 -2
- package/_cjs/Ref/Derived.cjs.map +1 -1
- package/_cjs/Ref/DerivedAll.cjs +1 -2
- package/_cjs/Ref/DerivedAll.cjs.map +1 -1
- package/_cjs/Ref/Synchronized/api.cjs +2 -3
- package/_cjs/Ref/Synchronized/api.cjs.map +1 -1
- package/_cjs/Ref/Synchronized/constructors.cjs +2 -3
- package/_cjs/Ref/Synchronized/constructors.cjs.map +1 -1
- package/_cjs/Ref/Synchronized/definition.cjs +2 -3
- package/_cjs/Ref/Synchronized/definition.cjs.map +1 -1
- package/_cjs/Ref/api/collect.cjs +1 -2
- package/_cjs/Ref/api/collect.cjs.map +1 -1
- package/_cjs/Ref/api/dimap.cjs +1 -2
- package/_cjs/Ref/api/dimap.cjs.map +1 -1
- package/_cjs/Ref/api/filter.cjs +1 -2
- package/_cjs/Ref/api/filter.cjs.map +1 -1
- package/_cjs/Ref/api/modify.cjs +1 -2
- package/_cjs/Ref/api/modify.cjs.map +1 -1
- package/_cjs/Ref/api.cjs +1 -2
- package/_cjs/Ref/api.cjs.map +1 -1
- package/_cjs/Ref/constructors.cjs +1 -2
- package/_cjs/Ref/constructors.cjs.map +1 -1
- package/_cjs/RefSubject/Atomic.cjs +1 -2
- package/_cjs/RefSubject/Atomic.cjs.map +1 -1
- package/_cjs/RefSubject/Synchronized/api.cjs +1 -2
- package/_cjs/RefSubject/Synchronized/api.cjs.map +1 -1
- package/_cjs/RefSubject/Synchronized/definition.cjs +1 -2
- package/_cjs/RefSubject/Synchronized/definition.cjs.map +1 -1
- package/_cjs/RefSubject/api.cjs +1 -2
- package/_cjs/RefSubject/api.cjs.map +1 -1
- package/_cjs/Reloadable/api.cjs +1 -2
- package/_cjs/Reloadable/api.cjs.map +1 -1
- package/_cjs/Reloadable/constructors.cjs +1 -2
- package/_cjs/Reloadable/constructors.cjs.map +1 -1
- package/_cjs/Reloadable/definition.cjs +1 -2
- package/_cjs/Reloadable/definition.cjs.map +1 -1
- package/_cjs/RuntimeFlags/Patch.cjs +1 -2
- package/_cjs/RuntimeFlags/Patch.cjs.map +1 -1
- package/_cjs/RuntimeFlags/RuntimeFlags.cjs +1 -2
- package/_cjs/RuntimeFlags/RuntimeFlags.cjs.map +1 -1
- package/_cjs/STM/api/atomically.cjs +1 -2
- package/_cjs/STM/api/atomically.cjs.map +1 -1
- package/_cjs/STM/api/core-api.cjs +1 -2
- package/_cjs/STM/api/core-api.cjs.map +1 -1
- package/_cjs/STM/api.cjs +1 -2
- package/_cjs/STM/api.cjs.map +1 -1
- package/_cjs/STM/definition.cjs +2 -3
- package/_cjs/STM/definition.cjs.map +1 -1
- package/_cjs/STM/driver.cjs +1 -2
- package/_cjs/STM/driver.cjs.map +1 -1
- package/_cjs/STM/internal/CommitState.cjs +1 -2
- package/_cjs/STM/internal/CommitState.cjs.map +1 -1
- package/_cjs/STM/internal/Journal.cjs +1 -2
- package/_cjs/STM/internal/Journal.cjs.map +1 -1
- package/_cjs/Schedule/Decision.cjs +1 -2
- package/_cjs/Schedule/Decision.cjs.map +1 -1
- package/_cjs/Schedule/api/driver.cjs +1 -2
- package/_cjs/Schedule/api/driver.cjs.map +1 -1
- package/_cjs/Schedule/api.cjs +1 -2
- package/_cjs/Schedule/api.cjs.map +1 -1
- package/_cjs/Scope/Finalizer/definition.cjs +1 -2
- package/_cjs/Scope/Finalizer/definition.cjs.map +1 -1
- package/_cjs/Scope/ReleaseMap/api/releaseAll.cjs +1 -2
- package/_cjs/Scope/ReleaseMap/api/releaseAll.cjs.map +1 -1
- package/_cjs/Scope/ReleaseMap/api.cjs +1 -2
- package/_cjs/Scope/ReleaseMap/api.cjs.map +1 -1
- package/_cjs/Scope/ReleaseMap/constructors.cjs +1 -2
- package/_cjs/Scope/ReleaseMap/constructors.cjs.map +1 -1
- package/_cjs/Scope/ReleaseMap/definition.cjs +1 -2
- package/_cjs/Scope/ReleaseMap/definition.cjs.map +1 -1
- package/_cjs/Scope/api.cjs +1 -2
- package/_cjs/Scope/api.cjs.map +1 -1
- package/_cjs/Scope/definition.cjs +1 -2
- package/_cjs/Scope/definition.cjs.map +1 -1
- package/_cjs/ScopedRef/api.cjs +2 -3
- package/_cjs/ScopedRef/api.cjs.map +1 -1
- package/_cjs/Semaphore/Reservation.cjs +24 -0
- package/_cjs/Semaphore/Reservation.cjs.map +1 -0
- package/_cjs/Semaphore/constructors.cjs +25 -0
- package/_cjs/Semaphore/constructors.cjs.map +1 -0
- package/_cjs/Semaphore/definition.cjs +149 -0
- package/_cjs/Semaphore/definition.cjs.map +1 -0
- package/_cjs/Semaphore.cjs +31 -138
- package/_cjs/Semaphore.cjs.map +1 -1
- package/_cjs/Sink/api.cjs +1 -2
- package/_cjs/Sink/api.cjs.map +1 -1
- package/_cjs/State/api.cjs +1 -2
- package/_cjs/State/api.cjs.map +1 -1
- package/_cjs/Stream/api/zipAllWith.cjs +1 -2
- package/_cjs/Stream/api/zipAllWith.cjs.map +1 -1
- package/_cjs/Stream/api/zipWith.cjs +1 -2
- package/_cjs/Stream/api/zipWith.cjs.map +1 -1
- package/_cjs/Stream/api/zipWithChunks.cjs +1 -2
- package/_cjs/Stream/api/zipWithChunks.cjs.map +1 -1
- package/_cjs/Stream/api.cjs +702 -703
- package/_cjs/Stream/api.cjs.map +1 -1
- package/_cjs/Stream/internal/Handoff.cjs +1 -2
- package/_cjs/Stream/internal/Handoff.cjs.map +1 -1
- package/_cjs/Stream/internal/Pull.cjs +1 -2
- package/_cjs/Stream/internal/Pull.cjs.map +1 -1
- package/_cjs/Stream/internal/Take.cjs +1 -2
- package/_cjs/Stream/internal/Take.cjs.map +1 -1
- package/_cjs/Stream/internal/util.cjs +1 -2
- package/_cjs/Stream/internal/util.cjs.map +1 -1
- package/_cjs/Subject/Atomic.cjs +1 -2
- package/_cjs/Subject/Atomic.cjs.map +1 -1
- package/_cjs/Subject/api.cjs +1 -2
- package/_cjs/Subject/api.cjs.map +1 -1
- package/_cjs/SubscriptionRef.cjs +2 -3
- package/_cjs/SubscriptionRef.cjs.map +1 -1
- package/_cjs/Supervisor/api.cjs +1 -2
- package/_cjs/Supervisor/api.cjs.map +1 -1
- package/_cjs/Supervisor/constructors.cjs +1 -2
- package/_cjs/Supervisor/constructors.cjs.map +1 -1
- package/_cjs/Supervisor/definition.cjs +1 -2
- package/_cjs/Supervisor/definition.cjs.map +1 -1
- package/_cjs/SupervisorPatch.cjs +1 -2
- package/_cjs/SupervisorPatch.cjs.map +1 -1
- package/_cjs/TExit/definition.cjs +1 -2
- package/_cjs/TExit/definition.cjs.map +1 -1
- package/_cjs/TFuture/api.cjs +1 -2
- package/_cjs/TFuture/api.cjs.map +1 -1
- package/_cjs/TFuture/constructors.cjs +1 -2
- package/_cjs/TFuture/constructors.cjs.map +1 -1
- package/_cjs/TFuture/definition.cjs +1 -2
- package/_cjs/TFuture/definition.cjs.map +1 -1
- package/_cjs/TReentrantLock/api.cjs +1 -2
- package/_cjs/TReentrantLock/api.cjs.map +1 -1
- package/_cjs/TReentrantLock/definition.cjs +1 -2
- package/_cjs/TReentrantLock/definition.cjs.map +1 -1
- package/_cjs/TRef/api.cjs +1 -2
- package/_cjs/TRef/api.cjs.map +1 -1
- package/_cjs/TRef/constructors.cjs +1 -2
- package/_cjs/TRef/constructors.cjs.map +1 -1
- package/_cjs/TRef/definition.cjs +1 -2
- package/_cjs/TRef/definition.cjs.map +1 -1
- package/_cjs/TSemaphore/api.cjs +1 -2
- package/_cjs/TSemaphore/api.cjs.map +1 -1
- package/_cjs/TSemaphore/constructors.cjs +1 -2
- package/_cjs/TSemaphore/constructors.cjs.map +1 -1
- package/_cjs/TSemaphore/definition.cjs +1 -2
- package/_cjs/TSemaphore/definition.cjs.map +1 -1
- package/_cjs/collection/immutable/Conc/dropUntilIO.cjs +1 -2
- package/_cjs/collection/immutable/Conc/dropUntilIO.cjs.map +1 -1
- package/_cjs/collection/immutable/Conc/dropWhileIO.cjs +1 -2
- package/_cjs/collection/immutable/Conc/dropWhileIO.cjs.map +1 -1
- package/_cjs/collection/immutable/Conc/filterIO.cjs +1 -2
- package/_cjs/collection/immutable/Conc/filterIO.cjs.map +1 -1
- package/_cjs/collection/immutable/Conc/findIO.cjs +1 -2
- package/_cjs/collection/immutable/Conc/findIO.cjs.map +1 -1
- package/_cjs/collection/immutable/Conc/mapIO.cjs +1 -2
- package/_cjs/collection/immutable/Conc/mapIO.cjs.map +1 -1
- package/_cjs/collection/immutable/Conc/takeWhileIO.cjs +1 -2
- package/_cjs/collection/immutable/Conc/takeWhileIO.cjs.map +1 -1
- package/_cjs/data/Exit/foreachIO.cjs +1 -2
- package/_cjs/data/Exit/foreachIO.cjs.map +1 -1
- package/_cjs/internal/HashedPair.cjs +1 -2
- package/_cjs/internal/HashedPair.cjs.map +1 -1
- package/_cjs/internal/Hub.cjs +1 -2
- package/_cjs/internal/Hub.cjs.map +1 -1
- package/_cjs/internal/MutableQueue.cjs +1 -2
- package/_cjs/internal/MutableQueue.cjs.map +1 -1
- package/_cjs/internal/Scheduler.cjs +1 -2
- package/_cjs/internal/Scheduler.cjs.map +1 -1
- package/_cjs/internal/StackTraceBuilder.cjs +1 -2
- package/_cjs/internal/StackTraceBuilder.cjs.map +1 -1
- package/_mjs/Cached/api.mjs.map +1 -1
- package/_mjs/Channel/api/mapOutConcurrentIO.mjs +1 -1
- package/_mjs/Channel/api/mergeAllWith.mjs +1 -1
- package/_mjs/Channel/api/runScoped.mjs +2 -2
- package/_mjs/Channel/api/runScoped.mjs.map +1 -1
- package/_mjs/Channel/api/toPull.mjs +1 -1
- package/_mjs/Channel/api/toPull.mjs.map +1 -1
- package/_mjs/Channel/api.mjs +205 -205
- package/_mjs/Channel/api.mjs.map +1 -1
- package/_mjs/Channel/core-api.mjs +43 -42
- package/_mjs/Channel/core-api.mjs.map +1 -1
- package/_mjs/Channel/internal/ChannelExecutor.mjs +3 -3
- package/_mjs/Channel/internal/ChannelExecutor.mjs.map +1 -1
- package/_mjs/Console/definition.mjs +1 -0
- package/_mjs/Console/definition.mjs.map +1 -1
- package/_mjs/CountdownLatch.mjs +2 -1
- package/_mjs/CountdownLatch.mjs.map +1 -1
- package/_mjs/Fiber/FiberMessage.mjs +2 -20
- package/_mjs/Fiber/FiberMessage.mjs.map +1 -1
- package/_mjs/Fiber/FiberRuntime.mjs +877 -633
- package/_mjs/Fiber/FiberRuntime.mjs.map +1 -1
- package/_mjs/Fiber/api/collectAll.mjs +1 -1
- package/_mjs/Fiber/api/collectAll.mjs.map +1 -1
- package/_mjs/Fiber/api/interrupt.mjs +1 -1
- package/_mjs/Fiber/api/interrupt.mjs.map +1 -1
- package/_mjs/Fiber/api/interruptAll.mjs +1 -1
- package/_mjs/Fiber/api/interruptAll.mjs.map +1 -1
- package/_mjs/Fiber/api/interruptAs.mjs +4 -7
- package/_mjs/Fiber/api/interruptAs.mjs.map +1 -1
- package/_mjs/Fiber/api/interruptFork.mjs +1 -1
- package/_mjs/Fiber/api/interruptFork.mjs.map +1 -1
- package/_mjs/Fiber/api/mapIO.mjs +1 -1
- package/_mjs/Fiber/api/mapIO.mjs.map +1 -1
- package/_mjs/Fiber/api/zipWith.mjs +1 -1
- package/_mjs/Fiber/api/zipWith.mjs.map +1 -1
- package/_mjs/Fiber/constructors.mjs +1 -1
- package/_mjs/Fiber/constructors.mjs.map +1 -1
- package/_mjs/Fiber/definition.mjs +5 -2
- package/_mjs/Fiber/definition.mjs.map +1 -1
- package/_mjs/FiberScope/definition.mjs +28 -4
- package/_mjs/FiberScope/definition.mjs.map +1 -1
- package/_mjs/FiberSet.mjs +14 -12
- package/_mjs/FiberSet.mjs.map +1 -1
- package/_mjs/Future/State.mjs +96 -0
- package/_mjs/Future/State.mjs.map +1 -0
- package/_mjs/Future/api.mjs +67 -61
- package/_mjs/Future/api.mjs.map +1 -1
- package/_mjs/Future/constructors.mjs +3 -3
- package/_mjs/Future/constructors.mjs.map +1 -1
- package/_mjs/Future/definition.mjs +0 -12
- package/_mjs/Future/definition.mjs.map +1 -1
- package/_mjs/Future.mjs +1 -0
- package/_mjs/Future.mjs.map +1 -1
- package/_mjs/Hub/api.mjs +55 -55
- package/_mjs/Hub/api.mjs.map +1 -1
- package/_mjs/IO/api/array.mjs +42 -0
- package/_mjs/IO/api/array.mjs.map +1 -0
- package/_mjs/IO/api/asyncInterrupt.mjs.map +1 -1
- package/_mjs/IO/api/awaitAllChildren.mjs +10 -0
- package/_mjs/IO/api/awaitAllChildren.mjs.map +1 -0
- package/_mjs/IO/api/cachedInvalidate.mjs +39 -0
- package/_mjs/IO/api/cachedInvalidate.mjs.map +1 -0
- package/_mjs/IO/api/disconnect.mjs +1 -1
- package/_mjs/IO/api/disconnect.mjs.map +1 -1
- package/_mjs/IO/api/foreachConcurrent.mjs +35 -28
- package/_mjs/IO/api/foreachConcurrent.mjs.map +1 -1
- package/_mjs/IO/api/fork.mjs +1 -1
- package/_mjs/IO/api/fork.mjs.map +1 -1
- package/_mjs/IO/api/forkDaemon.mjs +4 -4
- package/_mjs/IO/api/forkDaemon.mjs.map +1 -1
- package/_mjs/IO/api/interrupt.mjs +3 -3
- package/_mjs/IO/api/onTermination.mjs +1 -1
- package/_mjs/IO/api/onTermination.mjs.map +1 -1
- package/_mjs/IO/api/race.mjs +1 -1
- package/_mjs/IO/api/race.mjs.map +1 -1
- package/_mjs/IO/api/timeout.mjs +8 -9
- package/_mjs/IO/api/timeout.mjs.map +1 -1
- package/_mjs/IO/api/transplant.mjs +19 -5
- package/_mjs/IO/api/transplant.mjs.map +1 -1
- package/_mjs/IO/api/zipConcurrent.mjs +4 -4
- package/_mjs/IO/api/zipConcurrent.mjs.map +1 -1
- package/_mjs/IO/api.mjs +515 -468
- package/_mjs/IO/api.mjs.map +1 -1
- package/_mjs/IO/definition.mjs +1 -1
- package/_mjs/IO/definition.mjs.map +1 -1
- package/_mjs/IO/runtime.mjs +8 -8
- package/_mjs/IO/runtime.mjs.map +1 -1
- package/_mjs/IO.mjs +3 -1
- package/_mjs/IO.mjs.map +1 -1
- package/_mjs/IOEnv/definition.mjs.map +1 -1
- package/_mjs/Push/api.mjs +1 -1
- package/_mjs/Random/definition.mjs +1 -0
- package/_mjs/Random/definition.mjs.map +1 -1
- package/_mjs/Ref/Synchronized/api.mjs +1 -1
- package/_mjs/Ref/Synchronized/api.mjs.map +1 -1
- package/_mjs/Ref/Synchronized/constructors.mjs +1 -1
- package/_mjs/Ref/Synchronized/definition.mjs +1 -1
- package/_mjs/Ref/Synchronized/definition.mjs.map +1 -1
- package/_mjs/STM/definition.mjs +1 -1
- package/_mjs/ScopedRef/api.mjs +1 -1
- package/_mjs/ScopedRef/api.mjs.map +1 -1
- package/_mjs/Semaphore/Reservation.mjs +16 -0
- package/_mjs/Semaphore/Reservation.mjs.map +1 -0
- package/_mjs/Semaphore/constructors.mjs +17 -0
- package/_mjs/Semaphore/constructors.mjs.map +1 -0
- package/_mjs/Semaphore/definition.mjs +141 -0
- package/_mjs/Semaphore/definition.mjs.map +1 -0
- package/_mjs/Semaphore.mjs +4 -133
- package/_mjs/Semaphore.mjs.map +1 -1
- package/_mjs/Stream/api.mjs +701 -701
- package/_mjs/Stream/api.mjs.map +1 -1
- package/_mjs/SubscriptionRef.mjs +1 -1
- package/_src/Cached/api.ts +3 -3
- package/_src/Channel/api/toPull.ts +1 -1
- package/_src/Channel/api.ts +273 -272
- package/_src/Channel/core-api.ts +57 -55
- package/_src/Channel/internal/ChannelExecutor.ts +3 -3
- package/_src/Console/definition.ts +1 -0
- package/_src/CountdownLatch.ts +2 -0
- package/_src/Fiber/FiberMessage.ts +3 -28
- package/_src/Fiber/FiberRuntime.ts +988 -616
- package/_src/Fiber/api/interruptAs.ts +4 -3
- package/_src/Fiber/constructors.ts +1 -1
- package/_src/Fiber/definition.ts +4 -0
- package/_src/FiberScope/definition.ts +40 -2
- package/_src/FiberSet.ts +6 -2
- package/_src/Future/State.ts +128 -0
- package/_src/Future/api.ts +62 -51
- package/_src/Future/constructors.ts +4 -2
- package/_src/Future/definition.ts +2 -17
- package/_src/Future.ts +4 -3
- package/_src/Hub/api.ts +61 -61
- package/_src/IO/api/addFinalizerExit.ts +4 -4
- package/_src/IO/api/array.ts +49 -0
- package/_src/IO/api/asyncInterrupt.ts +1 -1
- package/_src/IO/api/awaitAllChildren.ts +6 -0
- package/_src/IO/api/cachedInvalidate.ts +42 -0
- package/_src/IO/api/foreachConcurrent.ts +39 -23
- package/_src/IO/api/fork.ts +1 -1
- package/_src/IO/api/forkDaemon.ts +2 -2
- package/_src/IO/api/memoize.ts +3 -3
- package/_src/IO/api/onTermination.ts +2 -2
- package/_src/IO/api/transplant.ts +26 -3
- package/_src/IO/api/zipConcurrent.ts +2 -2
- package/_src/IO/api.ts +547 -525
- package/_src/IO/definition.ts +4 -28
- package/_src/IO/runtime.ts +0 -1
- package/_src/IO.ts +65 -63
- package/_src/IOEnv/definition.ts +1 -4
- package/_src/Random/definition.ts +1 -0
- package/_src/Ref/Synchronized/api.ts +2 -2
- package/_src/Ref/Synchronized/definition.ts +1 -1
- package/_src/Semaphore/Reservation.ts +15 -0
- package/_src/Semaphore/constructors.ts +14 -0
- package/_src/Semaphore/definition.ts +180 -0
- package/_src/Semaphore.ts +5 -159
- package/_src/Stream/api.ts +679 -679
- package/package.json +4 -4
- package/IO/api/sequenceT.d.ts +0 -26
- package/_cjs/IO/api/sequenceT.cjs +0 -18
- package/_cjs/IO/api/sequenceT.cjs.map +0 -1
- package/_mjs/IO/api/sequenceT.mjs +0 -10
- package/_mjs/IO/api/sequenceT.mjs.map +0 -1
- package/_src/IO/api/sequenceT.ts +0 -16
package/_src/Stream/api.ts
CHANGED
@@ -25,6 +25,34 @@ export function absolve<R, E, E2, A>(self: Stream<R, E, Either<E2, A>>, __tsplus
|
|
25
25
|
return self.mapIO((either) => IO.fromEither(either));
|
26
26
|
}
|
27
27
|
|
28
|
+
/**
|
29
|
+
* Creates a stream from a single value that will get cleaned up after the
|
30
|
+
* stream is consumed
|
31
|
+
*
|
32
|
+
* @tsplus static fncts.io.StreamOps acquireRelease
|
33
|
+
*/
|
34
|
+
export function acquireRelease<R, E, A, R1>(
|
35
|
+
acquire: IO<R, E, A>,
|
36
|
+
release: (a: A) => IO<R1, never, unknown>,
|
37
|
+
__tsplusTrace?: string,
|
38
|
+
): Stream<R | R1, E, A> {
|
39
|
+
return Stream.scoped(IO.acquireRelease(acquire, release));
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Creates a stream from a single value that will get cleaned up after the
|
44
|
+
* stream is consumed
|
45
|
+
*
|
46
|
+
* @tsplus static fncts.io.StreamOps acquireReleaseExit
|
47
|
+
*/
|
48
|
+
export function acquireReleaseExit<R, E, A, R1>(
|
49
|
+
acquire: IO<R, E, A>,
|
50
|
+
release: (a: A, exit: Exit<any, any>) => IO<R1, never, unknown>,
|
51
|
+
__tsplusTrace?: string,
|
52
|
+
): Stream<R | R1, E, A> {
|
53
|
+
return Stream.scoped(IO.acquireReleaseExit(acquire, release));
|
54
|
+
}
|
55
|
+
|
28
56
|
/**
|
29
57
|
* Aggregates elements of this stream using the provided sink for as long
|
30
58
|
* as the downstream operators on the stream are busy.
|
@@ -81,13 +109,13 @@ export function aggregateAsyncWithinEither<R1, E1, A1, B, R2, C>(
|
|
81
109
|
) {
|
82
110
|
return <R, E, A extends A1>(stream: Stream<R, E, A>): Stream<R | R1 | R2, E | E1, Either<C, B>> => {
|
83
111
|
type LocalHandoffSignal = HandoffSignal<E | E1, A1>;
|
84
|
-
const deps = IO.
|
112
|
+
const deps = IO.all([
|
85
113
|
Handoff<LocalHandoffSignal>(),
|
86
114
|
Ref.make<SinkEndReason>(new ScheduleEnd()),
|
87
115
|
Ref.make(Conc.empty<A1>()),
|
88
116
|
schedule.driver,
|
89
117
|
Ref.make(false),
|
90
|
-
);
|
118
|
+
]);
|
91
119
|
return Stream.fromIO(deps).flatMap(([handoff, sinkEndReason, sinkLeftovers, scheduleDriver, consumed]) => {
|
92
120
|
const handoffProducer: Channel<never, E | E1, Conc<A1>, unknown, never, never, any> = Channel.readWithCause(
|
93
121
|
(_in: Conc<A1>) => Channel.fromIO(handoff.offer(HandoffSignal.Emit(_in))).zipRight(handoffProducer),
|
@@ -192,32 +220,6 @@ export function aggregateAsyncWithinEither<R1, E1, A1, B, R2, C>(
|
|
192
220
|
};
|
193
221
|
}
|
194
222
|
|
195
|
-
/**
|
196
|
-
* Composes this stream with the specified stream to create a cartesian product of elements,
|
197
|
-
* but keeps only elements from this stream.
|
198
|
-
* The `that` stream would be run multiple times, for every element in the `this` stream.
|
199
|
-
*
|
200
|
-
* @tsplus pipeable fncts.io.Stream zipLeft
|
201
|
-
*/
|
202
|
-
export function zipLeft<R1, E1, A1>(that: Stream<R1, E1, A1>, __tsplusTrace?: string) {
|
203
|
-
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, A> => {
|
204
|
-
return stream.crossWith(that, (a, _) => a);
|
205
|
-
};
|
206
|
-
}
|
207
|
-
|
208
|
-
/**
|
209
|
-
* Composes this stream with the specified stream to create a cartesian product of elements,
|
210
|
-
* but keeps only elements from the other stream.
|
211
|
-
* The `that` stream would be run multiple times, for every element in the `this` stream.
|
212
|
-
*
|
213
|
-
* @tsplus pipeable fncts.io.Stream zipRight
|
214
|
-
*/
|
215
|
-
export function zipRight<R1, E1, A1>(that: Stream<R1, E1, A1>, __tsplusTrace?: string) {
|
216
|
-
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, A1> => {
|
217
|
-
return stream.crossWith(that, (_, b) => b);
|
218
|
-
};
|
219
|
-
}
|
220
|
-
|
221
223
|
/**
|
222
224
|
* Maps the success values of this stream to the specified constant value.
|
223
225
|
*
|
@@ -229,6 +231,20 @@ export function as<B>(b: Lazy<B>, __tsplusTrace?: string) {
|
|
229
231
|
};
|
230
232
|
}
|
231
233
|
|
234
|
+
/**
|
235
|
+
* @tsplus static fncts.io.StreamOps async
|
236
|
+
*/
|
237
|
+
export function async<R, E, A>(
|
238
|
+
register: (resolve: (next: IO<R, Maybe<E>, Conc<A>>, offerCb?: (e: Exit<never, boolean>) => void) => void) => void,
|
239
|
+
outputBuffer = 16,
|
240
|
+
__tsplusTrace?: string,
|
241
|
+
): Stream<R, E, A> {
|
242
|
+
return Stream.asyncMaybe((cb) => {
|
243
|
+
register(cb);
|
244
|
+
return Nothing();
|
245
|
+
}, outputBuffer);
|
246
|
+
}
|
247
|
+
|
232
248
|
/**
|
233
249
|
* @tsplus static fncts.io.StreamOps asyncInterrupt
|
234
250
|
*/
|
@@ -273,38 +289,6 @@ export function asyncInterrupt<R, E, A>(
|
|
273
289
|
);
|
274
290
|
}
|
275
291
|
|
276
|
-
/**
|
277
|
-
* Creates a stream from an asynchronous callback that can be called multiple times.
|
278
|
-
* The registration of the callback can possibly return the stream synchronously.
|
279
|
-
* The optionality of the error type `E` can be used to signal the end of the stream,
|
280
|
-
* by setting it to `None`.
|
281
|
-
*
|
282
|
-
* @tsplus static fncts.io.StreamOps asyncMaybe
|
283
|
-
*/
|
284
|
-
export function asyncMaybe<R, E, A>(
|
285
|
-
register: (
|
286
|
-
resolve: (next: IO<R, Maybe<E>, Conc<A>>, offerCb?: (e: Exit<never, boolean>) => void) => void,
|
287
|
-
) => Maybe<Stream<R, E, A>>,
|
288
|
-
outputBuffer = 16,
|
289
|
-
__tsplusTrace?: string,
|
290
|
-
): Stream<R, E, A> {
|
291
|
-
return Stream.asyncInterrupt((k) => register(k).match(() => Either.left(IO.unit), Either.right), outputBuffer);
|
292
|
-
}
|
293
|
-
|
294
|
-
/**
|
295
|
-
* @tsplus static fncts.io.StreamOps async
|
296
|
-
*/
|
297
|
-
export function async<R, E, A>(
|
298
|
-
register: (resolve: (next: IO<R, Maybe<E>, Conc<A>>, offerCb?: (e: Exit<never, boolean>) => void) => void) => void,
|
299
|
-
outputBuffer = 16,
|
300
|
-
__tsplusTrace?: string,
|
301
|
-
): Stream<R, E, A> {
|
302
|
-
return Stream.asyncMaybe((cb) => {
|
303
|
-
register(cb);
|
304
|
-
return Nothing();
|
305
|
-
}, outputBuffer);
|
306
|
-
}
|
307
|
-
|
308
292
|
/**
|
309
293
|
* @tsplus static fncts.io.StreamOps asyncIO
|
310
294
|
*/
|
@@ -351,41 +335,31 @@ export function asyncIO<R, E, A, R1 = R, E1 = E>(
|
|
351
335
|
}
|
352
336
|
|
353
337
|
/**
|
354
|
-
*
|
355
|
-
* the
|
356
|
-
*
|
357
|
-
*
|
358
|
-
*/
|
359
|
-
export function bimap<E, E1, A, A1>(f: (e: E) => E1, g: (a: A) => A1, __tsplusTrace?: string) {
|
360
|
-
return <R>(stream: Stream<R, E, A>): Stream<R, E1, A1> => stream.mapError(f).map(g);
|
361
|
-
}
|
362
|
-
|
363
|
-
/**
|
364
|
-
* Creates a stream from a single value that will get cleaned up after the
|
365
|
-
* stream is consumed
|
338
|
+
* Creates a stream from an asynchronous callback that can be called multiple times.
|
339
|
+
* The registration of the callback can possibly return the stream synchronously.
|
340
|
+
* The optionality of the error type `E` can be used to signal the end of the stream,
|
341
|
+
* by setting it to `None`.
|
366
342
|
*
|
367
|
-
* @tsplus static fncts.io.StreamOps
|
343
|
+
* @tsplus static fncts.io.StreamOps asyncMaybe
|
368
344
|
*/
|
369
|
-
export function
|
370
|
-
|
371
|
-
|
345
|
+
export function asyncMaybe<R, E, A>(
|
346
|
+
register: (
|
347
|
+
resolve: (next: IO<R, Maybe<E>, Conc<A>>, offerCb?: (e: Exit<never, boolean>) => void) => void,
|
348
|
+
) => Maybe<Stream<R, E, A>>,
|
349
|
+
outputBuffer = 16,
|
372
350
|
__tsplusTrace?: string,
|
373
|
-
): Stream<R
|
374
|
-
return Stream.
|
351
|
+
): Stream<R, E, A> {
|
352
|
+
return Stream.asyncInterrupt((k) => register(k).match(() => Either.left(IO.unit), Either.right), outputBuffer);
|
375
353
|
}
|
376
354
|
|
377
355
|
/**
|
378
|
-
*
|
379
|
-
*
|
356
|
+
* Returns a stream whose failure and success channels have been mapped by
|
357
|
+
* the specified pair of functions, `f` and `g`.
|
380
358
|
*
|
381
|
-
* @tsplus
|
359
|
+
* @tsplus pipeable fncts.io.Stream bimap
|
382
360
|
*/
|
383
|
-
export function
|
384
|
-
|
385
|
-
release: (a: A, exit: Exit<any, any>) => IO<R1, never, unknown>,
|
386
|
-
__tsplusTrace?: string,
|
387
|
-
): Stream<R | R1, E, A> {
|
388
|
-
return Stream.scoped(IO.acquireReleaseExit(acquire, release));
|
361
|
+
export function bimap<E, E1, A, A1>(f: (e: E) => E1, g: (a: A) => A1, __tsplusTrace?: string) {
|
362
|
+
return <R>(stream: Stream<R, E, A>): Stream<R, E1, A1> => stream.mapError(f).map(g);
|
389
363
|
}
|
390
364
|
|
391
365
|
/**
|
@@ -501,27 +475,19 @@ export function bufferChunks(capacity: number, __tsplusTrace?: string) {
|
|
501
475
|
};
|
502
476
|
}
|
503
477
|
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
const process: Channel<never, unknown, unknown, unknown, E, Conc<A>, void> = Channel.fromIO(queue.take).flatMap(
|
516
|
-
(take) =>
|
517
|
-
take.match(Channel.endNow(undefined), Channel.failCauseNow, (value) =>
|
518
|
-
Channel.writeNow(value).zipRight(process),
|
519
|
-
),
|
520
|
-
);
|
521
|
-
return process;
|
522
|
-
}),
|
523
|
-
),
|
478
|
+
function bufferSignalConsumer<R, E, A>(
|
479
|
+
queue: Queue<readonly [Take<E, A>, Future<never, void>]>,
|
480
|
+
__tsplusTrace?: string,
|
481
|
+
): Channel<R, unknown, unknown, unknown, E, Conc<A>, void> {
|
482
|
+
const process: Channel<never, unknown, unknown, unknown, E, Conc<A>, void> = Channel.fromIO(queue.take).flatMap(
|
483
|
+
([take, promise]) =>
|
484
|
+
Channel.fromIO(promise.succeed(undefined)).zipRight(
|
485
|
+
take.match(Channel.endNow(undefined), Channel.failCauseNow, (value) =>
|
486
|
+
Channel.writeNow(value).zipRight(process),
|
487
|
+
),
|
488
|
+
),
|
524
489
|
);
|
490
|
+
return process;
|
525
491
|
}
|
526
492
|
|
527
493
|
function bufferSignalProducer<E, A>(
|
@@ -554,19 +520,27 @@ function bufferSignalProducer<E, A>(
|
|
554
520
|
);
|
555
521
|
}
|
556
522
|
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
)
|
523
|
+
/**
|
524
|
+
* Allows a faster producer to progress independently of a slower consumer by buffering
|
525
|
+
* elements into an unbounded queue.
|
526
|
+
*
|
527
|
+
* @tsplus getter fncts.io.Stream bufferUnbounded
|
528
|
+
*/
|
529
|
+
export function bufferUnbounded<R, E, A>(stream: Stream<R, E, A>, __tsplusTrace?: string): Stream<R, E, A> {
|
530
|
+
const queue = stream.toQueueUnbounded;
|
531
|
+
return new Stream(
|
532
|
+
Channel.unwrapScoped(
|
533
|
+
queue.map((queue) => {
|
534
|
+
const process: Channel<never, unknown, unknown, unknown, E, Conc<A>, void> = Channel.fromIO(queue.take).flatMap(
|
535
|
+
(take) =>
|
536
|
+
take.match(Channel.endNow(undefined), Channel.failCauseNow, (value) =>
|
537
|
+
Channel.writeNow(value).zipRight(process),
|
538
|
+
),
|
539
|
+
);
|
540
|
+
return process;
|
541
|
+
}),
|
542
|
+
),
|
568
543
|
);
|
569
|
-
return process;
|
570
544
|
}
|
571
545
|
|
572
546
|
/**
|
@@ -623,25 +597,38 @@ export function catchJustCause<R1, E, E1, A1>(pf: (e: Cause<E>) => Maybe<Stream<
|
|
623
597
|
}
|
624
598
|
|
625
599
|
/**
|
626
|
-
* Returns a stream
|
627
|
-
*
|
600
|
+
* Returns a new stream that only emits elements that are not equal to the
|
601
|
+
* previous element emitted, using the specified function to determine
|
602
|
+
* whether two elements are equal.
|
628
603
|
*
|
629
|
-
* @tsplus pipeable fncts.io.Stream
|
604
|
+
* @tsplus pipeable fncts.io.Stream changesWith
|
630
605
|
*/
|
631
|
-
export function
|
632
|
-
return <R, E>(stream: Stream<R, E, A>): Stream<R
|
633
|
-
return new Stream(
|
634
|
-
stream.channel.concatMap((as) =>
|
635
|
-
as
|
636
|
-
.map((a) => f(a).channel)
|
637
|
-
.foldLeft(Channel.unit as Channel<R1, unknown, unknown, unknown, E1, Conc<B>, unknown>, (s, a) =>
|
638
|
-
s.flatMap(() => a),
|
639
|
-
),
|
640
|
-
),
|
641
|
-
);
|
606
|
+
export function changesWith<A>(f: (x: A, y: A) => boolean, __tsplusTrace?: string) {
|
607
|
+
return <R, E>(stream: Stream<R, E, A>): Stream<R, E, A> => {
|
608
|
+
return new Stream(stream.channel.pipeTo(changesWithWriter<R, E, A>(f, Nothing())));
|
642
609
|
};
|
643
610
|
}
|
644
611
|
|
612
|
+
function changesWithWriter<R, E, A>(
|
613
|
+
f: (x: A, y: A) => boolean,
|
614
|
+
last: Maybe<A>,
|
615
|
+
__tsplusTrace?: string,
|
616
|
+
): Channel<R, E, Conc<A>, unknown, E, Conc<A>, void> {
|
617
|
+
return Channel.readWithCause(
|
618
|
+
(chunk: Conc<A>) => {
|
619
|
+
const [newLast, newChunk] = chunk.foldLeft([last, Conc.empty<A>()], ([maybeLast, os], o1) =>
|
620
|
+
maybeLast.match(
|
621
|
+
() => [Just(o1), os.append(o1)],
|
622
|
+
(o) => (f(o, o1) ? [Just(o1), os] : [Just(o1), os.append(o1)]),
|
623
|
+
),
|
624
|
+
);
|
625
|
+
return Channel.writeNow(newChunk).zipRight(changesWithWriter(f, newLast));
|
626
|
+
},
|
627
|
+
Channel.failCauseNow,
|
628
|
+
() => Channel.unit,
|
629
|
+
);
|
630
|
+
}
|
631
|
+
|
645
632
|
/**
|
646
633
|
* Exposes the underlying chunks of the stream as a stream of chunks of elements
|
647
634
|
*
|
@@ -666,39 +653,6 @@ export function chunksWith<R, E, A, R1, E1, B>(
|
|
666
653
|
};
|
667
654
|
}
|
668
655
|
|
669
|
-
function changesWithWriter<R, E, A>(
|
670
|
-
f: (x: A, y: A) => boolean,
|
671
|
-
last: Maybe<A>,
|
672
|
-
__tsplusTrace?: string,
|
673
|
-
): Channel<R, E, Conc<A>, unknown, E, Conc<A>, void> {
|
674
|
-
return Channel.readWithCause(
|
675
|
-
(chunk: Conc<A>) => {
|
676
|
-
const [newLast, newChunk] = chunk.foldLeft([last, Conc.empty<A>()], ([maybeLast, os], o1) =>
|
677
|
-
maybeLast.match(
|
678
|
-
() => [Just(o1), os.append(o1)],
|
679
|
-
(o) => (f(o, o1) ? [Just(o1), os] : [Just(o1), os.append(o1)]),
|
680
|
-
),
|
681
|
-
);
|
682
|
-
return Channel.writeNow(newChunk).zipRight(changesWithWriter(f, newLast));
|
683
|
-
},
|
684
|
-
Channel.failCauseNow,
|
685
|
-
() => Channel.unit,
|
686
|
-
);
|
687
|
-
}
|
688
|
-
|
689
|
-
/**
|
690
|
-
* Returns a new stream that only emits elements that are not equal to the
|
691
|
-
* previous element emitted, using the specified function to determine
|
692
|
-
* whether two elements are equal.
|
693
|
-
*
|
694
|
-
* @tsplus pipeable fncts.io.Stream changesWith
|
695
|
-
*/
|
696
|
-
export function changesWith<A>(f: (x: A, y: A) => boolean, __tsplusTrace?: string) {
|
697
|
-
return <R, E>(stream: Stream<R, E, A>): Stream<R, E, A> => {
|
698
|
-
return new Stream(stream.channel.pipeTo(changesWithWriter<R, E, A>(f, Nothing())));
|
699
|
-
};
|
700
|
-
}
|
701
|
-
|
702
656
|
/**
|
703
657
|
* Transforms all elements of the stream for as long as the specified partial function is defined.
|
704
658
|
*
|
@@ -755,20 +709,6 @@ function collectWhileIOLoop<R, E, A, R1, E1, B>(
|
|
755
709
|
}
|
756
710
|
}
|
757
711
|
|
758
|
-
function combineProducer<Err, Elem>(
|
759
|
-
handoff: Handoff<Exit<Maybe<Err>, Elem>>,
|
760
|
-
latch: Handoff<void>,
|
761
|
-
__tsplusTrace?: string,
|
762
|
-
): Channel<never, Err, Elem, unknown, never, never, any> {
|
763
|
-
return Channel.fromIO(latch.take).zipRight(
|
764
|
-
Channel.readWithCause(
|
765
|
-
(value) => Channel.fromIO(handoff.offer(Exit.succeed(value))).zipRight(combineProducer(handoff, latch)),
|
766
|
-
(cause) => Channel.fromIO(handoff.offer(Exit.failCause(cause.map(Maybe.just)))),
|
767
|
-
() => Channel.fromIO(handoff.offer(Exit.fail(Nothing()))).zipRight(combineProducer(handoff, latch)),
|
768
|
-
),
|
769
|
-
);
|
770
|
-
}
|
771
|
-
|
772
712
|
/**
|
773
713
|
* Combines the elements from this stream and the specified stream by repeatedly applying the
|
774
714
|
* function `f` to extract an element using both sides and conceptually "offer"
|
@@ -811,21 +751,6 @@ export function combine<R, E, A, R1, E1, A1, S, R2, A2>(
|
|
811
751
|
};
|
812
752
|
}
|
813
753
|
|
814
|
-
function combineChunksProducer<Err, Elem>(
|
815
|
-
handoff: Handoff<Take<Err, Elem>>,
|
816
|
-
latch: Handoff<void>,
|
817
|
-
__tsplusTrace?: string,
|
818
|
-
): Channel<never, Err, Conc<Elem>, unknown, never, never, any> {
|
819
|
-
return Channel.fromIO(latch.take).zipRight(
|
820
|
-
Channel.readWithCause(
|
821
|
-
(chunk: Conc<Elem>) =>
|
822
|
-
Channel.fromIO(handoff.offer(Take.chunk(chunk))).zipRight(combineChunksProducer(handoff, latch)),
|
823
|
-
(cause) => Channel.fromIO(handoff.offer(Take.failCause(cause))),
|
824
|
-
() => Channel.fromIO(handoff.offer(Take.end)),
|
825
|
-
),
|
826
|
-
);
|
827
|
-
}
|
828
|
-
|
829
754
|
/**
|
830
755
|
* Combines the chunks from this stream and the specified stream by repeatedly applying the
|
831
756
|
* function `f` to extract a chunk using both sides and conceptually "offer"
|
@@ -872,6 +797,35 @@ export function combineChunks<R, E, A, R1, E1, A1, S, R2, A2>(
|
|
872
797
|
};
|
873
798
|
}
|
874
799
|
|
800
|
+
function combineChunksProducer<Err, Elem>(
|
801
|
+
handoff: Handoff<Take<Err, Elem>>,
|
802
|
+
latch: Handoff<void>,
|
803
|
+
__tsplusTrace?: string,
|
804
|
+
): Channel<never, Err, Conc<Elem>, unknown, never, never, any> {
|
805
|
+
return Channel.fromIO(latch.take).zipRight(
|
806
|
+
Channel.readWithCause(
|
807
|
+
(chunk: Conc<Elem>) =>
|
808
|
+
Channel.fromIO(handoff.offer(Take.chunk(chunk))).zipRight(combineChunksProducer(handoff, latch)),
|
809
|
+
(cause) => Channel.fromIO(handoff.offer(Take.failCause(cause))),
|
810
|
+
() => Channel.fromIO(handoff.offer(Take.end)),
|
811
|
+
),
|
812
|
+
);
|
813
|
+
}
|
814
|
+
|
815
|
+
function combineProducer<Err, Elem>(
|
816
|
+
handoff: Handoff<Exit<Maybe<Err>, Elem>>,
|
817
|
+
latch: Handoff<void>,
|
818
|
+
__tsplusTrace?: string,
|
819
|
+
): Channel<never, Err, Elem, unknown, never, never, any> {
|
820
|
+
return Channel.fromIO(latch.take).zipRight(
|
821
|
+
Channel.readWithCause(
|
822
|
+
(value) => Channel.fromIO(handoff.offer(Exit.succeed(value))).zipRight(combineProducer(handoff, latch)),
|
823
|
+
(cause) => Channel.fromIO(handoff.offer(Exit.failCause(cause.map(Maybe.just)))),
|
824
|
+
() => Channel.fromIO(handoff.offer(Exit.fail(Nothing()))).zipRight(combineProducer(handoff, latch)),
|
825
|
+
),
|
826
|
+
);
|
827
|
+
}
|
828
|
+
|
875
829
|
/**
|
876
830
|
* Concatenates the specified stream with this stream, resulting in a stream
|
877
831
|
* that emits the elements from this stream and then the elements from the specified stream.
|
@@ -884,6 +838,18 @@ export function concat<R1, E1, A1>(that: Stream<R1, E1, A1>, __tsplusTrace?: str
|
|
884
838
|
};
|
885
839
|
}
|
886
840
|
|
841
|
+
/**
|
842
|
+
* Provides some of the environment required to run this effect,
|
843
|
+
* leaving the remainder `R0`.
|
844
|
+
*
|
845
|
+
* @tsplus pipeable fncts.io.Stream contramapEnvironment
|
846
|
+
*/
|
847
|
+
export function contramapEnvironment<R, R0>(f: (r0: Environment<R0>) => Environment<R>, __tsplusTrace?: string) {
|
848
|
+
return <E, A>(ra: Stream<R, E, A>): Stream<R0, E, A> => {
|
849
|
+
return Stream.environment<R0>().flatMap((r0) => ra.provideEnvironment(f(r0)));
|
850
|
+
};
|
851
|
+
}
|
852
|
+
|
887
853
|
/**
|
888
854
|
* Composes this stream with the specified stream to create a cartesian product of elements.
|
889
855
|
* The `that` stream would be run multiple times, for every element in the `this` stream.
|
@@ -911,18 +877,6 @@ export function crossWith<A, R1, E1, B, C>(fb: Stream<R1, E1, B>, f: (a: A, b: B
|
|
911
877
|
};
|
912
878
|
}
|
913
879
|
|
914
|
-
/**
|
915
|
-
* Provides some of the environment required to run this effect,
|
916
|
-
* leaving the remainder `R0`.
|
917
|
-
*
|
918
|
-
* @tsplus pipeable fncts.io.Stream contramapEnvironment
|
919
|
-
*/
|
920
|
-
export function contramapEnvironment<R, R0>(f: (r0: Environment<R0>) => Environment<R>, __tsplusTrace?: string) {
|
921
|
-
return <E, A>(ra: Stream<R, E, A>): Stream<R0, E, A> => {
|
922
|
-
return Stream.environment<R0>().flatMap((r0) => ra.provideEnvironment(f(r0)));
|
923
|
-
};
|
924
|
-
}
|
925
|
-
|
926
880
|
/**
|
927
881
|
* @tsplus pipeable fncts.io.Stream debounce
|
928
882
|
*/
|
@@ -933,7 +887,7 @@ export function debounce(duration: Lazy<Duration>, __tsplusTrace?: string) {
|
|
933
887
|
Do((Δ) => {
|
934
888
|
const handoff = Δ(Handoff<HandoffSignal<E, A>>());
|
935
889
|
function enqueue(last: Conc<A>, __tsplusTrace?: string) {
|
936
|
-
return grafter(Clock.sleep(duration).as(last).fork).map((f) => consumer(DebounceState.Previous(f)));
|
890
|
+
return grafter.graft(Clock.sleep(duration).as(last).fork).map((f) => consumer(DebounceState.Previous(f)));
|
937
891
|
}
|
938
892
|
const producer: Channel<R, E, Conc<A>, unknown, E, never, unknown> = Channel.readWithCause(
|
939
893
|
(inp: Conc<A>) =>
|
@@ -999,10 +953,14 @@ export function debounce(duration: Lazy<Duration>, __tsplusTrace?: string) {
|
|
999
953
|
}
|
1000
954
|
|
1001
955
|
/**
|
1002
|
-
*
|
956
|
+
* Switches to the provided stream in case this one is empty.
|
957
|
+
*
|
958
|
+
* @tsplus pipeable fncts.io.Stream defaultIfEmpty
|
1003
959
|
*/
|
1004
|
-
export function
|
1005
|
-
return
|
960
|
+
export function defaultIfEmpty<R1, E1, B>(fb: Stream<R1, E1, B>, __tsplusTrace?: string) {
|
961
|
+
return <R, E, A>(fa: Stream<R, E, A>): Stream<R | R1, E | E1, A | B> => {
|
962
|
+
return new Stream(fa.channel.pipeTo(defaultIfEmptyWriter(fb)));
|
963
|
+
};
|
1006
964
|
}
|
1007
965
|
|
1008
966
|
function defaultIfEmptyWriter<R, E, A, R1, E1, B>(
|
@@ -1018,14 +976,10 @@ function defaultIfEmptyWriter<R, E, A, R1, E1, B>(
|
|
1018
976
|
}
|
1019
977
|
|
1020
978
|
/**
|
1021
|
-
*
|
1022
|
-
*
|
1023
|
-
* @tsplus pipeable fncts.io.Stream defaultIfEmpty
|
979
|
+
* @tsplus static fncts.io.StreamOps defer
|
1024
980
|
*/
|
1025
|
-
export function
|
1026
|
-
return
|
1027
|
-
return new Stream(fa.channel.pipeTo(defaultIfEmptyWriter(fb)));
|
1028
|
-
};
|
981
|
+
export function defer<R, E, A>(self: Lazy<Stream<R, E, A>>): Stream<R, E, A> {
|
982
|
+
return new Stream(Channel.defer(self().channel));
|
1029
983
|
}
|
1030
984
|
|
1031
985
|
/**
|
@@ -1167,6 +1121,17 @@ export function drain<R, E, A>(fa: Stream<R, E, A>, __tsplusTrace?: string): Str
|
|
1167
1121
|
return new Stream(fa.channel.drain);
|
1168
1122
|
}
|
1169
1123
|
|
1124
|
+
/**
|
1125
|
+
* Drops the specified number of elements from this stream.
|
1126
|
+
*
|
1127
|
+
* @tsplus pipeable fncts.io.Stream drop
|
1128
|
+
*/
|
1129
|
+
export function drop(n: number, __tsplusTrace?: string) {
|
1130
|
+
return <R, E, A>(stream: Stream<R, E, A>): Stream<R, E, A> => {
|
1131
|
+
return new Stream(stream.channel.pipeTo(dropLoop(n)));
|
1132
|
+
};
|
1133
|
+
}
|
1134
|
+
|
1170
1135
|
function dropLoop<R, E, A>(r: number, __tsplusTrace?: string): Channel<R, E, Conc<A>, unknown, E, Conc<A>, unknown> {
|
1171
1136
|
return Channel.readWith(
|
1172
1137
|
(inp: Conc<A>) => {
|
@@ -1181,13 +1146,14 @@ function dropLoop<R, E, A>(r: number, __tsplusTrace?: string): Channel<R, E, Con
|
|
1181
1146
|
}
|
1182
1147
|
|
1183
1148
|
/**
|
1184
|
-
* Drops the
|
1149
|
+
* Drops all elements of the stream until the specified predicate evaluates
|
1150
|
+
* to `true`.
|
1185
1151
|
*
|
1186
|
-
* @tsplus pipeable fncts.io.Stream
|
1152
|
+
* @tsplus pipeable fncts.io.Stream dropUntil
|
1187
1153
|
*/
|
1188
|
-
export function
|
1189
|
-
return <R, E
|
1190
|
-
return
|
1154
|
+
export function dropUntil<A>(p: Predicate<A>, __tsplusTrace?: string) {
|
1155
|
+
return <R, E>(stream: Stream<R, E, A>): Stream<R, E, A> => {
|
1156
|
+
return stream.dropWhile(p.invert).drop(1);
|
1191
1157
|
};
|
1192
1158
|
}
|
1193
1159
|
|
@@ -1203,18 +1169,6 @@ export function dropWhile<A>(p: Predicate<A>, __tsplusTrace?: string) {
|
|
1203
1169
|
};
|
1204
1170
|
}
|
1205
1171
|
|
1206
|
-
/**
|
1207
|
-
* Drops all elements of the stream until the specified predicate evaluates
|
1208
|
-
* to `true`.
|
1209
|
-
*
|
1210
|
-
* @tsplus pipeable fncts.io.Stream dropUntil
|
1211
|
-
*/
|
1212
|
-
export function dropUntil<A>(p: Predicate<A>, __tsplusTrace?: string) {
|
1213
|
-
return <R, E>(stream: Stream<R, E, A>): Stream<R, E, A> => {
|
1214
|
-
return stream.dropWhile(p.invert).drop(1);
|
1215
|
-
};
|
1216
|
-
}
|
1217
|
-
|
1218
1172
|
/**
|
1219
1173
|
* Returns a stream whose failures and successes have been lifted into an
|
1220
1174
|
* `Either`. The resulting stream cannot fail, because the failures have
|
@@ -1228,11 +1182,76 @@ export function either<R, E, A>(stream: Stream<R, E, A>, __tsplusTrace?: string)
|
|
1228
1182
|
return stream.map(Either.right).catchAll((e) => Stream.succeedNow(Either.left(e)));
|
1229
1183
|
}
|
1230
1184
|
|
1185
|
+
/**
|
1186
|
+
* Returns a stream made of the concatenation in strict order of all the streams
|
1187
|
+
* produced by passing each element of this stream to `f`
|
1188
|
+
*
|
1189
|
+
* @tsplus pipeable fncts.io.Stream flatMap
|
1190
|
+
*/
|
1191
|
+
export function flatMap<A, R1, E1, B>(f: (a: A) => Stream<R1, E1, B>, __tsplusTrace?: string) {
|
1192
|
+
return <R, E>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, B> => {
|
1193
|
+
return new Stream(
|
1194
|
+
stream.channel.concatMap((as) =>
|
1195
|
+
as
|
1196
|
+
.map((a) => f(a).channel)
|
1197
|
+
.foldLeft(Channel.unit as Channel<R1, unknown, unknown, unknown, E1, Conc<B>, unknown>, (s, a) =>
|
1198
|
+
s.flatMap(() => a),
|
1199
|
+
),
|
1200
|
+
),
|
1201
|
+
);
|
1202
|
+
};
|
1203
|
+
}
|
1204
|
+
|
1205
|
+
/**
|
1206
|
+
* Composes this stream with the specified stream to create a cartesian product of elements,
|
1207
|
+
* but keeps only elements from this stream.
|
1208
|
+
* The `that` stream would be run multiple times, for every element in the `this` stream.
|
1209
|
+
*
|
1210
|
+
* @tsplus pipeable fncts.io.Stream zipLeft
|
1211
|
+
*/
|
1212
|
+
export function zipLeft<R1, E1, A1>(that: Stream<R1, E1, A1>, __tsplusTrace?: string) {
|
1213
|
+
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, A> => {
|
1214
|
+
return stream.crossWith(that, (a, _) => a);
|
1215
|
+
};
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
/**
|
1219
|
+
* Composes this stream with the specified stream to create a cartesian product of elements,
|
1220
|
+
* but keeps only elements from the other stream.
|
1221
|
+
* The `that` stream would be run multiple times, for every element in the `this` stream.
|
1222
|
+
*
|
1223
|
+
* @tsplus pipeable fncts.io.Stream zipRight
|
1224
|
+
*/
|
1225
|
+
export function zipRight<R1, E1, A1>(that: Stream<R1, E1, A1>, __tsplusTrace?: string) {
|
1226
|
+
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, A1> => {
|
1227
|
+
return stream.crossWith(that, (_, b) => b);
|
1228
|
+
};
|
1229
|
+
}
|
1230
|
+
|
1231
1231
|
/**
|
1232
1232
|
* @tsplus static fncts.io.StreamOps empty
|
1233
1233
|
*/
|
1234
1234
|
export const empty: Stream<never, never, never> = Stream.fromChunkNow(Conc.empty<never>());
|
1235
1235
|
|
1236
|
+
export type TerminationStrategy = "Left" | "Right" | "Both" | "Either";
|
1237
|
+
|
1238
|
+
/**
|
1239
|
+
* Halts the evaluation of this stream when the provided IO completes. The given IO
|
1240
|
+
* will be forked as part of the returned stream, and its success will be discarded.
|
1241
|
+
*
|
1242
|
+
* An element in the process of being pulled will not be interrupted when the IO
|
1243
|
+
* completes. See `interruptWhen` for this behavior.
|
1244
|
+
*
|
1245
|
+
* If the IO completes with a failure, the stream will emit that failure.
|
1246
|
+
*
|
1247
|
+
* @tsplus pipeable fncts.io.Stream endWhen
|
1248
|
+
*/
|
1249
|
+
export function endWhen<R1, E1>(io: IO<R1, E1, any>, __tsplusTrace?: string) {
|
1250
|
+
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, A> => {
|
1251
|
+
return new Stream(Channel.unwrapScoped(io.forkScoped.map((fiber) => stream.channel.pipeTo(endWhenWriter(fiber)))));
|
1252
|
+
};
|
1253
|
+
}
|
1254
|
+
|
1236
1255
|
function endWhenWriter<E, A, E1>(
|
1237
1256
|
fiber: Fiber<E1, any>,
|
1238
1257
|
__tsplusTrace?: string,
|
@@ -1252,23 +1271,6 @@ function endWhenWriter<E, A, E1>(
|
|
1252
1271
|
);
|
1253
1272
|
}
|
1254
1273
|
|
1255
|
-
/**
|
1256
|
-
* Halts the evaluation of this stream when the provided IO completes. The given IO
|
1257
|
-
* will be forked as part of the returned stream, and its success will be discarded.
|
1258
|
-
*
|
1259
|
-
* An element in the process of being pulled will not be interrupted when the IO
|
1260
|
-
* completes. See `interruptWhen` for this behavior.
|
1261
|
-
*
|
1262
|
-
* If the IO completes with a failure, the stream will emit that failure.
|
1263
|
-
*
|
1264
|
-
* @tsplus pipeable fncts.io.Stream endWhen
|
1265
|
-
*/
|
1266
|
-
export function endWhen<R1, E1>(io: IO<R1, E1, any>, __tsplusTrace?: string) {
|
1267
|
-
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, A> => {
|
1268
|
-
return new Stream(Channel.unwrapScoped(io.forkScoped.map((fiber) => stream.channel.pipeTo(endWhenWriter(fiber)))));
|
1269
|
-
};
|
1270
|
-
}
|
1271
|
-
|
1272
1274
|
/**
|
1273
1275
|
* @tsplus pipeable fncts.io.Stream ensuring
|
1274
1276
|
*/
|
@@ -1327,15 +1329,6 @@ export function execute<R, E>(io: IO<R, E, any>, __tsplusTrace?: string): Stream
|
|
1327
1329
|
return Stream.fromIO(io).drain;
|
1328
1330
|
}
|
1329
1331
|
|
1330
|
-
/**
|
1331
|
-
* Halt a stream with the specified error
|
1332
|
-
*
|
1333
|
-
* @tsplus static fncts.io.StreamOps failNow
|
1334
|
-
*/
|
1335
|
-
export function failNow<E>(error: E, __tsplusTrace?: string): Stream<never, E, never> {
|
1336
|
-
return new Stream(Channel.failNow(error));
|
1337
|
-
}
|
1338
|
-
|
1339
1332
|
/**
|
1340
1333
|
* Halt a stream with the specified error
|
1341
1334
|
*
|
@@ -1348,26 +1341,35 @@ export function fail<E>(error: Lazy<E>, __tsplusTrace?: string): Stream<never, E
|
|
1348
1341
|
/**
|
1349
1342
|
* The stream that always halts with `cause`.
|
1350
1343
|
*
|
1351
|
-
* @tsplus static fncts.io.StreamOps
|
1344
|
+
* @tsplus static fncts.io.StreamOps failCause
|
1352
1345
|
*/
|
1353
|
-
export function
|
1354
|
-
return Stream.fromIO(IO.
|
1346
|
+
export function failCause<E>(cause: Lazy<Cause<E>>, __tsplusTrace?: string): Stream<never, E, never> {
|
1347
|
+
return Stream.fromIO(IO.failCause(cause));
|
1355
1348
|
}
|
1356
1349
|
|
1357
1350
|
/**
|
1358
1351
|
* The stream that always halts with `cause`.
|
1359
1352
|
*
|
1360
|
-
* @tsplus static fncts.io.StreamOps
|
1353
|
+
* @tsplus static fncts.io.StreamOps failCauseNow
|
1361
1354
|
*/
|
1362
|
-
export function
|
1363
|
-
return Stream.fromIO(IO.
|
1355
|
+
export function failCauseNow<E>(cause: Cause<E>, __tsplusTrace?: string): Stream<never, E, never> {
|
1356
|
+
return Stream.fromIO(IO.failCauseNow(cause));
|
1357
|
+
}
|
1358
|
+
/**
|
1359
|
+
* Halt a stream with the specified error
|
1360
|
+
*
|
1361
|
+
* @tsplus static fncts.io.StreamOps failNow
|
1362
|
+
*/
|
1363
|
+
export function failNow<E>(error: E, __tsplusTrace?: string): Stream<never, E, never> {
|
1364
|
+
return new Stream(Channel.failNow(error));
|
1364
1365
|
}
|
1365
|
-
|
1366
1366
|
/**
|
1367
1367
|
* @tsplus pipeable fncts.io.Stream filter
|
1368
1368
|
*/
|
1369
1369
|
export function filter<A, B extends A>(refinement: Refinement<A, B>): <R, E>(fa: Stream<R, E, A>) => Stream<R, E, B>;
|
1370
|
+
|
1370
1371
|
export function filter<A>(predicate: Predicate<A>): <R, E>(fa: Stream<R, E, A>) => Stream<R, E, A>;
|
1372
|
+
|
1371
1373
|
export function filter<A>(predicate: Predicate<A>, __tsplusTrace?: string) {
|
1372
1374
|
return <R, E>(fa: Stream<R, E, A>): Stream<R, E, A> => {
|
1373
1375
|
return fa.mapChunks((chunk) => chunk.filter(predicate));
|
@@ -1507,6 +1509,16 @@ export function flatten<R, E, R1, E1, A>(
|
|
1507
1509
|
return self.flatMap(identity);
|
1508
1510
|
}
|
1509
1511
|
|
1512
|
+
/**
|
1513
|
+
* Submerges the chunks carried by this stream into the stream's structure, while
|
1514
|
+
* still preserving them.
|
1515
|
+
*
|
1516
|
+
* @tsplus getter fncts.io.Stream flattenChunks
|
1517
|
+
*/
|
1518
|
+
export function flattenChunks<R, E, A>(stream: Stream<R, E, Conc<A>>, __tsplusTrace?: string): Stream<R, E, A> {
|
1519
|
+
return new Stream(stream.channel.mapOut((c) => c.flatten));
|
1520
|
+
}
|
1521
|
+
|
1510
1522
|
/**
|
1511
1523
|
* Unwraps `Exit` values that also signify end-of-stream by failing with `None`.
|
1512
1524
|
*
|
@@ -1553,16 +1565,6 @@ export function flattenTake<R, E, E1, A>(
|
|
1553
1565
|
return stream.map((take) => take.exit).flattenExitOption.flattenChunks;
|
1554
1566
|
}
|
1555
1567
|
|
1556
|
-
/**
|
1557
|
-
* Submerges the chunks carried by this stream into the stream's structure, while
|
1558
|
-
* still preserving them.
|
1559
|
-
*
|
1560
|
-
* @tsplus getter fncts.io.Stream flattenChunks
|
1561
|
-
*/
|
1562
|
-
export function flattenChunks<R, E, A>(stream: Stream<R, E, Conc<A>>, __tsplusTrace?: string): Stream<R, E, A> {
|
1563
|
-
return new Stream(stream.channel.mapOut((c) => c.flatten));
|
1564
|
-
}
|
1565
|
-
|
1566
1568
|
/**
|
1567
1569
|
* Repeats this stream forever.
|
1568
1570
|
*
|
@@ -1573,12 +1575,27 @@ export function forever<R, E, A>(stream: Stream<R, E, A>, __tsplusTrace?: string
|
|
1573
1575
|
}
|
1574
1576
|
|
1575
1577
|
/**
|
1576
|
-
*
|
1577
|
-
*
|
1578
|
-
* @tsplus static fncts.io.StreamOps fromChunkNow
|
1578
|
+
* @tsplus static fncts.io.StreamOps fromAsyncIterable
|
1579
1579
|
*/
|
1580
|
-
export function
|
1581
|
-
return new Stream(
|
1580
|
+
export function fromAsyncIterable<A>(iterable: AsyncIterable<A>, __tsplusTrace?: string): Stream<unknown, never, A> {
|
1581
|
+
return new Stream(fromAsyncIterableLoop(iterable[Symbol.asyncIterator]()));
|
1582
|
+
}
|
1583
|
+
|
1584
|
+
function fromAsyncIterableLoop<A>(
|
1585
|
+
iterator: AsyncIterator<A>,
|
1586
|
+
__tsplusTrace?: string,
|
1587
|
+
): Channel<unknown, unknown, unknown, unknown, never, Conc<A>, unknown> {
|
1588
|
+
return Channel.unwrap(
|
1589
|
+
IO.async<unknown, never, Channel<unknown, unknown, unknown, unknown, never, Conc<A>, unknown>>((k) => {
|
1590
|
+
iterator
|
1591
|
+
.next()
|
1592
|
+
.then((result) =>
|
1593
|
+
result.done
|
1594
|
+
? k(IO.succeedNow(Channel.end(undefined)))
|
1595
|
+
: k(IO.succeedNow(Channel.writeNow(Conc.single(result.value)).zipRight(fromAsyncIterableLoop(iterator)))),
|
1596
|
+
);
|
1597
|
+
}),
|
1598
|
+
);
|
1582
1599
|
}
|
1583
1600
|
|
1584
1601
|
/**
|
@@ -1591,91 +1608,34 @@ export function fromChunk<O>(c: Lazy<Conc<O>>, __tsplusTrace?: string): Stream<n
|
|
1591
1608
|
}
|
1592
1609
|
|
1593
1610
|
/**
|
1594
|
-
*
|
1611
|
+
* Creates a stream from a `Chunk` of values
|
1612
|
+
*
|
1613
|
+
* @tsplus static fncts.io.StreamOps fromChunkNow
|
1595
1614
|
*/
|
1596
|
-
export function
|
1597
|
-
|
1598
|
-
onError: (error: unknown) => E,
|
1599
|
-
): Stream<never, E, A> {
|
1600
|
-
return Stream.unwrapScoped(
|
1601
|
-
IO(evaluate().getReader())
|
1602
|
-
.acquireRelease((reader) => IO.fromPromiseHalt(reader.cancel()))
|
1603
|
-
.map((reader) =>
|
1604
|
-
Stream.repeatIOMaybe(
|
1605
|
-
IO.fromPromiseCatch(reader.read(), (reason) => Just(onError(reason))).flatMap(({ done, value }) =>
|
1606
|
-
done ? IO.failNow(Nothing()) : IO.succeedNow(value),
|
1607
|
-
),
|
1608
|
-
),
|
1609
|
-
),
|
1610
|
-
);
|
1615
|
+
export function fromChunkNow<O>(c: Conc<O>, __tsplusTrace?: string): Stream<never, never, O> {
|
1616
|
+
return new Stream(Channel.defer(() => (c.isEmpty ? Channel.unit : Channel.writeNow(c))));
|
1611
1617
|
}
|
1612
1618
|
|
1613
1619
|
/**
|
1614
|
-
*
|
1615
|
-
*
|
1616
|
-
* @tsplus static fncts.io.StreamOps scoped
|
1620
|
+
* @tsplus static fncts.io.StreamOps fromHub
|
1617
1621
|
*/
|
1618
|
-
export function
|
1619
|
-
|
1622
|
+
export function fromHub<A>(
|
1623
|
+
hub: Lazy<Hub<A>>,
|
1624
|
+
maxChunkSize = DEFAULT_CHUNK_SIZE,
|
1625
|
+
__tsplusTrace?: string,
|
1626
|
+
): Stream<never, never, A> {
|
1627
|
+
return Stream.scoped(hub().subscribe).flatMap((queue) => Stream.fromQueueWithShutdown(queue, maxChunkSize));
|
1620
1628
|
}
|
1621
1629
|
|
1622
1630
|
/**
|
1623
|
-
*
|
1624
|
-
*
|
1625
|
-
* @tsplus pipeable fncts.io.Stream sliding
|
1631
|
+
* @tsplus static fncts.io.StreamOps fromHubScoped
|
1626
1632
|
*/
|
1627
|
-
export function
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
if (length >= chunkSize) {
|
1634
|
-
const array = new Array<Conc<A>>((length - chunkSize) / stepSize + 1);
|
1635
|
-
let arrayIndex = 0;
|
1636
|
-
let chunkIndex = 0;
|
1637
|
-
while (chunkIndex + chunkSize <= length) {
|
1638
|
-
array[arrayIndex] = updatedChunk.slice(chunkIndex, chunkIndex + chunkSize);
|
1639
|
-
arrayIndex += 1;
|
1640
|
-
chunkIndex += stepSize;
|
1641
|
-
}
|
1642
|
-
return [updatedChunk.drop(chunkIndex), Conc.fromArray(array)];
|
1643
|
-
} else {
|
1644
|
-
return [updatedChunk, Conc.empty()];
|
1645
|
-
}
|
1646
|
-
}
|
1647
|
-
function sliding(chunk: Conc<A>, written: boolean): Channel<never, E, Conc<A>, any, E, Conc<Conc<A>>, any> {
|
1648
|
-
return Channel.readWithCause(
|
1649
|
-
(input) => {
|
1650
|
-
const [updatedChunk, out] = slidingChunk(chunk, input);
|
1651
|
-
if (out.isEmpty) {
|
1652
|
-
return sliding(updatedChunk, written);
|
1653
|
-
} else {
|
1654
|
-
return Channel.writeNow(out) > sliding(updatedChunk, true);
|
1655
|
-
}
|
1656
|
-
},
|
1657
|
-
(err) => {
|
1658
|
-
const index = written && chunkSize > stepSize ? chunkSize - stepSize : 0;
|
1659
|
-
if (index >= chunk.length) {
|
1660
|
-
return Channel.failCauseNow(err);
|
1661
|
-
} else {
|
1662
|
-
return Channel.writeNow(Conc.single(chunk)) > Channel.failCauseNow(err);
|
1663
|
-
}
|
1664
|
-
},
|
1665
|
-
(done) => {
|
1666
|
-
const index = written && chunkSize > stepSize ? chunkSize - stepSize : 0;
|
1667
|
-
if (index >= chunk.length) {
|
1668
|
-
return Channel.succeedNow(done);
|
1669
|
-
} else {
|
1670
|
-
return Channel.writeNow(Conc.single(chunk)) > Channel.succeedNow(done);
|
1671
|
-
}
|
1672
|
-
},
|
1673
|
-
);
|
1674
|
-
}
|
1675
|
-
|
1676
|
-
return new Stream(self.channel >>> sliding(Conc.empty(), false));
|
1677
|
-
});
|
1678
|
-
};
|
1633
|
+
export function fromHubScoped<A>(
|
1634
|
+
hub: Lazy<Hub<A>>,
|
1635
|
+
maxChunkSize = DEFAULT_CHUNK_SIZE,
|
1636
|
+
__tsplusTrace?: string,
|
1637
|
+
): IO<Scope, never, Stream<never, never, A>> {
|
1638
|
+
return IO.defer(hub().subscribe.map((queue) => Stream.fromQueueWithShutdown(queue, maxChunkSize)));
|
1679
1639
|
}
|
1680
1640
|
|
1681
1641
|
/**
|
@@ -1703,30 +1663,6 @@ export function fromIOMaybe<R, E, A>(fa: IO<R, Maybe<E>, A>, __tsplusTrace?: str
|
|
1703
1663
|
);
|
1704
1664
|
}
|
1705
1665
|
|
1706
|
-
function fromAsyncIterableLoop<A>(
|
1707
|
-
iterator: AsyncIterator<A>,
|
1708
|
-
__tsplusTrace?: string,
|
1709
|
-
): Channel<unknown, unknown, unknown, unknown, never, Conc<A>, unknown> {
|
1710
|
-
return Channel.unwrap(
|
1711
|
-
IO.async<unknown, never, Channel<unknown, unknown, unknown, unknown, never, Conc<A>, unknown>>((k) => {
|
1712
|
-
iterator
|
1713
|
-
.next()
|
1714
|
-
.then((result) =>
|
1715
|
-
result.done
|
1716
|
-
? k(IO.succeedNow(Channel.end(undefined)))
|
1717
|
-
: k(IO.succeedNow(Channel.writeNow(Conc.single(result.value)).zipRight(fromAsyncIterableLoop(iterator)))),
|
1718
|
-
);
|
1719
|
-
}),
|
1720
|
-
);
|
1721
|
-
}
|
1722
|
-
|
1723
|
-
/**
|
1724
|
-
* @tsplus static fncts.io.StreamOps fromAsyncIterable
|
1725
|
-
*/
|
1726
|
-
export function fromAsyncIterable<A>(iterable: AsyncIterable<A>, __tsplusTrace?: string): Stream<unknown, never, A> {
|
1727
|
-
return new Stream(fromAsyncIterableLoop(iterable[Symbol.asyncIterator]()));
|
1728
|
-
}
|
1729
|
-
|
1730
1666
|
/**
|
1731
1667
|
* @tsplus static fncts.io.StreamOps fromIterable
|
1732
1668
|
*/
|
@@ -1833,64 +1769,43 @@ export function fromQueueWithShutdown<RA, RB, EA, EB, A, B>(
|
|
1833
1769
|
}
|
1834
1770
|
|
1835
1771
|
/**
|
1836
|
-
* @tsplus static fncts.io.StreamOps
|
1837
|
-
*/
|
1838
|
-
export function fromHub<A>(
|
1839
|
-
hub: Lazy<Hub<A>>,
|
1840
|
-
maxChunkSize = DEFAULT_CHUNK_SIZE,
|
1841
|
-
__tsplusTrace?: string,
|
1842
|
-
): Stream<never, never, A> {
|
1843
|
-
return Stream.scoped(hub().subscribe).flatMap((queue) => Stream.fromQueueWithShutdown(queue, maxChunkSize));
|
1844
|
-
}
|
1845
|
-
|
1846
|
-
/**
|
1847
|
-
* @tsplus static fncts.io.StreamOps fromHubScoped
|
1772
|
+
* @tsplus static fncts.io.StreamOps fromReadableStream
|
1848
1773
|
*/
|
1849
|
-
export function
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1774
|
+
export function fromReadableStream<A, E>(
|
1775
|
+
evaluate: Lazy<ReadableStream<A>>,
|
1776
|
+
onError: (error: unknown) => E,
|
1777
|
+
): Stream<never, E, A> {
|
1778
|
+
return Stream.unwrapScoped(
|
1779
|
+
IO(evaluate().getReader())
|
1780
|
+
.acquireRelease((reader) => IO.fromPromiseHalt(reader.cancel()))
|
1781
|
+
.map((reader) =>
|
1782
|
+
Stream.repeatIOMaybe(
|
1783
|
+
IO.fromPromiseCatch(reader.read(), (reason) => Just(onError(reason))).flatMap(({ done, value }) =>
|
1784
|
+
done ? IO.failNow(Nothing()) : IO.succeedNow(value),
|
1785
|
+
),
|
1786
|
+
),
|
1787
|
+
),
|
1788
|
+
);
|
1855
1789
|
}
|
1856
1790
|
|
1857
1791
|
/**
|
1858
1792
|
* Halt a stream with the specified exception
|
1859
1793
|
*
|
1860
|
-
* @tsplus static fncts.io.StreamOps
|
1794
|
+
* @tsplus static fncts.io.StreamOps halt
|
1861
1795
|
*/
|
1862
|
-
export function
|
1796
|
+
export function halt(u: Lazy<unknown>, __tsplusTrace?: string): Stream<never, never, never> {
|
1863
1797
|
return new Stream(Channel.halt(u));
|
1864
1798
|
}
|
1865
1799
|
|
1866
1800
|
/**
|
1867
1801
|
* Halt a stream with the specified exception
|
1868
1802
|
*
|
1869
|
-
* @tsplus static fncts.io.StreamOps
|
1803
|
+
* @tsplus static fncts.io.StreamOps haltNow
|
1870
1804
|
*/
|
1871
|
-
export function
|
1805
|
+
export function haltNow(u: unknown, __tsplusTrace?: string): Stream<never, never, never> {
|
1872
1806
|
return new Stream(Channel.halt(u));
|
1873
1807
|
}
|
1874
1808
|
|
1875
|
-
function haltWhenWriter<E, A, E1>(
|
1876
|
-
fiber: Fiber<E1, any>,
|
1877
|
-
__tsplusTrace?: string,
|
1878
|
-
): Channel<never, E | E1, Conc<A>, unknown, E | E1, Conc<A>, void> {
|
1879
|
-
return Channel.unwrap(
|
1880
|
-
fiber.poll.map((maybeExit) =>
|
1881
|
-
maybeExit.match(
|
1882
|
-
() =>
|
1883
|
-
Channel.readWith(
|
1884
|
-
(i: Conc<A>) => Channel.writeNow(i).zipRight(haltWhenWriter<E, A, E1>(fiber)),
|
1885
|
-
Channel.failNow,
|
1886
|
-
() => Channel.unit,
|
1887
|
-
),
|
1888
|
-
(exit) => exit.match(Channel.failCauseNow, () => Channel.unit),
|
1889
|
-
),
|
1890
|
-
),
|
1891
|
-
);
|
1892
|
-
}
|
1893
|
-
|
1894
1809
|
/**
|
1895
1810
|
* Halts the evaluation of this stream when the provided IO completes. The
|
1896
1811
|
* given IO will be forked as part of the returned stream, and its success
|
@@ -1909,6 +1824,19 @@ export function haltWhen<R1, E1>(io: IO<R1, E1, any>, __tsplusTrace?: string) {
|
|
1909
1824
|
};
|
1910
1825
|
}
|
1911
1826
|
|
1827
|
+
/**
|
1828
|
+
* Halts the evaluation of this stream when the provided promise resolves.
|
1829
|
+
*
|
1830
|
+
* If the promise completes with a failure, the stream will emit that failure.
|
1831
|
+
*
|
1832
|
+
* @tsplus pipeable fncts.io.Stream haltWhen
|
1833
|
+
*/
|
1834
|
+
export function haltWhenFuture<E1>(future: Future<E1, any>, __tsplusTrace?: string) {
|
1835
|
+
return <R, E, A>(fa: Stream<R, E, A>): Stream<R, E | E1, A> => {
|
1836
|
+
return new Stream(fa.channel.pipeTo(haltWhenFutureWriter(future)));
|
1837
|
+
};
|
1838
|
+
}
|
1839
|
+
|
1912
1840
|
function haltWhenFutureWriter<R, E, A, E1>(
|
1913
1841
|
future: Future<E1, unknown>,
|
1914
1842
|
__tsplusTrace?: string,
|
@@ -1928,17 +1856,23 @@ function haltWhenFutureWriter<R, E, A, E1>(
|
|
1928
1856
|
);
|
1929
1857
|
}
|
1930
1858
|
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1859
|
+
function haltWhenWriter<E, A, E1>(
|
1860
|
+
fiber: Fiber<E1, any>,
|
1861
|
+
__tsplusTrace?: string,
|
1862
|
+
): Channel<never, E | E1, Conc<A>, unknown, E | E1, Conc<A>, void> {
|
1863
|
+
return Channel.unwrap(
|
1864
|
+
fiber.poll.map((maybeExit) =>
|
1865
|
+
maybeExit.match(
|
1866
|
+
() =>
|
1867
|
+
Channel.readWith(
|
1868
|
+
(i: Conc<A>) => Channel.writeNow(i).zipRight(haltWhenWriter<E, A, E1>(fiber)),
|
1869
|
+
Channel.failNow,
|
1870
|
+
() => Channel.unit,
|
1871
|
+
),
|
1872
|
+
(exit) => exit.match(Channel.failCauseNow, () => Channel.unit),
|
1873
|
+
),
|
1874
|
+
),
|
1875
|
+
);
|
1942
1876
|
}
|
1943
1877
|
|
1944
1878
|
/**
|
@@ -1950,17 +1884,6 @@ export function interleave<R1, E1, B>(sb: Stream<R1, E1, B>, __tsplusTrace?: str
|
|
1950
1884
|
};
|
1951
1885
|
}
|
1952
1886
|
|
1953
|
-
function interleaveWithProducer<E, A>(
|
1954
|
-
handoff: Handoff<Take<E, A>>,
|
1955
|
-
__tsplusTrace?: string,
|
1956
|
-
): Channel<never, E, A, unknown, never, never, void> {
|
1957
|
-
return Channel.readWithCause(
|
1958
|
-
(value: A) => Channel.fromIO(handoff.offer(Take.single(value))).zipRight(interleaveWithProducer(handoff)),
|
1959
|
-
(cause) => Channel.fromIO(handoff.offer(Take.failCause(cause))),
|
1960
|
-
() => Channel.fromIO(handoff.offer(Take.end)),
|
1961
|
-
);
|
1962
|
-
}
|
1963
|
-
|
1964
1887
|
/**
|
1965
1888
|
* Combines this stream and the specified stream deterministically using the
|
1966
1889
|
* stream of boolean values `b` to control which stream to pull from next.
|
@@ -2018,6 +1941,53 @@ export function interleaveWith<R1, E1, B, R2, E2>(
|
|
2018
1941
|
};
|
2019
1942
|
}
|
2020
1943
|
|
1944
|
+
function interleaveWithProducer<E, A>(
|
1945
|
+
handoff: Handoff<Take<E, A>>,
|
1946
|
+
__tsplusTrace?: string,
|
1947
|
+
): Channel<never, E, A, unknown, never, never, void> {
|
1948
|
+
return Channel.readWithCause(
|
1949
|
+
(value: A) => Channel.fromIO(handoff.offer(Take.single(value))).zipRight(interleaveWithProducer(handoff)),
|
1950
|
+
(cause) => Channel.fromIO(handoff.offer(Take.failCause(cause))),
|
1951
|
+
() => Channel.fromIO(handoff.offer(Take.end)),
|
1952
|
+
);
|
1953
|
+
}
|
1954
|
+
|
1955
|
+
/**
|
1956
|
+
* Interrupts the evaluation of this stream when the provided IO completes. The given
|
1957
|
+
* IO will be forked as part of this stream, and its success will be discarded. This
|
1958
|
+
* combinator will also interrupt any in-progress element being pulled from upstream.
|
1959
|
+
*
|
1960
|
+
* If the IO completes with a failure before the stream completes, the returned stream
|
1961
|
+
* will emit that failure.
|
1962
|
+
*
|
1963
|
+
* @tsplus pipeable fncts.io.Stream interruptWhen
|
1964
|
+
*/
|
1965
|
+
export function interruptWhen<R1, E1>(io: IO<R1, E1, any>, __tsplusTrace?: string) {
|
1966
|
+
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, A> => {
|
1967
|
+
return new Stream(stream.channel.interruptWhen(io));
|
1968
|
+
};
|
1969
|
+
}
|
1970
|
+
|
1971
|
+
/**
|
1972
|
+
* @tsplus pipeable fncts.io.Stream interruptWhen
|
1973
|
+
*/
|
1974
|
+
export function interruptWhenFuture<E1>(future: Future<E1, unknown>, __tsplusTrace?: string) {
|
1975
|
+
return <R, E, A>(fa: Stream<R, E, A>): Stream<R, E | E1, A> => {
|
1976
|
+
return new Stream(fa.channel.interruptWhen(future));
|
1977
|
+
};
|
1978
|
+
}
|
1979
|
+
|
1980
|
+
/**
|
1981
|
+
* Intersperse stream with provided element
|
1982
|
+
*/
|
1983
|
+
export function intersperse<R, E, A, A1>(
|
1984
|
+
stream: Stream<R, E, A>,
|
1985
|
+
middle: A1,
|
1986
|
+
__tsplusTrace?: string,
|
1987
|
+
): Stream<R, E, A | A1> {
|
1988
|
+
return new Stream(stream.channel.pipeTo(intersperseWriter(middle, true)));
|
1989
|
+
}
|
1990
|
+
|
2021
1991
|
function intersperseWriter<R, E, A, A1>(
|
2022
1992
|
middle: A1,
|
2023
1993
|
isFirst: boolean,
|
@@ -2044,49 +2014,24 @@ function intersperseWriter<R, E, A, A1>(
|
|
2044
2014
|
}
|
2045
2015
|
|
2046
2016
|
/**
|
2047
|
-
*
|
2048
|
-
*/
|
2049
|
-
export function intersperse<R, E, A, A1>(
|
2050
|
-
stream: Stream<R, E, A>,
|
2051
|
-
middle: A1,
|
2052
|
-
__tsplusTrace?: string,
|
2053
|
-
): Stream<R, E, A | A1> {
|
2054
|
-
return new Stream(stream.channel.pipeTo(intersperseWriter(middle, true)));
|
2055
|
-
}
|
2056
|
-
|
2057
|
-
/**
|
2058
|
-
* Interrupts the evaluation of this stream when the provided IO completes. The given
|
2059
|
-
* IO will be forked as part of this stream, and its success will be discarded. This
|
2060
|
-
* combinator will also interrupt any in-progress element being pulled from upstream.
|
2061
|
-
*
|
2062
|
-
* If the IO completes with a failure before the stream completes, the returned stream
|
2063
|
-
* will emit that failure.
|
2017
|
+
* Transforms the elements of this stream using the supplied function.
|
2064
2018
|
*
|
2065
|
-
* @tsplus pipeable fncts.io.Stream
|
2066
|
-
*/
|
2067
|
-
export function interruptWhen<R1, E1>(io: IO<R1, E1, any>, __tsplusTrace?: string) {
|
2068
|
-
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, A> => {
|
2069
|
-
return new Stream(stream.channel.interruptWhen(io));
|
2070
|
-
};
|
2071
|
-
}
|
2072
|
-
|
2073
|
-
/**
|
2074
|
-
* @tsplus pipeable fncts.io.Stream interruptWhen
|
2019
|
+
* @tsplus pipeable fncts.io.Stream map
|
2075
2020
|
*/
|
2076
|
-
export function
|
2077
|
-
return <R, E
|
2078
|
-
return new Stream(
|
2021
|
+
export function map<A, B>(f: (o: A) => B, __tsplusTrace?: string) {
|
2022
|
+
return <R, E>(stream: Stream<R, E, A>): Stream<R, E, B> => {
|
2023
|
+
return new Stream(stream.channel.mapOut((as) => as.map(f)));
|
2079
2024
|
};
|
2080
2025
|
}
|
2081
2026
|
|
2082
2027
|
/**
|
2083
|
-
*
|
2028
|
+
* Statefully maps over the elements of this stream to produce new elements.
|
2084
2029
|
*
|
2085
|
-
* @tsplus pipeable fncts.io.Stream
|
2030
|
+
* @tsplus pipeable fncts.io.Stream mapAccum
|
2086
2031
|
*/
|
2087
|
-
export function
|
2032
|
+
export function mapAccum<A, S, B>(s: S, f: (s: S, a: A) => readonly [S, B], __tsplusTrace?: string) {
|
2088
2033
|
return <R, E>(stream: Stream<R, E, A>): Stream<R, E, B> => {
|
2089
|
-
return new Stream(stream.channel.
|
2034
|
+
return new Stream(stream.channel.pipeTo(mapAccumAccumulator(s, f)));
|
2090
2035
|
};
|
2091
2036
|
}
|
2092
2037
|
|
@@ -2106,13 +2051,18 @@ function mapAccumAccumulator<S, E = never, A = never, B = never>(
|
|
2106
2051
|
}
|
2107
2052
|
|
2108
2053
|
/**
|
2109
|
-
* Statefully maps over the elements of this stream to produce
|
2054
|
+
* Statefully and effectfully maps over the elements of this stream to produce
|
2055
|
+
* new elements.
|
2110
2056
|
*
|
2111
|
-
* @tsplus pipeable fncts.io.Stream
|
2057
|
+
* @tsplus pipeable fncts.io.Stream mapAccumIO
|
2112
2058
|
*/
|
2113
|
-
export function
|
2114
|
-
|
2115
|
-
|
2059
|
+
export function mapAccumIO<A, R1, E1, S, B>(
|
2060
|
+
s: S,
|
2061
|
+
f: (s: S, a: A) => IO<R1, E1, readonly [B, S]>,
|
2062
|
+
__tsplusTrace?: string,
|
2063
|
+
) {
|
2064
|
+
return <R, E>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, B> => {
|
2065
|
+
return new Stream(stream.channel.pipeTo(mapAccumIOAccumulator(s, f)));
|
2116
2066
|
};
|
2117
2067
|
}
|
2118
2068
|
|
@@ -2146,22 +2096,6 @@ function mapAccumIOAccumulator<R, E, A, R1, E1, S, B>(
|
|
2146
2096
|
);
|
2147
2097
|
}
|
2148
2098
|
|
2149
|
-
/**
|
2150
|
-
* Statefully and effectfully maps over the elements of this stream to produce
|
2151
|
-
* new elements.
|
2152
|
-
*
|
2153
|
-
* @tsplus pipeable fncts.io.Stream mapAccumIO
|
2154
|
-
*/
|
2155
|
-
export function mapAccumIO<A, R1, E1, S, B>(
|
2156
|
-
s: S,
|
2157
|
-
f: (s: S, a: A) => IO<R1, E1, readonly [B, S]>,
|
2158
|
-
__tsplusTrace?: string,
|
2159
|
-
) {
|
2160
|
-
return <R, E>(stream: Stream<R, E, A>): Stream<R | R1, E | E1, B> => {
|
2161
|
-
return new Stream(stream.channel.pipeTo(mapAccumIOAccumulator(s, f)));
|
2162
|
-
};
|
2163
|
-
}
|
2164
|
-
|
2165
2099
|
/**
|
2166
2100
|
* Transforms the chunks emitted by this stream.
|
2167
2101
|
*
|
@@ -2265,25 +2199,6 @@ export function mapIO<A, R1, E1, B>(f: (a: A) => IO<R1, E1, B>, __tsplusTrace?:
|
|
2265
2199
|
};
|
2266
2200
|
}
|
2267
2201
|
|
2268
|
-
function mapIOLoop<R, E, A, R1, E1, B>(
|
2269
|
-
iterator: Iterator<A>,
|
2270
|
-
f: (a: A) => IO<R1, E1, B>,
|
2271
|
-
__tsplusTrace?: string,
|
2272
|
-
): Channel<R | R1, E, Conc<A>, unknown, E | E1, Conc<B>, unknown> {
|
2273
|
-
const next = iterator.next();
|
2274
|
-
if (next.done) {
|
2275
|
-
return Channel.readWithCause(
|
2276
|
-
(elem) => mapIOLoop(elem[Symbol.iterator](), f),
|
2277
|
-
Channel.failCauseNow,
|
2278
|
-
Channel.succeedNow,
|
2279
|
-
);
|
2280
|
-
} else {
|
2281
|
-
return Channel.unwrap(
|
2282
|
-
f(next.value).map((b) => Channel.writeNow(Conc.single(b)) > mapIOLoop<R, E, A, R1, E1, B>(iterator, f)),
|
2283
|
-
);
|
2284
|
-
}
|
2285
|
-
}
|
2286
|
-
|
2287
2202
|
/**
|
2288
2203
|
* Maps over elements of the stream with the specified effectful function,
|
2289
2204
|
* executing up to `n` invocations of `f` concurrently. Transformed elements
|
@@ -2312,6 +2227,25 @@ export function mapIOConcurrentlyUnordered<A, R1, E1, B>(n: number, f: (a: A) =>
|
|
2312
2227
|
};
|
2313
2228
|
}
|
2314
2229
|
|
2230
|
+
function mapIOLoop<R, E, A, R1, E1, B>(
|
2231
|
+
iterator: Iterator<A>,
|
2232
|
+
f: (a: A) => IO<R1, E1, B>,
|
2233
|
+
__tsplusTrace?: string,
|
2234
|
+
): Channel<R | R1, E, Conc<A>, unknown, E | E1, Conc<B>, unknown> {
|
2235
|
+
const next = iterator.next();
|
2236
|
+
if (next.done) {
|
2237
|
+
return Channel.readWithCause(
|
2238
|
+
(elem) => mapIOLoop(elem[Symbol.iterator](), f),
|
2239
|
+
Channel.failCauseNow,
|
2240
|
+
Channel.succeedNow,
|
2241
|
+
);
|
2242
|
+
} else {
|
2243
|
+
return Channel.unwrap(
|
2244
|
+
f(next.value).map((b) => Channel.writeNow(Conc.single(b)) > mapIOLoop<R, E, A, R1, E1, B>(iterator, f)),
|
2245
|
+
);
|
2246
|
+
}
|
2247
|
+
}
|
2248
|
+
|
2315
2249
|
/**
|
2316
2250
|
* Merges this stream and the specified stream together.
|
2317
2251
|
*
|
@@ -2330,6 +2264,15 @@ export function merge<R1, E1, B>(
|
|
2330
2264
|
};
|
2331
2265
|
}
|
2332
2266
|
|
2267
|
+
/**
|
2268
|
+
* @tsplus pipeable fncts.io.Stream mergeEither
|
2269
|
+
*/
|
2270
|
+
export function mergeEither<R1, E1, B>(fb: Stream<R1, E1, B>, __tsplusTrace?: string) {
|
2271
|
+
return <R, E, A>(fa: Stream<R, E, A>): Stream<R | R1, E | E1, Either<A, B>> => {
|
2272
|
+
return fa.mergeWith(fb, Either.left, Either.right);
|
2273
|
+
};
|
2274
|
+
}
|
2275
|
+
|
2333
2276
|
/**
|
2334
2277
|
* Merges this stream and the specified stream together. New produced stream
|
2335
2278
|
* will terminate when either stream terminates.
|
@@ -2378,18 +2321,6 @@ export function mergeLeft<R1, E1, B>(that: Stream<R1, E1, B>, __tsplusTrace?: st
|
|
2378
2321
|
};
|
2379
2322
|
}
|
2380
2323
|
|
2381
|
-
/**
|
2382
|
-
* Merges this stream and the specified stream together, discarding the values
|
2383
|
-
* from the left stream.
|
2384
|
-
*
|
2385
|
-
* @tsplus pipeable fncts.io.Stream mergeRight
|
2386
|
-
*/
|
2387
|
-
export function mergeRight<R1, E1, B>(that: Stream<R1, E1, B>, __tsplusTrace?: string) {
|
2388
|
-
return <R, E, A>(self: Stream<R, E, A>): Stream<R | R1, E | E1, B> => {
|
2389
|
-
return self.drain.merge(that);
|
2390
|
-
};
|
2391
|
-
}
|
2392
|
-
|
2393
2324
|
/**
|
2394
2325
|
* Maps each element of this stream to another stream and returns the
|
2395
2326
|
* non-deterministic merge of those streams, executing up to `n` inner streams
|
@@ -2428,24 +2359,17 @@ export function mergeMapIO<A, R1, E1, B>(
|
|
2428
2359
|
}
|
2429
2360
|
|
2430
2361
|
/**
|
2431
|
-
*
|
2362
|
+
* Merges this stream and the specified stream together, discarding the values
|
2363
|
+
* from the left stream.
|
2364
|
+
*
|
2365
|
+
* @tsplus pipeable fncts.io.Stream mergeRight
|
2432
2366
|
*/
|
2433
|
-
export function
|
2434
|
-
return <R, E, A>(
|
2435
|
-
return
|
2367
|
+
export function mergeRight<R1, E1, B>(that: Stream<R1, E1, B>, __tsplusTrace?: string) {
|
2368
|
+
return <R, E, A>(self: Stream<R, E, A>): Stream<R | R1, E | E1, B> => {
|
2369
|
+
return self.drain.merge(that);
|
2436
2370
|
};
|
2437
2371
|
}
|
2438
2372
|
|
2439
|
-
function mergeWithHandler<R, E>(
|
2440
|
-
terminate: boolean,
|
2441
|
-
__tsplusTrace?: string,
|
2442
|
-
): (exit: Exit<E, unknown>) => MergeDecision<R, E, unknown, E, unknown> {
|
2443
|
-
return (exit) =>
|
2444
|
-
terminate || !exit.isSuccess() ? MergeDecision.Done(IO.fromExitNow(exit)) : MergeDecision.Await(IO.fromExitNow);
|
2445
|
-
}
|
2446
|
-
|
2447
|
-
export type TerminationStrategy = "Left" | "Right" | "Both" | "Either";
|
2448
|
-
|
2449
2373
|
/**
|
2450
2374
|
* @tsplus pipeable fncts.io.Stream mergeWith
|
2451
2375
|
*/
|
@@ -2469,6 +2393,14 @@ export function mergeWith<A, R1, E1, A1, B, C>(
|
|
2469
2393
|
};
|
2470
2394
|
}
|
2471
2395
|
|
2396
|
+
function mergeWithHandler<R, E>(
|
2397
|
+
terminate: boolean,
|
2398
|
+
__tsplusTrace?: string,
|
2399
|
+
): (exit: Exit<E, unknown>) => MergeDecision<R, E, unknown, E, unknown> {
|
2400
|
+
return (exit) =>
|
2401
|
+
terminate || !exit.isSuccess() ? MergeDecision.Done(IO.fromExitNow(exit)) : MergeDecision.Await(IO.fromExitNow);
|
2402
|
+
}
|
2403
|
+
|
2472
2404
|
/**
|
2473
2405
|
* Runs the specified effect if this stream fails, providing the error to the effect if it exists.
|
2474
2406
|
*
|
@@ -2599,6 +2531,19 @@ export function provideSomeLayer<RIn, E1, ROut>(layer: Layer<RIn, E1, ROut>, __t
|
|
2599
2531
|
};
|
2600
2532
|
}
|
2601
2533
|
|
2534
|
+
/**
|
2535
|
+
* Re-chunks the elements of the stream into chunks of
|
2536
|
+
* `n` elements each.
|
2537
|
+
* The last chunk might contain less than `n` elements
|
2538
|
+
*
|
2539
|
+
* @tsplus pipeable fncts.io.Stream rechunk
|
2540
|
+
*/
|
2541
|
+
export function rechunk(n: number, __tsplusTrace?: string) {
|
2542
|
+
return <R, E, A>(stream: Stream<R, E, A>): Stream<R, E, A> => {
|
2543
|
+
return new Stream(stream.channel.pipeTo(rechunkProcess(new Rechunker(n), n)));
|
2544
|
+
};
|
2545
|
+
}
|
2546
|
+
|
2602
2547
|
class Rechunker<A> {
|
2603
2548
|
private builder: Array<A> = [];
|
2604
2549
|
private pos = 0;
|
@@ -2659,28 +2604,6 @@ function rechunkProcess<E, In>(
|
|
2659
2604
|
);
|
2660
2605
|
}
|
2661
2606
|
|
2662
|
-
/**
|
2663
|
-
* Re-chunks the elements of the stream into chunks of
|
2664
|
-
* `n` elements each.
|
2665
|
-
* The last chunk might contain less than `n` elements
|
2666
|
-
*
|
2667
|
-
* @tsplus pipeable fncts.io.Stream rechunk
|
2668
|
-
*/
|
2669
|
-
export function rechunk(n: number, __tsplusTrace?: string) {
|
2670
|
-
return <R, E, A>(stream: Stream<R, E, A>): Stream<R, E, A> => {
|
2671
|
-
return new Stream(stream.channel.pipeTo(rechunkProcess(new Rechunker(n), n)));
|
2672
|
-
};
|
2673
|
-
}
|
2674
|
-
|
2675
|
-
/**
|
2676
|
-
* Repeats the provided value infinitely.
|
2677
|
-
*
|
2678
|
-
* @tsplus static fncts.io.StreamOps repeatValue
|
2679
|
-
*/
|
2680
|
-
export function repeatValue<A>(a: A, __tsplusTrace?: string): Stream<unknown, never, A> {
|
2681
|
-
return new Stream(Channel.writeNow(Conc.single(a)).repeated);
|
2682
|
-
}
|
2683
|
-
|
2684
2607
|
/**
|
2685
2608
|
* Creates a stream from an effect producing a value of type `A` which repeats forever.
|
2686
2609
|
*
|
@@ -2690,15 +2613,6 @@ export function repeatIO<R, E, A>(fa: IO<R, E, A>, __tsplusTrace?: string): Stre
|
|
2690
2613
|
return Stream.repeatIOMaybe(fa.mapError(Maybe.just));
|
2691
2614
|
}
|
2692
2615
|
|
2693
|
-
/**
|
2694
|
-
* Creates a stream from an effect producing values of type `A` until it fails with None.
|
2695
|
-
*
|
2696
|
-
* @tsplus static fncts.io.StreamOps repeatIOMaybe
|
2697
|
-
*/
|
2698
|
-
export function repeatIOMaybe<R, E, A>(fa: IO<R, Maybe<E>, A>, __tsplusTrace?: string): Stream<R, E, A> {
|
2699
|
-
return repeatIOChunkMaybe(fa.map(Conc.single));
|
2700
|
-
}
|
2701
|
-
|
2702
2616
|
/**
|
2703
2617
|
* Creates a stream from an effect producing chunks of `A` values which repeats forever.
|
2704
2618
|
*
|
@@ -2721,6 +2635,24 @@ export function repeatIOChunkMaybe<R, E, A>(fa: IO<R, Maybe<E>, Conc<A>>, __tspl
|
|
2721
2635
|
);
|
2722
2636
|
}
|
2723
2637
|
|
2638
|
+
/**
|
2639
|
+
* Creates a stream from an effect producing values of type `A` until it fails with None.
|
2640
|
+
*
|
2641
|
+
* @tsplus static fncts.io.StreamOps repeatIOMaybe
|
2642
|
+
*/
|
2643
|
+
export function repeatIOMaybe<R, E, A>(fa: IO<R, Maybe<E>, A>, __tsplusTrace?: string): Stream<R, E, A> {
|
2644
|
+
return repeatIOChunkMaybe(fa.map(Conc.single));
|
2645
|
+
}
|
2646
|
+
|
2647
|
+
/**
|
2648
|
+
* Repeats the provided value infinitely.
|
2649
|
+
*
|
2650
|
+
* @tsplus static fncts.io.StreamOps repeatValue
|
2651
|
+
*/
|
2652
|
+
export function repeatValue<A>(a: A, __tsplusTrace?: string): Stream<unknown, never, A> {
|
2653
|
+
return new Stream(Channel.writeNow(Conc.single(a)).repeated);
|
2654
|
+
}
|
2655
|
+
|
2724
2656
|
/**
|
2725
2657
|
* Runs the sink on the stream to produce either the sink's result or an error.
|
2726
2658
|
*
|
@@ -2786,22 +2718,17 @@ export function runIntoElementsScoped_<E, A, R1, E1>(
|
|
2786
2718
|
}
|
2787
2719
|
|
2788
2720
|
/**
|
2789
|
-
* Like `Stream#
|
2721
|
+
* Like `Stream#runIntoHub`, but provides the result as a `Managed` to allow for scope
|
2790
2722
|
* composition.
|
2791
2723
|
*
|
2792
|
-
* @tsplus pipeable fncts.io.Stream
|
2724
|
+
* @tsplus pipeable fncts.io.Stream runIntoHubScoped
|
2793
2725
|
*/
|
2794
|
-
export function
|
2795
|
-
|
2726
|
+
export function runIntoHubScoped<RA, RB, EA, EB, E1, A, B>(
|
2727
|
+
hub: PHub<RA, RB, EA, EB, Take<E1, A>, B>,
|
2796
2728
|
__tsplusTrace?: string,
|
2797
2729
|
) {
|
2798
2730
|
return <R, E extends E1>(stream: Stream<R, E, A>): IO<R | RA | Scope, E | EA | E1, void> => {
|
2799
|
-
|
2800
|
-
(inp) => Channel.writeNow(Take.chunk(inp)).zipRight(writer),
|
2801
|
-
(cause) => Channel.writeNow(Take.failCause(cause)),
|
2802
|
-
(_) => Channel.writeNow(Take.end),
|
2803
|
-
);
|
2804
|
-
return stream.channel.pipeTo(writer).mapOutIO((take) => queue.offer(take)).drain.runScoped.asUnit;
|
2731
|
+
return stream.runIntoQueueScoped(hub);
|
2805
2732
|
};
|
2806
2733
|
}
|
2807
2734
|
|
@@ -2827,17 +2754,22 @@ export function runIntoQueueElementsScoped<E, A>(queue: Lazy<Queue.Enqueue<Exit<
|
|
2827
2754
|
}
|
2828
2755
|
|
2829
2756
|
/**
|
2830
|
-
* Like `Stream#
|
2757
|
+
* Like `Stream#into`, but provides the result as a `Managed` to allow for scope
|
2831
2758
|
* composition.
|
2832
2759
|
*
|
2833
|
-
* @tsplus pipeable fncts.io.Stream
|
2760
|
+
* @tsplus pipeable fncts.io.Stream runIntoQueueScoped
|
2834
2761
|
*/
|
2835
|
-
export function
|
2836
|
-
|
2762
|
+
export function runIntoQueueScoped<RA, RB, EA, EB, E1, A, B>(
|
2763
|
+
queue: PEnqueue<RA, RB, EA, EB, Take<E1, A>, B>,
|
2837
2764
|
__tsplusTrace?: string,
|
2838
2765
|
) {
|
2839
2766
|
return <R, E extends E1>(stream: Stream<R, E, A>): IO<R | RA | Scope, E | EA | E1, void> => {
|
2840
|
-
|
2767
|
+
const writer: Channel<R, E, Conc<A>, unknown, E, Take<E | E1, A>, any> = Channel.readWithCause(
|
2768
|
+
(inp) => Channel.writeNow(Take.chunk(inp)).zipRight(writer),
|
2769
|
+
(cause) => Channel.writeNow(Take.failCause(cause)),
|
2770
|
+
(_) => Channel.writeNow(Take.end),
|
2771
|
+
);
|
2772
|
+
return stream.channel.pipeTo(writer).mapOutIO((take) => queue.offer(take)).drain.runScoped.asUnit;
|
2841
2773
|
};
|
2842
2774
|
}
|
2843
2775
|
|
@@ -2905,6 +2837,74 @@ export function scanReduceIO<A extends B, R1, E1, B>(f: (b: B, a: A) => IO<R1, E
|
|
2905
2837
|
};
|
2906
2838
|
}
|
2907
2839
|
|
2840
|
+
/**
|
2841
|
+
* Creates a single-valued stream from a managed resource
|
2842
|
+
*
|
2843
|
+
* @tsplus static fncts.io.StreamOps scoped
|
2844
|
+
*/
|
2845
|
+
export function scoped<R, E, A>(stream: Lazy<IO<R, E, A>>, __tsplusTrace?: string): Stream<Exclude<R, Scope>, E, A> {
|
2846
|
+
return new Stream(Channel.scoped(stream().map(Conc.single)));
|
2847
|
+
}
|
2848
|
+
|
2849
|
+
/**
|
2850
|
+
* Emits a sliding window of n elements.
|
2851
|
+
*
|
2852
|
+
* @tsplus pipeable fncts.io.Stream sliding
|
2853
|
+
*/
|
2854
|
+
export function sliding(chunkSize: number, stepSize: number, __tsplusTrace?: string) {
|
2855
|
+
return <R, E, A>(self: Stream<R, E, A>): Stream<R, E, Conc<A>> => {
|
2856
|
+
return Stream.defer(() => {
|
2857
|
+
function slidingChunk(chunk: Conc<A>, input: Conc<A>): [Conc<A>, Conc<Conc<A>>] {
|
2858
|
+
const updatedChunk = chunk.concat(input);
|
2859
|
+
const length = updatedChunk.length;
|
2860
|
+
if (length >= chunkSize) {
|
2861
|
+
const array = new Array<Conc<A>>((length - chunkSize) / stepSize + 1);
|
2862
|
+
let arrayIndex = 0;
|
2863
|
+
let chunkIndex = 0;
|
2864
|
+
while (chunkIndex + chunkSize <= length) {
|
2865
|
+
array[arrayIndex] = updatedChunk.slice(chunkIndex, chunkIndex + chunkSize);
|
2866
|
+
arrayIndex += 1;
|
2867
|
+
chunkIndex += stepSize;
|
2868
|
+
}
|
2869
|
+
return [updatedChunk.drop(chunkIndex), Conc.fromArray(array)];
|
2870
|
+
} else {
|
2871
|
+
return [updatedChunk, Conc.empty()];
|
2872
|
+
}
|
2873
|
+
}
|
2874
|
+
function sliding(chunk: Conc<A>, written: boolean): Channel<never, E, Conc<A>, any, E, Conc<Conc<A>>, any> {
|
2875
|
+
return Channel.readWithCause(
|
2876
|
+
(input) => {
|
2877
|
+
const [updatedChunk, out] = slidingChunk(chunk, input);
|
2878
|
+
if (out.isEmpty) {
|
2879
|
+
return sliding(updatedChunk, written);
|
2880
|
+
} else {
|
2881
|
+
return Channel.writeNow(out) > sliding(updatedChunk, true);
|
2882
|
+
}
|
2883
|
+
},
|
2884
|
+
(err) => {
|
2885
|
+
const index = written && chunkSize > stepSize ? chunkSize - stepSize : 0;
|
2886
|
+
if (index >= chunk.length) {
|
2887
|
+
return Channel.failCauseNow(err);
|
2888
|
+
} else {
|
2889
|
+
return Channel.writeNow(Conc.single(chunk)) > Channel.failCauseNow(err);
|
2890
|
+
}
|
2891
|
+
},
|
2892
|
+
(done) => {
|
2893
|
+
const index = written && chunkSize > stepSize ? chunkSize - stepSize : 0;
|
2894
|
+
if (index >= chunk.length) {
|
2895
|
+
return Channel.succeedNow(done);
|
2896
|
+
} else {
|
2897
|
+
return Channel.writeNow(Conc.single(chunk)) > Channel.succeedNow(done);
|
2898
|
+
}
|
2899
|
+
},
|
2900
|
+
);
|
2901
|
+
}
|
2902
|
+
|
2903
|
+
return new Stream(self.channel >>> sliding(Conc.empty(), false));
|
2904
|
+
});
|
2905
|
+
};
|
2906
|
+
}
|
2907
|
+
|
2908
2908
|
/**
|
2909
2909
|
* @tsplus pipeable fncts.io.Stream split
|
2910
2910
|
*/
|
@@ -2939,6 +2939,15 @@ export function split<A>(predicate: Predicate<A>, __tsplusTrace?: string) {
|
|
2939
2939
|
};
|
2940
2940
|
}
|
2941
2941
|
|
2942
|
+
/**
|
2943
|
+
* Creates a single-valued pure stream
|
2944
|
+
*
|
2945
|
+
* @tsplus static fncts.io.StreamOps succeed
|
2946
|
+
*/
|
2947
|
+
export function succeed<A>(a: Lazy<A>, __tsplusTrace?: string): Stream<never, never, A> {
|
2948
|
+
return fromChunk(Conc.single(a()));
|
2949
|
+
}
|
2950
|
+
|
2942
2951
|
/**
|
2943
2952
|
* Creates a single-valued pure stream
|
2944
2953
|
*
|
@@ -2949,12 +2958,20 @@ export function succeedNow<O>(o: O, __tsplusTrace?: string): Stream<never, never
|
|
2949
2958
|
}
|
2950
2959
|
|
2951
2960
|
/**
|
2952
|
-
*
|
2961
|
+
* Takes the specified number of elements from this stream.
|
2953
2962
|
*
|
2954
|
-
* @tsplus
|
2963
|
+
* @tsplus pipeable fncts.io.Stream take
|
2955
2964
|
*/
|
2956
|
-
export function
|
2957
|
-
return
|
2965
|
+
export function take(n: number, __tsplusTrace?: string) {
|
2966
|
+
return <R, E, A>(stream: Stream<R, E, A>): Stream<R, E, A> => {
|
2967
|
+
if (n <= 0) {
|
2968
|
+
return empty;
|
2969
|
+
}
|
2970
|
+
if (!Number.isInteger(n)) {
|
2971
|
+
return halt(new IllegalArgumentError(`${n} should be an integer`, "Stream.take"));
|
2972
|
+
}
|
2973
|
+
return new Stream(stream.channel.pipeTo(takeLoop(n)));
|
2974
|
+
};
|
2958
2975
|
}
|
2959
2976
|
|
2960
2977
|
function takeLoop<E, A>(n: number, __tsplusTrace?: string): Channel<never, E, Conc<A>, unknown, E, Conc<A>, unknown> {
|
@@ -2974,19 +2991,14 @@ function takeLoop<E, A>(n: number, __tsplusTrace?: string): Channel<never, E, Co
|
|
2974
2991
|
}
|
2975
2992
|
|
2976
2993
|
/**
|
2977
|
-
* Takes the
|
2994
|
+
* Takes all elements of the stream until the specified predicate evaluates
|
2995
|
+
* to `true`.
|
2978
2996
|
*
|
2979
|
-
* @tsplus pipeable fncts.io.Stream
|
2997
|
+
* @tsplus pipeable fncts.io.Stream takeUntil
|
2980
2998
|
*/
|
2981
|
-
export function
|
2982
|
-
return <R, E
|
2983
|
-
|
2984
|
-
return empty;
|
2985
|
-
}
|
2986
|
-
if (!Number.isInteger(n)) {
|
2987
|
-
return halt(new IllegalArgumentError(`${n} should be an integer`, "Stream.take"));
|
2988
|
-
}
|
2989
|
-
return new Stream(stream.channel.pipeTo(takeLoop(n)));
|
2999
|
+
export function takeUntil<A>(p: Predicate<A>, __tsplusTrace?: string) {
|
3000
|
+
return <R, E>(fa: Stream<R, E, A>): Stream<R, E, A> => {
|
3001
|
+
return new Stream(fa.channel.pipeTo(takeUntilLoop(p)));
|
2990
3002
|
};
|
2991
3003
|
}
|
2992
3004
|
|
@@ -3041,18 +3053,6 @@ function takeUntilLoop<R, E, A>(
|
|
3041
3053
|
);
|
3042
3054
|
}
|
3043
3055
|
|
3044
|
-
/**
|
3045
|
-
* Takes all elements of the stream until the specified predicate evaluates
|
3046
|
-
* to `true`.
|
3047
|
-
*
|
3048
|
-
* @tsplus pipeable fncts.io.Stream takeUntil
|
3049
|
-
*/
|
3050
|
-
export function takeUntil<A>(p: Predicate<A>, __tsplusTrace?: string) {
|
3051
|
-
return <R, E>(fa: Stream<R, E, A>): Stream<R, E, A> => {
|
3052
|
-
return new Stream(fa.channel.pipeTo(takeUntilLoop(p)));
|
3053
|
-
};
|
3054
|
-
}
|
3055
|
-
|
3056
3056
|
/**
|
3057
3057
|
* @tsplus pipeable fncts.io.Stream tap
|
3058
3058
|
*/
|
@@ -3146,6 +3146,30 @@ export function throttleEnforce<A>(
|
|
3146
3146
|
};
|
3147
3147
|
}
|
3148
3148
|
|
3149
|
+
/**
|
3150
|
+
* Throttles the chunks of this stream according to the given bandwidth parameters using the token bucket
|
3151
|
+
* algorithm. Allows for burst in the processing of elements by allowing the token bucket to accumulate
|
3152
|
+
* tokens up to a `units + burst` threshold. Chunks that do not meet the bandwidth constraints are dropped.
|
3153
|
+
* The weight of each chunk is determined by the `costFn` effectful function.
|
3154
|
+
*
|
3155
|
+
* @tsplus pipeable fncts.io.Stream throttleEnforceIO
|
3156
|
+
*/
|
3157
|
+
export function throttleEnforceIO<A, R1, E1>(
|
3158
|
+
costFn: (chunk: Conc<A>) => IO<R1, E1, number>,
|
3159
|
+
units: number,
|
3160
|
+
duration: number,
|
3161
|
+
burst = 0,
|
3162
|
+
__tsplusTrace?: string,
|
3163
|
+
) {
|
3164
|
+
return <R, E>(sa: Stream<R, E, A>): Stream<R | R1, E | E1, A> => {
|
3165
|
+
return new Stream(
|
3166
|
+
Channel.fromIO(Clock.currentTime).flatMap((current) =>
|
3167
|
+
sa.channel.pipeTo(throttleEnforceIOLoop(costFn, units, duration, burst, units, current)),
|
3168
|
+
),
|
3169
|
+
);
|
3170
|
+
};
|
3171
|
+
}
|
3172
|
+
|
3149
3173
|
function throttleEnforceIOLoop<E, A, R1, E1>(
|
3150
3174
|
costFn: (chunk: Conc<A>) => IO<R1, E1, number>,
|
3151
3175
|
units: number,
|
@@ -3178,30 +3202,6 @@ function throttleEnforceIOLoop<E, A, R1, E1>(
|
|
3178
3202
|
);
|
3179
3203
|
}
|
3180
3204
|
|
3181
|
-
/**
|
3182
|
-
* Throttles the chunks of this stream according to the given bandwidth parameters using the token bucket
|
3183
|
-
* algorithm. Allows for burst in the processing of elements by allowing the token bucket to accumulate
|
3184
|
-
* tokens up to a `units + burst` threshold. Chunks that do not meet the bandwidth constraints are dropped.
|
3185
|
-
* The weight of each chunk is determined by the `costFn` effectful function.
|
3186
|
-
*
|
3187
|
-
* @tsplus pipeable fncts.io.Stream throttleEnforceIO
|
3188
|
-
*/
|
3189
|
-
export function throttleEnforceIO<A, R1, E1>(
|
3190
|
-
costFn: (chunk: Conc<A>) => IO<R1, E1, number>,
|
3191
|
-
units: number,
|
3192
|
-
duration: number,
|
3193
|
-
burst = 0,
|
3194
|
-
__tsplusTrace?: string,
|
3195
|
-
) {
|
3196
|
-
return <R, E>(sa: Stream<R, E, A>): Stream<R | R1, E | E1, A> => {
|
3197
|
-
return new Stream(
|
3198
|
-
Channel.fromIO(Clock.currentTime).flatMap((current) =>
|
3199
|
-
sa.channel.pipeTo(throttleEnforceIOLoop(costFn, units, duration, burst, units, current)),
|
3200
|
-
),
|
3201
|
-
);
|
3202
|
-
};
|
3203
|
-
}
|
3204
|
-
|
3205
3205
|
/**
|
3206
3206
|
* Converts the stream to a managed hub of chunks. After the managed hub is used,
|
3207
3207
|
* the hub will never again produce values and should be discarded.
|
@@ -3339,19 +3339,26 @@ export function toReadableStream<E, A>(self: Stream<never, E, A>, __tsplusTrace?
|
|
3339
3339
|
});
|
3340
3340
|
}
|
3341
3341
|
|
3342
|
-
|
3342
|
+
/**
|
3343
|
+
* @tsplus static fncts.io.StreamOps unfold
|
3344
|
+
*/
|
3345
|
+
export function unfold<S, A>(
|
3343
3346
|
s: S,
|
3344
|
-
f: (s: S) =>
|
3347
|
+
f: (s: S) => Maybe<readonly [A, S]>,
|
3345
3348
|
__tsplusTrace?: string,
|
3346
|
-
):
|
3347
|
-
return
|
3348
|
-
|
3349
|
-
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3349
|
+
): Stream<never, never, A> {
|
3350
|
+
return Stream.unfoldChunk(s, (s) => f(s).map(([a, s]) => tuple(Conc.single(a), s)));
|
3351
|
+
}
|
3352
|
+
|
3353
|
+
/**
|
3354
|
+
* @tsplus static fncts.io.StreamOps unfoldChunk
|
3355
|
+
*/
|
3356
|
+
export function unfoldChunk<S, A>(
|
3357
|
+
s: S,
|
3358
|
+
f: (s: S) => Maybe<readonly [Conc<A>, S]>,
|
3359
|
+
__tsplusTrace?: string,
|
3360
|
+
): Stream<never, never, A> {
|
3361
|
+
return new Stream(Channel.defer(unfoldChunkLoop(s, f)));
|
3355
3362
|
}
|
3356
3363
|
|
3357
3364
|
/**
|
@@ -3367,17 +3374,19 @@ export function unfoldChunkIO<R, E, A, S>(
|
|
3367
3374
|
return new Stream(unfoldChunkIOLoop(s, f));
|
3368
3375
|
}
|
3369
3376
|
|
3370
|
-
|
3371
|
-
* Creates a stream by effectfully peeling off the "layers" of a value of type `S`
|
3372
|
-
*
|
3373
|
-
* @tsplus static fncts.io.StreamOps unfoldIO
|
3374
|
-
*/
|
3375
|
-
export function unfoldIO<S, R, E, A>(
|
3377
|
+
function unfoldChunkIOLoop<S, R, E, A>(
|
3376
3378
|
s: S,
|
3377
|
-
f: (s: S) => IO<R, E, Maybe<readonly [A
|
3379
|
+
f: (s: S) => IO<R, E, Maybe<readonly [Conc<A>, S]>>,
|
3378
3380
|
__tsplusTrace?: string,
|
3379
|
-
):
|
3380
|
-
return
|
3381
|
+
): Channel<R, unknown, unknown, unknown, E, Conc<A>, unknown> {
|
3382
|
+
return Channel.unwrap(
|
3383
|
+
f(s).map((m) =>
|
3384
|
+
m.match(
|
3385
|
+
() => Channel.unit,
|
3386
|
+
([as, s]) => Channel.writeNow(as).flatMap(() => unfoldChunkIOLoop(s, f)),
|
3387
|
+
),
|
3388
|
+
),
|
3389
|
+
);
|
3381
3390
|
}
|
3382
3391
|
|
3383
3392
|
function unfoldChunkLoop<S, A>(
|
@@ -3392,25 +3401,16 @@ function unfoldChunkLoop<S, A>(
|
|
3392
3401
|
}
|
3393
3402
|
|
3394
3403
|
/**
|
3395
|
-
*
|
3396
|
-
|
3397
|
-
|
3398
|
-
s: S,
|
3399
|
-
f: (s: S) => Maybe<readonly [Conc<A>, S]>,
|
3400
|
-
__tsplusTrace?: string,
|
3401
|
-
): Stream<never, never, A> {
|
3402
|
-
return new Stream(Channel.defer(unfoldChunkLoop(s, f)));
|
3403
|
-
}
|
3404
|
-
|
3405
|
-
/**
|
3406
|
-
* @tsplus static fncts.io.StreamOps unfold
|
3404
|
+
* Creates a stream by effectfully peeling off the "layers" of a value of type `S`
|
3405
|
+
*
|
3406
|
+
* @tsplus static fncts.io.StreamOps unfoldIO
|
3407
3407
|
*/
|
3408
|
-
export function
|
3408
|
+
export function unfoldIO<S, R, E, A>(
|
3409
3409
|
s: S,
|
3410
|
-
f: (s: S) => Maybe<readonly [A, S]
|
3410
|
+
f: (s: S) => IO<R, E, Maybe<readonly [A, S]>>,
|
3411
3411
|
__tsplusTrace?: string,
|
3412
|
-
): Stream<
|
3413
|
-
return
|
3412
|
+
): Stream<R, E, A> {
|
3413
|
+
return unfoldChunkIO(s, (_) => f(_).map((m) => m.map(([a, s]) => tuple(Conc.single(a), s))));
|
3414
3414
|
}
|
3415
3415
|
|
3416
3416
|
/**
|