since import { Applicative3 } from 'fp-ts/lib/Applicative' ; import { Apply3 } from 'fp-ts/lib/Apply' ; import { Bifunctor3 } from 'fp-ts/lib/Bifunctor' ; import { Either } from 'fp-ts/lib/Either' ; import { flow , identity , Predicate , Refinement } from 'fp-ts/lib/function' ; import { Functor3 } from 'fp-ts/lib/Functor' ; import { Monad3 } from 'fp-ts/lib/Monad' ; import { MonadIO3 } from 'fp-ts/lib/MonadIO' ; import { MonadTask3 } from 'fp-ts/lib/MonadTask' ; import { MonadThrow3 } from 'fp-ts/lib/MonadThrow' ; import { Option } from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; import * as R from 'fp-ts/lib/Reader' ; import { MonadObservable3 } from './MonadObservable' ; import * as OE from './ObservableEither' ; category since export interface ReaderObservableEither < R , E , A > { ( r ) : OE . ObservableEither < E , A > ; } category since export const fromObservableEither = R . of ; category since export const right = flow ( OE . right , fromObservableEither ) ; category since export const left = flow ( OE . left , fromObservableEither ) ; category since export const ask = ( ) => OE . right ; category since export const asks = f => flow ( OE . right , OE . map ( f ) ) ; category since export const fromReader = ma => flow ( ma , OE . right ) ; category since export const fromIO = ma => ( ) => OE . rightIO ( ma ) ; category since export const fromTask = ma => ( ) => OE . fromTask ( ma ) ; category since export const fromObservable = ma => ( ) => OE . rightObservable ( ma ) ; category since export const local = R . local ; category since export const throwError = e => ( ) => OE . left ( e ) ; category since export const map = f => fa => flow ( fa , OE . map ( f ) ) ; category since export const ap = fa => fab => r => pipe ( fab ( r ) , OE . ap ( fa ( r ) ) ) ; category since export const apFirst = fb => flow ( map ( a => ( ) => a ) , ap ( fb ) ) ; category since export const apSecond = < R , E , B > ( fb ) : ( < A > ( fa : ReaderObservableEither < R , E , A > ) => ReaderObservableEither < R , E , B > ) => flow ( map ( ( ) => ( b ) => b ) , ap ( fb ) ) ; category since export const of = right ; category since export const bimap = ( f , g ) => fea => r => OE . bimap ( f , g ) ( fea ( r ) ) ; category since export const mapLeft = f => fea => r => OE . mapLeft ( f ) ( fea ( r ) ) ; category since export const chainW = < A , R2 , E2 , B > ( f ) => < R1 , E1 > ( ma ) : ReaderObservableEither < R1 & R2 , E1 | E2 , B > => r => pipe ( ma ( r ) , OE . chainW ( a => f ( a ) ( r ) ) ) ; 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 filterOrElse = < E , A > ( predicate , onFalse ) : ( < R > ( ma : ReaderObservableEither < R , E , A > ) => ReaderObservableEither < R , 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 ) => < R , A > ( ma ) : ReaderObservableEither < R , E , A > => ma . _tag === 'None' ? throwError ( onNone ( ) ) : of ( ma . value ) ; since export const fromPredicate = < E , A > ( predicate , onFalse ) => < R > ( a ) : ReaderObservableEither < R , E , A > => predicate ( a ) ? of ( a ) : throwError ( onFalse ( a ) ) ; 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 ) ) ; category since export const URI = 'ReaderObservableEither' ; category since export type URI = typeof URI ; declare module 'fp-ts/lib/HKT' { export interface URItoKind3 < R , E , A > { readonly [ URI ] : ReaderObservableEither < R , 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 MonadIO = { URI , map : map_ , ap : ap_ , of , chain : chain_ , fromIO } ; category since export const MonadTask = { URI , map : map_ , of , ap : ap_ , chain : chain_ , fromIO , fromTask } ; category since export const MonadObservable = { URI , map : map_ , of , ap : ap_ , chain : chain_ , fromIO , fromObservable , fromTask } ; category since export const MonadThrow = { URI , map : map_ , of , ap : ap_ , chain : chain_ , throwError } ; category since deprecated export const readerObservableEither = { URI , ap : ap_ , map : map_ , of , chain : chain_ , fromIO , fromObservable , fromTask , throwError , bimap : bimap_ , mapLeft : mapLeft_ } ; since export const Do = of ( { } ) ; since export const bindTo = < K extends string , R , E , A > ( name ) : ( ( fa : ReaderObservableEither < R , E , A > ) => ReaderObservableEither < R , E , { [ P in K ] : A ; } > ) => map ( a => ( { [ name ] : a } as { [ P in K ] : A ; } ) ) ; since export const bind = < K extends string , R , E , A , B > ( name , f ) : ( ( fa : ReaderObservableEither < R , E , A > ) => ReaderObservableEither < R , 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 ;