import { Bifunctor3 } from 'fp-ts/lib/Bifunctor' ; import { Either } from 'fp-ts/lib/Either' ; import * as io from 'fp-ts/lib/IO' ; import { Monad3 } from 'fp-ts/lib/Monad' ; import * as readerT from 'fp-ts/lib/ReaderT' ; import * as taskEither from 'fp-ts/lib/TaskEither' ; import TaskEither = taskEither . TaskEither ; const readerTTaskEither = readerT . getReaderT2v ( taskEither . taskEither ) ; declare module 'fp-ts/lib/HKT' { interface URI2HKT3 < U , L , A > { TIO : TIO < U , L , A > ; } } export const URI = 'TIO' ; export type URI = typeof URI ; export class TIO < R , E , A > { readonly _R ! : R ; readonly _E ! : E ; readonly _A ! : A ; readonly _URI ! : URI ; param { ( e : R ) => TaskEither < E , A > } value memberof constructor ( readonly value ) { } param { R } e returns { Promise < Either < E , A > > } memberof run ( e ) { return this . value ( e ) . run ( ) ; } template R1 template E1 template B param { ( a : A ) => TIO < R1 , E1 , B > } f returns { TIO < R1 , E1 , B > } memberof chain < R1 extends R , E1 , B > ( f ) ; chain < E1 , B > ( f ) ; chain < B > ( f ) { return new TIO ( readerTTaskEither . chain ( this . value , ( a ) => f ( a ) . value ) ) ; } template R1 template E1 template B param { TIO < R1 , E1 , ( a : A ) => B > } fab returns { TIO < R1 , E1 , B > } memberof ap < R1 extends R , E1 , B > ( fab ) ; ap < R1 extends R , B > ( fab ) ; ap < B > ( fab ) { return new TIO ( readerTTaskEither . ap ( fab . value , this . value ) ) ; } template B param { ( a : A ) => B } f returns { TIO < R , E , B > } memberof map < B > ( f ) { return new TIO ( readerTTaskEither . map ( this . value , f ) ) ; } template E1 param { ( e : E ) => E1 } f returns { TIO < R , E1 , A > } memberof mapLeft < E1 > ( f ) { return new TIO ( ( e ) => this . value ( e ) . mapLeft ( f ) ) ; } template R1 param { ( e : R1 ) => R } f returns { TIO < R1 , E , A > } memberof local < R1 = R > ( f ) { return new TIO ( ( e ) => this . value ( f ( e ) ) ) ; } template E1 template B param { ( e : E ) => E1 } f param { ( a : A ) => B } g returns { TIO < R , E1 , B > } memberof bimap < E1 , B > ( f , g ) { return new TIO < R , E1 , B > ( ( e ) => this . value ( e ) . bimap ( f , g ) ) ; } template R1 template E1 template B param { ( e : R1 ) => R } f param { ( e : E ) => E1 } g param { ( a : A ) => B } h returns { TIO < R1 , E1 , B > } memberof trimap < R1 , E1 , B > ( f , g , h ) { return new TIO < R1 , E1 , B > ( ( e ) => this . value ( f ( e ) ) . bimap ( g , h ) ) ; } } export const map = < R , E , A , B > ( fa , f ) => fa . map ( f ) ; export const ap = < R , E , A , B > ( fab , fa ) => fa . ap ( fab ) ; export const of = < R , E , A > ( value ) => new TIO < R , E , A > ( ( ) => taskEither . fromIO ( io . io . of ( value ) ) ) ; export const fromIO = < R , E , A > ( a ) => new TIO < R , E , A > ( ( ) => taskEither . fromIO ( a ) ) ; export const chain = < R , E , A , B > ( fa , f ) => fa . chain ( f ) ; export const bimap = < R , E , E1 , A , B > ( fa , f , g ) => fa . bimap ( f , g ) ; export const ask = < E > ( ) : TIO < E , never , E > => new TIO ( ( e ) => taskEither . fromIO ( io . io . of ( e ) ) ) ; export type UIO < A > = TIO < any , never , A > ; export type Task < A > = TIO < any , Error , A > ; export type IO < E , A > = TIO < any , E , A > ; export const tio = { URI , map , ap , of , chain , bimap , } ;