import * as Tp from "../Collections/Immutable/Tuple/index.js"; import { _A, _E, _R, _U } from "../Effect/commons.js"; import * as E from "../Either/index.js"; import type { Option } from "../Option/index.js"; import type * as U from "../Utils/index.js"; /** * `Async[R, E, A]` is a purely functional description of an async computation * that requires an environment `R` and may either fail with an `E` or succeed * with an `A`. */ export interface Async extends U.HasUnify { } export declare abstract class Async { readonly [_U]: "Async"; readonly [_E]: () => E; readonly [_A]: () => A; readonly [_R]: (_: R) => void; } export interface UIO extends Async { } export interface RIO extends Async { } export interface IO extends Async { } /** * Models the state of interruption, allows for listening to interruption events & firing interruption events */ export declare class InterruptionState { private isInterrupted; readonly listeners: Set<() => void>; listen(f: () => void): () => void; get interrupted(): boolean; interrupt(): void; } export interface Failure { readonly _tag: "Failure"; e: E; } export interface Interrupt { readonly _tag: "Interrupt"; } export interface Success { readonly _tag: "Success"; a: A; } export declare type Rejection = Failure | Interrupt; export declare type Exit = Rejection | Success; export declare const failExit: (e: E) => Rejection; export declare const interruptExit: Exit; export declare const successExit: (a: A) => Exit; export declare class Tracer { private running; constructor(); traced(promise: () => Promise): () => Promise; wait(): Promise[]>; clear(): void; } export declare const tracingContext: Tracer; /** * Runs this computation with the specified initial state, returning either a * failure or the updated state and the result */ export declare function runPromiseExitEnv(self: Async, ri: R, is?: InterruptionState): Promise>; export declare function runPromiseExit(self: Async, is?: InterruptionState): Promise>; export declare function runPromise(task: Async, is?: InterruptionState): Promise; export declare function runAsync(task: Async, cb?: (e: Exit) => void): () => void; export declare function runAsyncEnv(task: Async, r: R, cb?: (e: Exit) => void): () => void; /** * Extends this computation with another computation that depends on the * result of this computation by running the first computation, using its * result to generate a second computation, and running that computation. * * @ets_data_first chain_ */ export declare function chain(f: (a: A) => Async): (self: Async) => Async; /** * Extends this computation with another computation that depends on the * result of this computation by running the first computation, using its * result to generate a second computation, and running that computation. */ export declare function chain_(self: Async, f: (a: A) => Async): Async; /** * Returns a computation that effectfully "peeks" at the success of this one. * * @ets_data_first tap_ */ export declare function tap(f: (a: A) => Async): (self: Async) => Async; /** * Returns a computation that effectfully "peeks" at the success of this one. */ export declare function tap_(self: Async, f: (a: A) => Async): Async; /** * Constructs a computation that always succeeds with the specified value. */ export declare function succeed(a: A): Async; /** * Constructs a computation that always succeeds with the specified value, * passing the state through unchanged. */ export declare function fail(a: E): Async; /** * Extends this computation with another computation that depends on the * result of this computation by running the first computation, using its * result to generate a second computation, and running that computation. */ export declare function map_(self: Async, f: (a: A) => B): Async; /** * Extends this computation with another computation that depends on the * result of this computation by running the first computation, using its * result to generate a second computation, and running that computation. * * @ets_data_first map_ */ export declare function map(f: (a: A) => B): (self: Async) => Async; /** * Recovers from errors by accepting one computation to execute for the case * of an error, and one computation to execute for the case of success. */ export declare function foldM_(self: Async, failure: (e: E) => Async, success: (a: A) => Async): Async; /** * Recovers from errors by accepting one computation to execute for the case * of an error, and one computation to execute for the case of success. * * @ets_data_first foldM_ */ export declare function foldM(failure: (e: E) => Async, success: (a: A) => Async): (self: Async) => Async; /** * Folds over the failed or successful results of this computation to yield * a computation that does not fail, but succeeds with the value of the left * or right function passed to `fold`. * * @ets_data_first fold_ */ export declare function fold(failure: (e: E) => B, success: (a: A) => C): (self: Async) => Async; /** * Folds over the failed or successful results of this computation to yield * a computation that does not fail, but succeeds with the value of the left * or righr function passed to `fold`. */ export declare function fold_(self: Async, failure: (e: E) => B, success: (a: A) => C): Async; /** * Recovers from all errors. * * @ets_data_first catchAll_ */ export declare function catchAll(failure: (e: E) => Async): (self: Async) => Async; /** * Recovers from all errors. */ export declare function catchAll_(self: Async, failure: (e: E) => Async): Async; /** * Returns a computation whose error and success channels have been mapped * by the specified functions, `f` and `g`. * * @ets_data_first bimap_ */ export declare function bimap(f: (e: E) => E1, g: (a: A) => A1): (self: Async) => Async A1>; /** * Returns a computation whose error and success channels have been mapped * by the specified functions, `f` and `g`. */ export declare function bimap_(self: Async, f: (e: E) => E1, g: (a: A) => A1): Async A1>; /** * Transforms the error type of this computation with the specified * function. * * @ets_data_first mapError_ */ export declare function mapError(f: (e: E) => E1): (self: Async) => Async; /** * Transforms the error type of this computation with the specified * function. */ export declare function mapError_(self: Async, f: (e: E) => E1): Async; /** * Constructs a computation that always returns the `Unit` value, passing the * state through unchanged. */ export declare const unit: Async; /** * Transforms the initial state of this computation` with the specified * function. */ export declare function provideSome(f: (s: R0) => R1): (self: Async) => Async; /** * Provides this computation with its required environment. * * @ets_data_first provideAll_ */ export declare function provideAll(r: R): (self: Async) => Async; /** * Provides this computation with its required environment. */ export declare function provideAll_(self: Async, r: R): Async; /** * Provides some of the environment required to run this effect, * leaving the remainder `R0` and combining it automatically using spread. */ export declare function provide(r: R): (next: Async) => Async; /** * Access the environment monadically */ export declare function accessM(f: (_: R) => Async): Async; /** * Access the environment with the function f */ export declare function access(f: (_: R) => A): Async; /** * Access the environment */ export declare function environment(): Async; /** * Returns a computation whose failure and success have been lifted into an * `Either`. The resulting computation cannot fail, because the failure case * has been exposed as part of the `Either` success case. */ export declare function either(self: Async): Async>; /** * Executes this computation and returns its value, if it succeeds, but * otherwise executes the specified computation. * * @ets_data_first orElseEither_ */ export declare function orElseEither(that: () => Async): (self: Async) => Async>; /** * Executes this computation and returns its value, if it succeeds, but * otherwise executes the specified computation. */ export declare function orElseEither_(self: Async, that: () => Async): Async>; /** * Combines this computation with the specified computation, passing the * updated state from this computation to that computation and combining the * results of both using the specified function. * * @ets_data_first zipWith_ */ export declare function zipWith(that: Async, f: (a: A, b: B) => C): (self: Async) => Async; /** * Combines this computation with the specified computation, passing the * updated state from this computation to that computation and combining the * results of both using the specified function. */ export declare function zipWith_(self: Async, that: Async, f: (a: A, b: B) => C): Async; /** * Combines this computation with the specified computation, passing the * updated state from this computation to that computation and combining the * results of both into a tuple. * * @ets_data_first zip_ */ export declare function zip(that: Async): (self: Async) => Async>; /** * Combines this computation with the specified computation, passing the * updated state from this computation to that computation and combining the * results of both into a tuple. */ export declare function zip_(self: Async, that: Async): Async>; /** * Suspend a computation, useful in recursion */ export declare function suspend(f: () => Async): Async; /** * Lift a sync (non failable) computation */ export declare function succeedWith(f: () => A): Async; /** * Lift a sync (non failable) computation */ export declare function tryCatch(f: () => A, onThrow: (u: unknown) => E): Async; export declare function promise(promise: (onInterrupt: (f: () => void) => void) => Promise, onError: (u: unknown) => E): Async; export declare function unfailable(promise: (onInterrupt: (f: () => void) => void) => Promise): Async; export declare function done(exit: Exit): Async; export declare function tapError(f: (_: EA) => Async): (self: Async) => Async; export declare function sleep(ms: number): Async; export declare function delay(ms: number): (self: Async) => Async; export declare function fromEither(e: E.Either): Async | Async; /** * Compact the union produced by the result of f * * @ets_optimize identity */ export declare function unionFn>(_: (...args: ARGS) => Ret): (...args: ARGS) => Async, U._E, U._A>; /** * Compact the union * * @ets_optimize identity */ export declare function union>(_: Ret): Async, U._E, U._A>; /** * Get the A from an option */ export default function tryCatchOption_(ma: Option, onNone: () => E): Async | Async; /** * Get the A from an option * * @ets_data_first tryCatchOption_ */ export declare function tryCatchOption(onNone: () => E): (ma: Option) => Async | Async; //# sourceMappingURL=core.d.ts.map