since import { Applicative2 , Applicative2C } from 'fp-ts/lib/Applicative' ; import { Apply1 } from 'fp-ts/lib/Apply' ; import { Bifunctor2 } from 'fp-ts/lib/Bifunctor' ; import { flow } from 'fp-ts/lib/function' ; import { Functor2 } from 'fp-ts/lib/Functor' ; import { IO } from 'fp-ts/lib/IO' ; import { IOEither } from 'fp-ts/lib/IOEither' ; import { Monad2C } from 'fp-ts/lib/Monad' ; import { MonadIO2 } from 'fp-ts/lib/MonadIO' ; import { MonadTask2 } from 'fp-ts/lib/MonadTask' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { Semigroup } from 'fp-ts/lib/Semigroup' ; import * as TT from 'fp-ts/lib/TaskThese' ; import * as TH from 'fp-ts/lib/These' ; import { Observable } from 'rxjs' ; import * as R from './Observable' ; category since export interface ObservableThese < E , A > extends Observable < TH . These < E , A > > { } category since export const left = flow ( TH . left , R . of ) ; category since export const both = flow ( TH . both , R . of ) ; category since export const right = flow ( TH . right , R . of ) ; category since export const rightObservable = R . map ( TH . right ) ; category since export const leftObservable = R . map ( TH . left ) ; category since export const fromIOEither = R . fromIO ; category since export const rightIO = flow ( R . fromIO , rightObservable ) ; category since export const leftIO = flow ( R . fromIO , leftObservable ) ; category since export const fromTaskThese = R . fromTask ; category since export const fromIO = rightIO ; category since export const fromTask = flow ( R . fromTask , rightObservable ) ; category since export const fold = flow ( TH . fold , R . chain ) ; category since export const swap = R . map ( TH . swap ) ; category since export const map = f => R . map ( TH . map ( f ) ) ; category since export const bimap = ( f , g ) => R . map ( TH . bimap ( f , g ) ) ; category since export const mapLeft = f => R . map ( TH . mapLeft ( f ) ) ; category since export const of = right ; const map_ = ( fa , f ) => pipe ( fa , map ( f ) ) ; const bimap_ = ( fea , f , g ) => pipe ( fea , bimap ( f , g ) ) ; const mapLeft_ = ( fea , f ) => pipe ( fea , mapLeft ( f ) ) ; since export const URI = 'ObservableThese' ; since export type URI = typeof URI ; declare module 'fp-ts/lib/HKT' { interface URItoKind2 < E , A > { readonly [ URI ] : ObservableThese < E , A > ; } } category since export const getApplicative = < E > ( A , S ) : Applicative2C < URI , E > => { const AV = TH . getMonad ( S ) ; const ap = < A > ( fga ) => < B > ( fgab ) : Observable < TH . These < E , B > > => A . ap ( A . map ( fgab , h => ( ga ) => AV . ap ( h , ga ) ) , fga ) ; return { URI , _E : undefined as any , map : map_ , ap : ( fab , fa ) => pipe ( fab , ap ( fa ) ) , of } ; } ; category since export const getMonad = < E > ( S ) : Monad2C < URI , E > => { const A = getApplicative ( R . Apply , S ) ; return { URI , _E : undefined as any , map : map_ , ap : A . ap , of , chain : ( ma , f ) => pipe ( ma , R . chain ( TH . fold ( left , f , ( e1 , a ) => pipe ( f ( a ) , R . map ( TH . fold ( e2 => TH . left ( S . concat ( e1 , e2 ) ) , b => TH . both ( e1 , b ) , ( e2 , b ) => TH . both ( S . concat ( e1 , e2 ) , b ) ) ) ) ) ) ) } ; } ; since export const Functor = { URI , map : map_ } ; category since export const Bifunctor = { URI , bimap : bimap_ , mapLeft : mapLeft_ } ; since export const toTaskThese = R . toTask ;