gcanti / fp-ts-rxjs

fp-ts bindings for RxJS
https://gcanti.github.io/fp-ts-rxjs/
MIT License
187 stars 29 forks source link

add liftOperator #42

Closed anthonyjoeseph closed 3 years ago

anthonyjoeseph commented 3 years ago

Closes https://github.com/gcanti/fp-ts-rxjs/issues/39

First draft of a liftOperator function that lifts a function from

Observable<A> => Observable<B> 

(a.k.a. OperatorFunction<A, B>)

to a function

ObservableEither<E, A> => ObservableEither<E, B>

This allows rxjs operators to be used on an ObservableEither.

This has been implemented for ReaderObservableEither & StateReaderObservableEither as well.

I would call this experimental. I have not used it in production a ton, and even changed the implementation while writing this PR (I realized the need for a takeUntil).

I am also not sure how this fits in with the ethos of the fp-ts-rxjs library. liftOperator allows for operators like scan and tap, which are impure at heart. Its implementation uses Subjects which are inherently imperative. Though I love rxjs and it's utility, I'm not sure if usefulness is a priority over purity for this lib.

I have been comfortable using this in production as it's relatively simple, but I would be willing to release this as a separate npm package if that would be better.

anthonyjoeseph commented 3 years ago

Whoops! I accidentally removed Lazy from some of the docs. I'll figure that out

anthonyjoeseph commented 3 years ago

In case it feels strange to instantiate a Subject and call subscribe inside an operator, the implementation of groupBy does something similar.

In a way, liftOperator is doing a groupBy and then reversing it. We want to operate over a subset of our source Observable while only subscribing to it once.

anthonyjoeseph commented 3 years ago

replaced by https://github.com/gcanti/fp-ts-rxjs/pull/47