since import { Alt2 } from 'fp-ts/lib/Alt' ; import { Alternative2 } from 'fp-ts/lib/Alternative' ; import { Applicative2 } from 'fp-ts/lib/Applicative' ; import { Apply2 } from 'fp-ts/lib/Apply' ; import { Compactable2 , Separated } from 'fp-ts/lib/Compactable' ; import * as E from 'fp-ts/lib/Either' ; import { Filterable2 } from 'fp-ts/lib/Filterable' ; 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 { Monad2 } from 'fp-ts/lib/Monad' ; import { MonadIO2 } from 'fp-ts/lib/MonadIO' ; import { MonadTask2 } from 'fp-ts/lib/MonadTask' ; import { Monoid } from 'fp-ts/lib/Monoid' ; import * as O from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; import * as R from 'fp-ts/lib/Reader' ; import { ReaderTask } from 'fp-ts/lib/ReaderTask' ; import { Observable } from 'rxjs' ; import { MonadObservable2 } from './MonadObservable' ; import * as T from './Observable' ; category since export interface ReaderObservable < R , A > { ( r ) : Observable < A > ; } category since export const fromObservable = R . of ; category since export const fromReader = ma => flow ( ma , T . of ) ; category since export const fromOption = < R , A > ( o ) : ReaderObservable < R , A > => fromObservable ( T . fromOption ( o ) ) ; category since export const fromIO = flow ( T . fromIO , fromObservable ) ; category since export const fromTask = flow ( T . fromTask , fromObservable ) ; category since export const fromReaderTask = < R , A > ( ma ) : ReaderObservable < R , A > => flow ( ma , T . fromTask ) ; category since export const ask = ( ) => T . of ; category since export const asks = f => flow ( T . of , T . map ( f ) ) ; category since export const local = R . local ; category since export const fromIOK = < A extends Array < unknown > , B > ( f ) : ( < R > ( ... a : A ) => ReaderObservable < R , B > ) => ( ... a ) => fromIO ( f ( ... a ) ) ; category since export const chainIOK = < A , B > ( f ) : ( < R > ( ma : ReaderObservable < R , A > ) => ReaderObservable < R , B > ) => chain ( a => fromIOK ( f ) ( a ) ) ; category since export const fromObservableK = < A extends Array < unknown > , B > ( f ) : ( < R > ( ... a : A ) => ReaderObservable < R , B > ) => ( ... a ) => fromObservable ( f ( ... a ) ) ; category since export const chainTaskK = < A , B > ( f ) : ( < R > ( ma : ReaderObservable < R , A > ) => ReaderObservable < R , B > ) => chain ( a => fromObservableK ( f ) ( a ) ) ; category since export const map = f => fa => flow ( fa , T . map ( f ) ) ; category since export const ap = fa => fab => r => pipe ( fab ( r ) , T . ap ( fa ( r ) ) ) ; category since export const apFirst = fb => flow ( map ( a => ( ) => a ) , ap ( fb ) ) ; category since export const apSecond = < R , B > ( fb ) : ( < A > ( fa : ReaderObservable < R , A > ) => ReaderObservable < R , B > ) => flow ( map ( ( ) => ( b ) => b ) , ap ( fb ) ) ; category since export const of = a => ( ) => T . of ( a ) ; category since export const chainW = < A , R2 , B > ( f ) => < R1 > ( ma ) : ReaderObservable < R1 & R2 , B > => r => pipe ( ma ( r ) , T . chain ( 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 ) ) ) ; category since export const alt = that => me => r => pipe ( me ( r ) , T . alt ( ( ) => that ( ) ( r ) ) ) ; since export const zero = ( ) => T . Alternative . zero ; category since export const filterMap = f => fa => r => pipe ( fa ( r ) , T . filterMap ( f ) ) ; category since export const compact = filterMap ( identity ) ; category since export const partitionMap = f => fa => ( { left : pipe ( fa , filterMap ( a => O . fromEither ( E . swap ( f ( a ) ) ) ) ) , right : pipe ( fa , filterMap ( a => O . fromEither ( f ( a ) ) ) ) } ) ; category since export const separate = partitionMap ( identity ) ; category since export const filter = < A > ( predicate ) : ( < R > ( fa : ReaderObservable < R , A > ) => ReaderObservable < R , A > ) => filterMap ( O . fromPredicate ( predicate ) ) ; category since export const partition = < A > ( predicate ) : ( < R > ( fa : ReaderObservable < R , A > ) => Separated < ReaderObservable < R , A > , ReaderObservable < R , A > > ) => partitionMap ( E . fromPredicate ( predicate , identity ) ) ; 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 alt_ = ( fx , f ) => pipe ( fx , alt ( f ) ) ; const filter_ = < R , A > ( fa , p ) => pipe ( fa , filter ( p ) ) ; const filterMap_ = ( fa , f ) => pipe ( fa , filterMap ( f ) ) ; const partition_ = < R , A > ( fa , p ) => pipe ( fa , partition ( p ) ) ; const partitionMap_ = ( fa , f ) => pipe ( fa , partitionMap ( f ) ) ; category since export const URI = 'ReaderObservable' ; category since export type URI = typeof URI ; declare module 'fp-ts/lib/HKT' { interface URItoKind2 < E , A > { readonly [ URI ] : ReaderObservable < E , A > ; } } category since export const getMonoid = < R , A > ( ) : Monoid < ReaderObservable < R , A > > => R . getMonoid ( T . getMonoid ( ) ) ; 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 Alt = { URI , map : map_ , alt : alt_ } ; category since export const Alternative = { URI , map : map_ , ap : ap_ , of , alt : alt_ , zero } ; category since export const Compactable = { URI , compact , separate } ; category since export const Filterable = { URI , compact , separate , map : map_ , filter : filter_ , filterMap : filterMap_ , partition : partition_ , partitionMap : partitionMap_ } ; 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 deprecated export const readerObservable = { URI , map : map_ , of , ap : ap_ , chain : chain_ , zero , alt : alt_ , compact , separate , partitionMap : partitionMap_ , partition : partition_ , filterMap : filterMap_ , filter : filter_ , fromIO , fromTask , fromObservable } ; since export const Do = of ( { } ) ; since export const bindTo = < K extends string , R , A > ( name ) : ( ( fa : ReaderObservable < R , A > ) => ReaderObservable < R , { [ P in K ] : A ; } > ) => map ( a => ( { [ name ] : a } as { [ P in K ] : A ; } ) ) ; since export const bind = < K extends string , R , A , B > ( name , f ) : ( ( fa : ReaderObservable < R , A > ) => ReaderObservable < R , { [ 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 run = < R , A > ( ma , r ) : Promise < A > => T . toTask ( ma ( r ) ) ( ) ; since export const toReaderTask = < R , A > ( ma ) : ReaderTask < R , A > => r => T . toTask ( ma ( r ) ) ; since export const toReaderTaskOption = < R , A > ( ma ) : ReaderTask < R , O . Option < A > > => r => T . toTaskOption ( ma ( r ) ) ;