fromObservable turns an RxJS Observable into an Effect Stream. Values, errors and completion map onto the stream's elements, typed failure and end, and the source is unsubscribed when the stream stops early.
Use it when RxJS code feeds an Effect pipeline.
import { fromObservable } from '@systemfsoftware/rx-effect'
import { Effect, Stream } from 'effect'
import { interval } from 'rxjs'
const ticks = fromObservable((error) => String(error))(interval(10)).pipe(Stream.take(2))
Effect.runPromise(Stream.runCollect(ticks)).then(console.log)
// [ 0, 1 ]fromObservable takes the error mapper first and returns a function that takes the Observable. The mapper runs only when the Observable errors, and its result becomes the stream's typed failure.
pnpm add @systemfsoftware/rx-effect effect@^4 rxjs@^7effect and rxjs are peer dependencies: this package declares them but does not install them, so one copy is shared with the rest of your project.
fromObservable<E>(onError: (error: unknown) => E): <A>(observable: Observable<A>) => Stream<A, E>The whole implementation is in FromObservable.ts.
- Each
nextvalue becomes a stream element, in the order it arrives. completeends the stream. An Observable that completes without emitting gives an empty stream.errorfails the stream with the valueonErrorreturns.- Stopping the stream early, for example with
Stream.take, unsubscribes the source once.
The bridge does not apply backpressure. It never pauses the Observable: values the stream has not read yet wait in an unbounded queue. A synchronous source that emits 10,000 values before the reader starts delivers all 10,000.
Development setup and workflow are in CONTRIBUTING.md.
Report bugs and ask questions in the issue tracker.