import * as E from 'fp-ts/lib/Either'; import * as RTE from 'fp-ts/lib/ReaderTaskEither'; import * as TE from 'fp-ts/lib/TaskEither'; import { EmptyEnv, Subtract } from '@monorail/sharedHelpers/fp-ts-ext/effectsUtils'; export * from 'fp-ts/lib/ReaderTaskEither'; /** * Pipeable port of rte.orElse, which widens types * @param f */ export declare const orElseW: (f: (e: E) => RTE.ReaderTaskEither) => (rte: RTE.ReaderTaskEither) => RTE.ReaderTaskEither; export declare const chainWFirst: (f: (a: A) => RTE.ReaderTaskEither) => (ma: RTE.ReaderTaskEither) => RTE.ReaderTaskEither; /** * Widens Dependency type to the manually supplied type parameter, * * i.e. * @example * ```ts * const rte = withEnv<{ num: number }>(RTE.of("foo")) * rte.run({ num: 6 }) // requires a `{ num: number }` * ``` */ export declare const withEnv: () => (r: RTE.ReaderTaskEither) => RTE.ReaderTaskEither; /** * Takes a successful Right RTE, and turns it into a failing 'Left' RTE * @param rtea */ export declare const toLeft: (rtea: RTE.ReaderTaskEither) => RTE.ReaderTaskEither; /** * Executes an RTE if a left is encountered, enabling access to the original error. * The value returnded from `f` will be discarded, and the resulting RTE will contain * the original value. * * @example * ```ts * pipe( * RTE.left2v('foo'), * onLeft(e => log(`Encountered error: ${e}`)) * ) * ``` */ export declare const onLeft: (f: (e: E) => RTE.ReaderTaskEither) => (rte: RTE.ReaderTaskEither) => RTE.ReaderTaskEither; /** * Runs a ReaderTaskEither with the specified parameters * * @example * ```ts * pipe( * RTE.ask(), * run('supplied parameter') * ) * ``` * * Note: if the inferred type of R is a subtype of the R in your RTE, * You'll need to explicitly type R to the supertype which matches the RTE * * This is because in fp-ts v1, the `R` type parameter in RTE is invariant * in fp-ts v2, it is contravariant, so this inference issue will go away. * * i.e.: * ```ts * declare const foo: 'foo' * pipe(RTE.ask(), run(foo)) // fails * pipe(RTE.ask(), run(foo)) // succeeds * ``` * * * Some more information about this error: * ```ts * * declare const fooRTE: RTE.ReaderTaskEither<'foo', unknown, unknown> * declare const stringRTE: RTE.ReaderTaskEither * * const a: RTE.ReaderTaskEither = fooRTE * const b: RTE.ReaderTaskEither<'foo', unknown, unknown> = fooRTE * const c: RTE.ReaderTaskEither<'foo', unknown, unknown> = stringRTE * const d: RTE.ReaderTaskEither = stringRTE * ``` * Here, the assignment to `a` and `b` fails, but in fp-ts v2, only the assignment to `a` fails * * Using the suffix `P` for `pipeable` to disambiguate the name from the base `run` * * NOTE: The above examples show primitive types being used in the RTE environment. However, * all utility functions in this file require the environment to be expressed as an object type * due to the reliance on using intersection types to aggregate dependencies. */ export declare const runP: (r: R) => (rte: RTE.ReaderTaskEither) => Promise>; /** * A ReaderTaskEither that performs a noOp computation * * It uses an empty environment and cannot fail. */ export declare const noOpRTE: RTE.ReaderTaskEither; /** * Provides the required environment to a ReaderTaskEither, * converting it into a TaskEither. * * Similar to `runP` but delays execution. */ export declare const provide: (r: R) => (rte: RTE.ReaderTaskEither) => TE.TaskEither; /** * Provides a subset of a ReaderTaskEither's required environment, * returning a new ReaderTaskEither with a narrowed environment requirement. * * Similar to `provide` but does not completely fulfill the RTE's requirements. * Think of this as partial application for RTE dependencies. */ export declare const providePartial: (q: Q) => (rte: RTE.ReaderTaskEither) => RTE.ReaderTaskEither>, E, A>; /** * Given a tuple/list of RTEs, it will aggregate their combined environments into an intersection, * their combined errors into a union, and map the values into a corresponding tuple/list. * * TLDR; Promise.all for ReaderTaskEither */ export declare function sequenceW(rtes: Rtes): CombinedRtes; /** * Performs the type-level computation that combineRTE uses */ export declare type CombinedRtes = RTE.ReaderTaskEither, CombinedRteErr, CombinedRteOutput>; /** * Aggregate many RTE environments into an intersection. */ export declare type CombinedRteEnv = unknown extends ToRteConsList ? ExtractRteEnv : UnNest, unknown>>; export declare type CombinedRteErr = { [K in keyof RTES]: ExtractRteError; }[number]; export declare type CombinedRteOutput = { [K in keyof RTES]: ExtractRteOutput; }; declare type SafeAny = any; export declare type ExtractRteEnv = A extends RTE.ReaderTaskEither ? R : never; export declare type ExtractRteError = A extends RTE.ReaderTaskEither ? R : never; export declare type ExtractRteOutput = A extends RTE.ReaderTaskEither ? R : never; declare type DEFAULT_RTE = RTE.ReaderTaskEither; declare type DEFAULT_RTES = ReadonlyArray; declare type ToRteConsList = [] extends A ? unknown : ((...a: A) => SafeAny) extends (t: infer T, ...ts: infer TS) => SafeAny ? TS extends DEFAULT_RTES ? [ExtractRteEnv, ToRteConsList] : never : never; declare type Flatten = A extends [infer H] ? S & H : A extends [infer I, infer T] ? [Flatten] : S; declare type UnNest = T extends ReadonlyArray ? { [K in keyof T]: T[K] extends [infer TT] ? TT extends ReadonlyArray ? UnNest : TT : T[K]; }[number] : Fallback;