since import { flow , identity , Lazy , pipe , Predicate , Refinement } from 'fp-ts/function' ; import { bind as bind_ , chainFirst as chainFirst_ , Chain4 } from 'fp-ts/Chain' ; import { Task } from 'fp-ts/Task' ; import * as TE from 'fp-ts/TaskEither' ; import * as H from '.' ; import * as M from './Middleware' ; import { IO } from 'fp-ts/IO' ; import { IOEither } from 'fp-ts/IOEither' ; import * as E from 'fp-ts/Either' ; import { Monad4 } from 'fp-ts/Monad' ; import { Alt4 } from 'fp-ts/Alt' ; import { Bifunctor4 } from 'fp-ts/Bifunctor' ; import { MonadThrow4 } from 'fp-ts/MonadThrow' ; import { Functor4 , bindTo as bindTo_ } from 'fp-ts/Functor' ; import { Apply4 , apS as apS_ , apFirst as apFirst_ , apSecond as apSecond_ } from 'fp-ts/Apply' ; import { Applicative4 } from 'fp-ts/Applicative' ; import * as RTE from 'fp-ts/ReaderTaskEither' ; import { Reader } from 'fp-ts/Reader' ; import { chainEitherK as chainEitherK_ , FromEither4 , fromPredicate as fromPredicate_ , filterOrElse as filterOrElse_ , } from 'fp-ts/FromEither' ; import { FromIO4 , fromIOK as fromIOK_ , chainIOK as chainIOK_ , chainFirstIOK as chainFirstIOK_ } from 'fp-ts/FromIO' ; import { FromTask4 , fromTaskK as fromTaskK_ , chainTaskK as chainTaskK_ , chainFirstTaskK as chainFirstTaskK_ , } from 'fp-ts/FromTask' ; category since export const URI = 'ReaderMiddleware' ; category since export type URI = typeof URI ; declare module 'fp-ts/HKT' { interface URItoKind4 < S , R , E , A > { readonly [ URI ] : ReaderMiddleware < S , R , R , E , A > ; } } category since export interface ReaderMiddleware < R , I , O , E , A > { ( r ) : M . Middleware < I , O , E , A > ; } category since export function fromTaskEither < R , I = H . StatusOpen , E = never , A = never > ( fa ) { return ( ) => M . fromTaskEither ( fa ) ; } category since export function fromReaderTaskEither < R , I = H . StatusOpen , E = never , A = never > ( fa ) { return ( r ) => M . fromTaskEither ( fa ( r ) ) ; } category since export const fromMiddleware = < R , I = H . StatusOpen , O = I , E = never , A = never > ( fa ) : ReaderMiddleware < R , I , O , E , A > => ( ) => fa ; category since export function gets < R , I = H . StatusOpen , E = never , A = never > ( f ) { return fromMiddleware ( M . gets ( f ) ) ; } category since export function fromConnection < R , I = H . StatusOpen , E = never , A = never > ( f ) { return fromMiddleware ( M . fromConnection ( f ) ) ; } category since export function modifyConnection < R , I , O , E > ( f ) { return fromMiddleware ( M . modifyConnection ( f ) ) ; } category since export function right < R , I = H . StatusOpen , E = never , A = never > ( a ) { return fromMiddleware ( M . right ( a ) ) ; } category since export function left < R , I = H . StatusOpen , E = never , A = never > ( e ) { return fromMiddleware ( M . left ( e ) ) ; } category since export function rightTask < R , I = H . StatusOpen , E = never , A = never > ( fa ) { return fromMiddleware ( M . rightTask ( fa ) ) ; } category since export function leftTask < R , I = H . StatusOpen , E = never , A = never > ( te ) { return fromMiddleware ( M . leftTask ( te ) ) ; } category since export function rightIO < R , I = H . StatusOpen , E = never , A = never > ( fa ) { return fromMiddleware ( M . rightIO ( fa ) ) ; } category since export function leftIO < R , I = H . StatusOpen , E = never , A = never > ( fe ) { return fromMiddleware ( M . leftIO ( fe ) ) ; } category since export const fromEither = < R , I = H . StatusOpen , E = never , A = never > ( e ) : ReaderMiddleware < R , I , I , E , A > => fromMiddleware ( M . fromEither ( e ) ) ; category since export function fromIOEither < R , I = H . StatusOpen , E = never , A = never > ( fa ) { return fromMiddleware ( M . fromIOEither ( fa ) ) ; } category since export const rightReader = < R , I = H . StatusOpen , E = never , A = never > ( ma ) : ReaderMiddleware < R , I , I , E , A > => ( r ) => M . right ( ma ( r ) ) ; category since export function leftReader < R , I = H . StatusOpen , E = never , A = never > ( me ) { return ( r ) => M . left ( me ( r ) ) ; } category since export const ask = < R , I = H . StatusOpen , E = never > ( ) : ReaderMiddleware < R , I , I , E , R > => M . right ; category since export const asks = < R , E = never , A = never > ( f ) : ReaderMiddleware < R , H . StatusOpen , H . StatusOpen , E , A > => flow ( f , M . right ) ; category since export const orElseW = < R2 , E , I , O , M , B > ( f ) => < R1 , A > ( ma ) : ReaderMiddleware < R2 & R1 , I , O , M , A | B > => ( r ) => ( c ) => pipe ( ma ( r ) ( c ) , TE . orElseW ( ( e ) => f ( e ) ( r ) ( c ) ) ) ; category since export const orElse = orElseW ; category since export function status < R , E = never > ( status ) { return ( ) => M . status ( status ) ; } category since export function header < R , E = never > ( name , value ) { return ( ) => M . header ( name , value ) ; } category since export function contentType < R , E = never > ( mediaType ) { return header ( 'Content-Type' , mediaType ) ; } category since export function cookie < R , E = never > ( name , value , options ) { return ( ) => M . cookie ( name , value , options ) ; } category since export function clearCookie < R , E = never > ( name , options ) { return ( ) => M . clearCookie ( name , options ) ; } const closedHeaders = iof ( undefined ) ; category since export function closeHeaders < R , E = never > ( ) { return closedHeaders ; } category since export function send < R , E = never > ( body ) { return ( ) => M . send ( body ) ; } category since export function end < R , E = never > ( ) { return M . end ; } category since export function json < R , E > ( body , onError ) { return ( ) => M . json ( body , onError ) ; } category since export function redirect < R , E = never > ( uri ) { return ( ) => M . redirect ( uri ) ; } category since export function pipeStream < R , E > ( stream ) { return modifyConnection ( ( c ) => c . pipeStream ( stream ) ) ; } category since export function decodeParam < R , E , A > ( name , f ) { return ( ) => M . decodeParam ( name , f ) ; } category since export function decodeParams < R , E , A > ( f ) { return ( ) => M . decodeParams ( f ) ; } category since export function decodeQuery < R , E , A > ( f ) { return ( ) => M . decodeQuery ( f ) ; } category since export function decodeBody < R , E , A > ( f ) { return ( ) => M . decodeBody ( f ) ; } category since export function decodeMethod < R , E , A > ( f ) { return ( ) => M . decodeMethod ( f ) ; } category since export function decodeHeader < R , E , A > ( name , f ) { return ( ) => M . decodeHeader ( name , f ) ; } const _map = ( fa , f ) => ( r ) => pipe ( fa ( r ) , M . map ( f ) ) ; const _apPar = ( fab , fa ) => pipe ( fab , ap ( fa ) ) ; const _apSeq = ( fab , fa ) => _chain ( fab , ( f ) => _map ( fa , ( a ) => f ( a ) ) ) ; const _chain = ( ma , f ) => ( r ) => pipe ( ma ( r ) , M . chain ( ( a ) => f ( a ) ( r ) ) ) ; const _alt = ( fx , f ) => ( r ) => ( c ) => pipe ( fx ( r ) ( c ) , TE . alt ( ( ) => f ( ) ( r ) ( c ) ) ) ; const _bimap = ( fea , f , g ) => ( r ) => ( c ) => pipe ( fea ( r ) ( c ) , TE . bimap ( f , ( [ a , c ] ) => [ g ( a ) , c ] ) ) ; const _mapLeft = ( fea , f ) => ( r ) => ( c ) => pipe ( fea ( r ) ( c ) , TE . mapLeft ( f ) ) ; category since export const map = < A , B > ( f ) => < R , I , E > ( fa ) : ReaderMiddleware < R , I , I , E , B > => _map ( fa , f ) ; category since export const imap = < A , B > ( f ) => < R , I , O , E > ( fa ) : ReaderMiddleware < R , I , O , E , B > => ( r ) => pipe ( fa ( r ) , M . imap ( f ) ) ; category since export const bimap = < E , G , A , B > ( f , g ) => < R , I > ( fa ) : ReaderMiddleware < R , I , I , G , B > => _bimap ( fa , f , g ) ; category since export const mapLeft = < E , G > ( f ) => < R , I , A > ( fa ) : ReaderMiddleware < R , I , I , G , A > => _mapLeft ( fa , f ) ; category since export const ap = < R , I , E , A > ( fa ) => < B > ( fab ) : ReaderMiddleware < R , I , I , E , B > => ( r ) => pipe ( fab ( r ) , M . ap ( fa ( r ) ) ) ; category since export const apW = ap as any ; category since export const of = right ; category since export function iof < R , I = H . StatusOpen , O = H . StatusOpen , E = never , A = never > ( a ) { return ( ) => M . iof ( a ) ; } category since export const chain = < R , I , E , A , B > ( f ) => ( ma ) : ReaderMiddleware < R , I , I , E , B > => _chain ( ma , f ) ; category since export const chainW = chain as any ; category since export const flattenW = chainW ( identity ) ; category since export const flatten = flattenW ; category since export const ichain = ichainW ; category since export function ichainW < R2 , A , O , Z , E2 , B > ( f ) { return ( ma ) => ( r ) => ( ci ) => pipe ( ma ( r ) ( ci ) , TE . chainW ( ( [ a , co ] ) => f ( a ) ( r ) ( co ) ) ) ; } category since export const ichainFirst = ichainFirstW ; category since export function ichainFirstW < R2 , A , O , Z , E2 , B > ( f ) { return ( ma ) => ( r ) => pipe ( ma ( r ) , M . ichainFirstW ( ( a ) => f ( a ) ( r ) ) ) ; } category since export const iflattenW = ichainW ( identity ) ; category since export const iflatten = iflattenW ; category since export const alt = < R , I , E , A > ( that ) => ( fa ) : ReaderMiddleware < R , I , I , E , A > => _alt ( fa , that ) ; category since export const altW = alt as any ; category since export const chainMiddlewareK = < R , I , E , A , B > ( f ) => ( ma ) : ReaderMiddleware < R , I , I , E , B > => pipe ( ma , chain ( ( a ) => fromMiddleware ( f ( a ) ) ) ) ; category since export const ichainMiddlewareK = chainMiddlewareK as any ; category since export const ichainMiddlewareKW = chainMiddlewareK as any ; category since export const chainTaskEitherK = ( f ) => ( ma ) => ( r ) => pipe ( ma ( r ) , M . chain ( ( a ) => M . fromTaskEither ( f ( a ) ) ) ) ; category since export const chainTaskEitherKW = chainTaskEitherK as any ; category since export const chainReaderTaskEitherK = ( f ) => ( ma ) => ( r ) => pipe ( ma ( r ) , M . chain ( ( a ) => M . fromTaskEither ( f ( a ) ( r ) ) ) ) ; category since export const chainReaderTaskEitherKW = chainReaderTaskEitherK as any ; category since export const chainFirstReaderTaskEitherKW = ( f ) => chainFirstW ( ( a ) => fromReaderTaskEither ( f ( a ) ) ) ; category since export const chainFirstReaderTaskEitherK = chainFirstReaderTaskEitherKW ; category since export const Functor = { URI , map : _map , } ; category since export const ApplyPar = { ... Functor , ap : _apPar , } ; category since export const ApplySeq = { ... Functor , ap : _apSeq , } ; category since deprecated export const Apply = ApplySeq ; category since export const ApplicativePar = { ... ApplyPar , of , } ; category since export const ApplicativeSeq = { ... ApplySeq , of , } ; category since deprecated export const Applicative = ApplicativeSeq ; category since export const Chain = { ... ApplyPar , chain : _chain , } ; category since export const Monad = { ... ApplicativeSeq , chain : _chain , } ; category since export const MonadThrow = { ... Monad , throwError : left , } ; category since export const Alt = { ... Functor , alt : _alt , } ; category since export const Bifunctor = { URI , bimap : _bimap , mapLeft : _mapLeft , } ; category since export const FromEither = { URI , fromEither , } ; category since export const apFirst = apFirst_ ( ApplyPar ) ; category since export const apFirstW = apFirst as any ; category since export const apSecond = apSecond_ ( ApplyPar ) ; category since export const apSecondW = apSecond as any ; category since export const chainFirst = chainFirst_ ( Chain ) ; category since export const chainFirstW = chainFirst as any ; category since export const fromPredicate = fromPredicate_ ( FromEither ) ; category since export const filterOrElse = filterOrElse_ ( FromEither , Chain ) ; category since export const filterOrElseW = filterOrElse ; category since export const chainEitherK = chainEitherK_ ( FromEither , Chain ) ; category since export const chainEitherKW = chainEitherK as any ; category since export const fromIO = rightIO ; category since export const FromIO = { URI , fromIO , } ; category since export const fromIOK = fromIOK_ ( FromIO ) ; category since export const chainIOK = chainIOK_ ( FromIO , Chain ) ; category since export const chainFirstIOK = chainFirstIOK_ ( FromIO , Chain ) ; category since export const fromTask = rightTask ; category since export const FromTask = { ... FromIO , fromTask , } ; category since export const fromTaskK = fromTaskK_ ( FromTask ) ; category since export const chainTaskK = chainTaskK_ ( FromTask , Chain ) ; category since export const chainFirstTaskK = chainFirstTaskK_ ( FromTask , Chain ) ; category since export const chainFirstTaskEitherKW = ( f ) => chainFirstW ( ( a ) => fromTaskEither ( f ( a ) ) ) ; category since export const chainFirstTaskEitherK = chainFirstTaskEitherKW ; since deprecated export const Do = iof < unknown , unknown , unknown , never , { } > ( { } ) ; since export const bindTo = bindTo_ ( Functor ) ; since export const ibindTo = bindTo as any ; since export const bind = bind_ ( Chain ) ; since export const bindW = bind as any ; since export const ibindW = bindW as any ; since export const ibind = ibindW ; since export const apS = apS_ ( ApplyPar ) ; since export const apSW = apS as any ; since export const iapSW = apS as any ; since export const iapS = iapSW ;