gcanti / fp-ts-rxjs

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

Add `liftEither` for `ObservableEither` #38

Closed agabriele-radius closed 3 years ago

agabriele-radius commented 3 years ago

I often end up needing a way to use MonoTypeOperatorFunction's on the right case of ObservableEither's

E.g. filter or takeUntil for ObservableEither

export const liftEither = <E, A, B>(
  f: (a: r.Observable<A>) => r.Observable<B>
): ((a: OBE.ObservableEither<E, A>) => OBE.ObservableEither<E, B>) =>
  flow(
    OB.separate,
    ({left, right}: {left: r.Observable<Err>; right: r.Observable<A>}) =>
      r.merge(pipe(left, ro.map(E.left)), pipe(right, f, ro.map(E.right)))
  )

I can make a P.R. if desired, but I'm not sure if this is the best way to do this.

anthonyjoeseph commented 3 years ago

whoops wrong github acct