since import { Alt2 } from 'fp-ts/lib/Alt' ; import { Applicative2 } from 'fp-ts/lib/Applicative' ; import { Apply2 } from 'fp-ts/lib/Apply' ; import { Bifunctor2 } from 'fp-ts/lib/Bifunctor' ; import * as E from 'fp-ts/lib/Either' ; import { flow , identity , Predicate , Refinement } 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 { Monad2 } from 'fp-ts/lib/Monad' ; import { MonadIO2 } from 'fp-ts/lib/MonadIO' ; import { MonadTask2 } from 'fp-ts/lib/MonadTask' ; import { MonadThrow2 } from 'fp-ts/lib/MonadThrow' ; import { Option } from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; import * as TE from 'fp-ts/lib/TaskEither' ; import { Observable } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; import { MonadObservable2 } from './MonadObservable' ; import * as R from './Observable' ; category since export interface ObservableEither < E , A > extends Observable < E . Either < E , A > > { } category since export const left = flow ( E . left , R . of ) ; category since export const right = flow ( E . right , R . of ) ; category since export const rightObservable = R . map ( E . right ) ; category since export const leftObservable = R . map ( E . 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 fromTaskEither = R . fromTask ; category since export const fromIO = rightIO ; category since export const fromTask = flow ( R . fromTask , rightObservable ) ; category since export const fromObservable = rightObservable ; category since export const tryCatch = flow ( R . map ( E . right ) , catchError ( flow ( E . left , R . of ) ) ) ; category since export const fold = flow ( E . fold , R . chain ) ; category since export const getOrElse = < E , A > ( onLeft ) => ( ma ) : Observable < A > => pipe ( ma , R . chain ( E . fold ( onLeft , R . of ) ) ) ; category since export const orElse = f => R . chain ( E . fold ( f , right ) ) ; category since export const swap = R . map ( E . swap ) ; category since export const map = f => R . map ( E . map ( f ) ) ; category since export const ap = < E , A > ( fa ) : ( < B > ( fab : ObservableEither < E , ( a : A ) => B > ) => ObservableEither < E , B > ) => flow ( R . map ( gab => ( ga ) => E . ap ( ga ) ( gab ) ) , R . ap ( fa ) ) ; category since export const apFirst = fb => flow ( map ( a => ( ) => a ) , ap ( fb ) ) ; category since export const apSecond = < E , B > ( fb ) : ( < A > ( fa : ObservableEither < E , A > ) => ObservableEither < E , B > ) => flow ( map ( ( ) => ( b ) => b ) , ap ( fb ) ) ; category since export const alt = < E , A > ( that ) : ( ( fa : ObservableEither < E , A > ) => ObservableEither < E , A > ) => R . chain ( E . fold ( that , right ) ) ; category since export const bimap = flow ( E . bimap , R . map ) ; category since export const mapLeft = f => R . map ( E . mapLeft ( f ) ) ; category since export const chainW = < A , E2 , B > ( f ) => < E1 > ( ma ) : ObservableEither < E1 | E2 , B > => pipe ( ma , R . chain ( E . fold ( a => left < E1 | E2 , B > ( a ) , f ) ) ) ; category since export const chain = chainW ; category since export const flatten = chain ( identity ) ; category since export const chainFirst = f => chain ( a => pipe ( f ( a ) , map ( ( ) => a ) ) ) ; since export const of = right ; since export const filterOrElse = < E , A > ( predicate , onFalse ) : ( ( ma : ObservableEither < E , A > ) => ObservableEither < E , A > ) => chain ( a => ( predicate ( a ) ? of ( a ) : throwError ( onFalse ( a ) ) ) ) ; since export const fromEither = ma => ma . _tag === 'Left' ? throwError ( ma . left ) : of ( ma . right ) ; since export const fromOption = < E > ( onNone ) => < A > ( ma ) : ObservableEither < E , A > => ma . _tag === 'None' ? throwError ( onNone ( ) ) : of ( ma . value ) ; since export const fromPredicate = < E , A > ( predicate , onFalse ) => ( a ) : ObservableEither < E , A > => predicate ( a ) ? of ( a ) : throwError ( onFalse ( a ) ) ; category since export const throwError = left ; const map_ = ( fa , f ) => pipe ( fa , map ( f ) ) ; const ap_ = ( fab , fa ) => pipe ( fab , ap ( fa ) ) ; const chain_ = ( ma , f ) => pipe ( ma , chain ( f ) ) ; const bimap_ = ( fea , f , g ) => pipe ( fea , bimap ( f , g ) ) ; const mapLeft_ = ( fea , f ) => pipe ( fea , mapLeft ( f ) ) ; const alt_ = ( fx , fy ) => pipe ( fx , alt ( fy ) ) ; category since export const URI = 'ObservableEither' ; category since export type URI = typeof URI ; declare module 'fp-ts/lib/HKT' { interface URItoKind2 < E , A > { readonly [ URI ] : ObservableEither < E , A > ; } } category since export const Functor = { URI , map : map_ } ; category since export const Apply = { URI , map : map_ , ap : ap_ } ; category since export const Applicative = { URI , map : map_ , ap : ap_ , of } ; category since export const Monad = { URI , map : map_ , ap : ap_ , of , chain : chain_ } ; category since export const Bifunctor = { URI , bimap : bimap_ , mapLeft : mapLeft_ } ; category since export const Alt = { URI , map : map_ , alt : alt_ } ; category since export const MonadIO = { URI , map : map_ , ap : ap_ , of , chain : chain_ , fromIO } ; category since export const MonadTask = { URI , map : map_ , ap : ap_ , of , chain : chain_ , fromIO , fromTask } ; category since export const MonadObservable = { URI , map : map_ , ap : ap_ , of , chain : chain_ , fromIO , fromTask , fromObservable } ; category since export const MonadThrow = { URI , map : map_ , ap : ap_ , of , chain : chain_ , throwError } ; category deprecated since export const observableEither = { URI , map : map_ , of , ap : ap_ , chain : chain_ , bimap : bimap_ , mapLeft : mapLeft_ , alt : alt_ , fromIO : rightIO , fromTask , fromObservable , throwError } ; since export const Do = of ( { } ) ; since export const bindTo = < K extends string , E , A > ( name ) : ( ( fa : ObservableEither < E , A > ) => ObservableEither < E , { [ P in K ] : A ; } > ) => map ( a => ( { [ name ] : a } as { [ P in K ] : A ; } ) ) ; since export const bind = < K extends string , E , A , B > ( name , f ) : ( ( fa : ObservableEither < E , A > ) => ObservableEither < E , { [ P in keyof A | K ] : P extends keyof A ? A [ P ] : B ; } > ) => chain ( a => pipe ( f ( a ) , map ( b => ( { ... a , [ name ] : b } as any ) ) ) ) ; since export const bindW = bind as any ; since export const toTaskEither = R . toTask ;