since import { Applicative4 } from 'fp-ts/lib/Applicative' ; import { Apply4 } from 'fp-ts/lib/Apply' ; import { Bifunctor4 } from 'fp-ts/lib/Bifunctor' ; import * as E from 'fp-ts/lib/Either' ; import { flow , identity , Predicate , Refinement } from 'fp-ts/lib/function' ; import { Functor4 } from 'fp-ts/lib/Functor' ; import { Monad4 } from 'fp-ts/lib/Monad' ; import { MonadIO4 } from 'fp-ts/lib/MonadIO' ; import { MonadTask4 } from 'fp-ts/lib/MonadTask' ; import { MonadThrow4 } from 'fp-ts/lib/MonadThrow' ; import { Option } from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { MonadObservable4 } from './MonadObservable' ; import * as OB from './Observable' ; import * as ROE from './ReaderObservableEither' ; category since export interface StateReaderObservableEither < S , R , E , A > { ( s ) : ROE . ReaderObservableEither < R , E , [ A , S ] > ; } category since export const fromReaderObservableEither = fa => s => pipe ( fa , ROE . map ( a => [ a , s ] ) ) ; category since export const get = ( ) => s => ROE . right ( [ s , s ] ) ; category since export const gets = f => s => ROE . right ( [ f ( s ) , s ] ) ; category since export const modify = f => s => ROE . right ( [ undefined , f ( s ) ] ) ; category since export const put = s => ( ) => ROE . right ( [ undefined , s ] ) ; category since export const right = a => s => ROE . right ( [ a , s ] ) ; category since export const left = e => ( ) => ROE . left ( e ) ; category since export const fromIO = ma => fromObservable ( OB . fromIO ( ma ) ) ; category since export const fromTask = ma => fromObservable ( OB . fromTask ( ma ) ) ; category since export const fromObservable = ma => s => ( ) => pipe ( ma , OB . map ( a => E . right ( [ a , s ] ) ) ) ; const map_ = ( fa , f ) => pipe ( fa , map ( f ) ) ; const ap_ = ( fab , fa ) => pipe ( fab , ap ( fa ) ) ; const chain_ = ( ma , f ) => pipe ( ma , chain ( f ) ) ; category since export const throwError = left ; category since export const map = f => fa => s1 => pipe ( fa ( s1 ) , ROE . map ( ( [ a , s2 ] ) => [ f ( a ) , s2 ] ) ) ; category since export const ap = fa => fab => s1 => pipe ( fab ( s1 ) , ROE . chain ( ( [ f , s2 ] ) => pipe ( fa ( s2 ) , ROE . map ( ( [ a , s3 ] ) => [ f ( a ) , s3 ] ) ) ) ) ; category since export const apFirst = fb => flow ( map ( a => ( ) => a ) , ap ( fb ) ) ; category since export const apSecond = < S , R , E , B > ( fb ) : ( < A > ( fa : StateReaderObservableEither < S , R , E , A > ) => StateReaderObservableEither < S , R , E , B > ) => flow ( map ( ( ) => ( b ) => b ) , ap ( fb ) ) ; category since export const bimap = ( f , g ) => fea => pipe ( map_ ( fea , g ) , mapLeft ( f ) ) ; category since export const mapLeft = f => fea => flow ( fea , ROE . mapLeft ( f ) ) ; category since export const chainW = < A , S , R2 , E2 , B > ( f ) => < R1 , E1 > ( ma ) : StateReaderObservableEither < S , R1 & R2 , E1 | E2 , B > => s1 => pipe ( ma ( s1 ) , ROE . chainW ( ( [ a , s2 ] ) => f ( a ) ( s2 ) ) ) ; 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 ) : ( < S , R > ( ma : StateReaderObservableEither < S , R , E , A > ) => StateReaderObservableEither < S , 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 ) => < S , R , A > ( ma ) : StateReaderObservableEither < S , R , E , A > => ma . _tag === 'None' ? throwError ( onNone ( ) ) : of ( ma . value ) ; since export const fromPredicate = < E , A > ( predicate , onFalse ) => < S , R > ( a ) : StateReaderObservableEither < S , R , E , A > => predicate ( a ) ? of ( a ) : throwError ( onFalse ( a ) ) ; since export const of = right ; const bimap_ = ( fea , f , g ) => pipe ( fea , bimap ( f , g ) ) ; const mapLeft_ = ( fea , f ) => pipe ( fea , mapLeft ( f ) ) ; since export const URI = 'StateReaderObservableEither' ; since export type URI = typeof URI ; declare module 'fp-ts/lib/HKT' { export interface URItoKind4 < S , R , E , A > { readonly [ URI ] : StateReaderObservableEither < S , R , E , A > ; } } since export const Functor = { URI , map : map_ } ; since export const Apply = { URI , map : map_ , ap : ap_ } ; since export const Applicative = { URI , map : map_ , ap : ap_ , of } ; since export const Monad = { URI , map : map_ , ap : ap_ , of , chain : chain_ } ; since export const Bifunctor = { URI , bimap : bimap_ , mapLeft : mapLeft_ } ; since export const MonadIO = { URI , map : map_ , of , ap : ap_ , chain : chain_ , fromIO } ; since export const MonadTask = { URI , map : map_ , of , ap : ap_ , chain : chain_ , fromIO , fromTask } ; since export const MonadObservable = { URI , map : map_ , of , ap : ap_ , chain : chain_ , fromIO , fromObservable , fromTask } ; since export const MonadThrow = { URI , map : map_ , of , ap : ap_ , chain : chain_ , throwError } ; since deprecated export const stateReaderObservableEither = { URI , ap : ap_ , chain : chain_ , map : map_ , of , mapLeft : mapLeft_ , bimap : bimap_ , throwError , fromIO , fromObservable , fromTask } ; since export const bindTo = < K extends string > ( name ) => < S , R , E , A > ( fa ) : StateReaderObservableEither < S , R , E , { [ P in K ] : A ; } > => pipe ( fa , map ( value => ( { [ name ] : value } as any ) ) ) ; since export const bind = < K extends string , S , R , E , A , B > ( name , f ) : ( ( fa : StateReaderObservableEither < S , R , E , A > ) => StateReaderObservableEither < S , 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 ; since export const evaluate = < S > ( s ) => < R , E , A > ( ma ) : ROE . ReaderObservableEither < R , E , A > => pipe ( ma ( s ) , ROE . map ( ( [ a ] ) => a ) ) ; since export const execute = < S > ( s ) => < R , E , A > ( ma ) : ROE . ReaderObservableEither < R , E , S > => pipe ( ma ( s ) , ROE . map ( ( [ _ , s ] ) => s ) ) ;