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 chainW #41

Closed anthonyjoeseph closed 3 years ago

anthonyjoeseph commented 3 years ago

closes https://github.com/gcanti/fp-ts-rxjs/issues/37

Based on the new fp-ts 3.0.0 chainW signatures

Not sure if this is desired. Ideally, chain would be implemented in terms of chainW, not the other way around. This is because the Observable* modules still use pipeable, which seems to be on the way out.

Also, I didn't implement any tests for chainW, since it seems to be the convention that a test for chain is good enough

Hopefully this is a useful placeholder in lieu of a larger structural change, but I understand if we'd rather hold out.

anthonyjoeseph commented 3 years ago

Example usage:

import * as OBE from 'fp-ts-rxjs/lib/ObservableEither'

const f = (a: string): OBE.ObservableEither<boolean, number> =>
  (a.length > 2 ? _.right(a.length) : _.left(false))
const e1: OBE.ObservableEither<boolean | string, number> = pipe(
  OBE.left('four'),
  OBE.chainW(f),
)

This would not work so simply with the ordinary chain

const e2: OBE.ObservableEither<boolean | string, number> = pipe(
  OBE.left('four'),
  OBE.chain(f), // Argument of type 'ObservableEither<string, never>' is not assignable
                // to parameter of type 'ObservableEither<boolean, string>'.
)
anthonyjoeseph commented 3 years ago

Replaced by https://github.com/gcanti/fp-ts-rxjs/pull/49