import { Maybe } from "../Maybe"; import { Result } from "../Result"; export declare type IO = Succeed | Die | Fail | Suspend | Async | FlatMap; /** UIO is a type alias for IO, which represents an effect that cannot fail, but can succeed with an A. */ export declare type UIO = IO; declare type Succeed = { tag: "Succeed"; a: A; }; declare type Fail = { tag: "Fail"; e: E; }; declare type Die = { tag: "Die"; e: unknown; }; declare type Async = { tag: "Async"; onDone: (onError: (e: E) => unit, onSuccess: (a: A) => unit, onDie: (e: unknown) => unit) => unit; }; declare class Suspend { readonly lazy: () => IO; tag: "Suspend"; _E: E; _A: A; constructor(lazy: () => IO); } declare class FlatMap { readonly aToIOB: (a: A0) => IO; readonly ioA: IO; tag: "FlatMap"; _E: E; _A0: A0; _A: A; constructor(aToIOB: (a: A0) => IO, ioA: IO); } declare type unit = void; /** **succeed** constructs a success IO from the provided value. */ export declare const succeed: (a: A) => IO; /** **unit** represents an IO that successfully resolves to void. */ export declare const unit: IO; /** **fail** wraps a strictly-evaluated error value in an error IO. */ export declare const fail: (e: E) => IO; /** **die** constructs an IO that will die by throwing the given `e`. */ export declare const die: (e: E) => IO; /** **sync** wraps a lazily-evaluated value of type A in a success IO. */ export declare const sync: (lazy: () => A) => IO; /** **syncFail** wraps a lazily-evaluated value of type E in an error IO. */ export declare const syncFail: (lazy: () => E) => IO; /** **suspend** wraps a lazily-evaluated IO value in an IO. */ export declare const suspend: (lazy: () => IO) => IO; /** **async** creates an async IO value that is run by invoking a callback. Example: ```ts async((onF, onS) => onS(1)); async((onF, onS) => onF(new Error('Failed'))); async((onF, onS, onE) => onE(new Error('Failed'))); ``` */ export declare const async: (onDone: (onError: (e: E) => unit, onSuccess: (a: A) => unit, onDie: (e: unknown) => unit) => unit) => IO; /** IO.**fromMaybe** lifts an evaluated Maybe to an IO by providing a fallback E value to use when the Maybe is `Nothing`. */ export declare const fromMaybe: (fallback: E) => (ma: Maybe) => IO; /** IO.**fromNullable** lifts a nullable value to an IO by providing a fallback E value to use when the value is `null` or `undefined`. */ export declare const fromNullable: (fallback: E) => (a: A | null | undefined) => IO; /** IO.**fromResult** lifts an evaluated result value of type Result to an IO. */ export declare const fromResult: (result: Result) => IO; /** IO.**tryCatch** lifts a lazy function (() => A) that can throw an unknown exception to an IO. */ export declare const tryCatch: (f: () => A) => IO; /** IO.**fromPromise** lifts a lazyily-evaluated promise into an async IO value. */ export declare const fromPromise: (lazy: () => Promise) => IO; /** IO.**fromPromiseOrDie** lifts a lazyily-evaluated promise into an async IO value and eliminates the error channel */ export declare const fromPromiseOrDie: (lazy: () => Promise) => UIO; /** **sleep** creates an async IO that will sleep for the given millisecond duration. */ export declare const sleep: (duration: number) => IO; /** **ioify** lifts a node style callback function to one returning an `IO` */ export declare function ioify(f: (cb: (e: L | null | undefined, r?: R) => void) => void): () => IO; export declare function ioify(f: (a: A, cb: (e: L | null | undefined, r?: R) => void) => void): (a: A) => IO; export declare function ioify(f: (a: A, b: B, cb: (e: L | null | undefined, r?: R) => void) => void): (a: A, b: B) => IO; export declare function ioify(f: (a: A, b: B, c: C, cb: (e: L | null | undefined, r?: R) => void) => void): (a: A, b: B, c: C) => IO; export declare function ioify(f: (a: A, b: B, c: C, d: D, cb: (e: L | null | undefined, r?: R) => void) => void): (a: A, b: B, c: C, d: D) => IO; export declare function ioify(f: (a: A, b: B, c: C, d: D, e: E, cb: (e: L | null | undefined, r?: R) => void) => void): (a: A, b: B, c: C, d: D, e: E) => IO; /** **traverse** converts an Array to an IO> where each element of the array is ran through the given `f`. It is useful when you have an array of items you want to run an effect on each item without ending up with an Array>, instead having just one IO. */ export declare const traverse: (f: (a: A) => IO) => (args: A[]) => IO; /** **forEach** converts an Array to an IO> where each element of the array is ran through the given `f`. It is useful when you have an array of items you want to run an effect on each item without ending up with an Array>, instead having just one IO. */ export declare const forEach: (args: A[]) => (f: (a: A) => IO) => IO; /** IO.**lift** lifts a function of (A => B) into a function of (A => IO). */ export declare const lift: (f: (a: A) => B) => (a: A) => IO; /** **flatMap** applies an effectful function (A => IO) on the success channel to produce an IO. */ export declare const flatMap: (f: (a: A) => IO) => (io: IO) => IO; /** **flatMapW** applies an effectful function (A => IO) on the success channel to produce an IO growing the error channel with E1. */ export declare const flatMapW: (f: (a: A) => IO) => (io: IO) => IO; /** **map** applies a function (**A** => **B**) on an IO success channel to produce an IO. */ export declare const map: (f: (a: A) => B) => (io: IO) => IO; /** **handleError** applies a function (E => A) on the error channel to convert an error value to a success value, which serves to "clear" the error in the IO, making the error type `never`. */ export declare const handleError: (f: (e: E) => A) => (io: IO) => IO; /** **flatHandleError** applies an effectful function (E => IO) on the error channel to convert an error value to a success value, which serves to "clear" the error in the IO, making the error type `never`. */ export declare const flatHandleError: (f: (e: E) => IO) => (io: IO) => IO; /** **catchError** applies an effectful function (E => IO) on the error channel to produce an IO. */ export declare const catchError: (f: (e: E) => IO) => (io: IO) => IO; /** **mapError** applies a function (**E** => **E1**) on an IO<**E**, A> error channel to produce an IO<**E1**, A>. */ export declare const mapError: (f: (e: E) => E1) => (io: IO) => IO; /** IO.**biFlatMap** applies flatMap functions on both the success and failure channels of the IO. Equivalent to: ```ts io.flatMap(f).flatMapFailure(g); ``` */ export declare const biFlatMap: (g: (e: E) => IO, f: (a: A) => IO) => (io: IO) => IO; /** **bimap** applies map functions on both the success and error channels of the IO. */ export declare const bimap: (f: (e: E) => E1, g: (a: A) => B) => (io: IO) => IO; /** IO.**flatTap** applies a side-effect function (A => UIO) on an IO success channel, and propagates the A value unchanged. This is useful for doing things like logging the value inside the IO. */ export declare const flatTap: (f: (a: A) => UIO) => (io: IO) => IO; /** IO.**tap** applies a side-effect function (A => unit) on an IO success channel, and propagates the A value unchanged. This is useful for doing things like logging the value inside the IO. */ export declare const tap: (f: (a: A) => unit) => (io: IO) => IO; /** IO.**tapError** applies a side-effect function (E => unit) on an IO error channel, and propagates the E value unchanged. This is useful for doing things like logging the value inside the IO. */ export declare const tapError: (f: (e: E) => unit) => (io: IO) => IO; /** IO.**biFlatTap** applies a side-effect function to an IO to both channels, and propagates the values unchanged. This is useful for doing things like logging the value inside the IO.. */ export declare const biFlatTap: (f: (e: E) => UIO, g: (a: A) => UIO) => (io: IO) => IO; /** IO.**flatTapError** applies a side-effect function (E => UIO) on an IO error channel, and propagates the E value unchanged. This is useful for doing things like logging the error inside the IO. */ export declare const flatTapError: (f: (e: E) => UIO) => (io: IO) => IO; /** IO.**biTap** applies a side-effect function to both channels, and propagates the values unchanged. This is useful for doing things like logging the value inside the IO. */ export declare const biTap: (f: (e: E) => unit, g: (a: A) => unit) => (io: IO) => IO; /** IO.**orDie** will throw the E value if ran on a failed IO and will eliminate the E type completely resulting in an IO. This is useful for dealing with exceptions that cannot be recovered in the IO context. */ export declare const orDie: (io: IO) => UIO; /** IO.**toUnit** converts a successful IO to void */ export declare const toUnit: (io: IO) => IO; /** IO.**nothing** converts a successful IO to void and kills a failed IO Syntaxical sugar for: `IO.toUnit.orDie` */ export declare const nothing: (io: IO) => UIO; /** IO.**filter** interrogates the success channel with a given predicate which when fails converts the IO to an error with the given fallback */ export declare const filter: (p: (a: A) => boolean, e: E) => (io: IO) => IO; /** IO.**filterWith** interrogates the success channel with a given predicate which when fails converts the IO to an error using the given `f` to produce a newly typed error E1 */ export declare const filterWith: (p: (a: A) => boolean, f: (a: A) => E1) => (io: IO) => IO; /** IO.**refine** runs the given refinement function on the success channel to allow the `A` to be changed to `B`. If refinement fails the IO is converted to an error with the given fallback */ export declare const refine: (p: (a: A) => a is B, e: E | E1) => (io: IO) => IO; /** IO.**refineErrorOrDie** runs the given refinement function on the error channel to allow the `E` to be changed to `E1`. IO dies if the result of the given refinement function is `Maybe.nothing`. */ export declare const refineErrorOrDie: (f: (e: E) => Maybe) => (io: IO) => IO; /** IO.**merge** joins the error and success channel into a success UIO. This is useful when you need to work over a success value and both A and E have a shared super type. */ export declare const merge: (io: IO) => UIO; /** IO.**fold** converts the IO to a UIO that cannot fail by running the success and error channels over the given functions and merges the results */ export declare const fold: (f: (e: E) => B, g: (a: A) => B) => (io: IO) => UIO; /** **flip** Flips the values between the success and error channels. */ export declare const flip: (io: IO) => IO; /** **delay** delays the exectuion of a successful IO by the giving time in milliseconds */ export declare const delay: (duration: number) => (io: IO) => IO; /** **unsafeRunAsync** runs the effectual IO and applies the given onFailure and onSuccess callbacks to the outcome of the IO depending on the channel the IO ends in and if the effect dies the onDie callback is invoked. This function should be run "at the edge of the world" to evaluate the suspended side-effects in the IO. */ export declare const unsafeRunAsync: (onFailure: (e: E) => unit, onSuccess: (a: A) => unit, onDie: (e: unknown) => unit) => (io: IO) => unit; /** **unsafeRunAsyncOrDie** runs the effectual IO and applies the given onFailure and onSuccess callbacks to the outcome of the IO depending on the channel the IO ends in. _Note:_ Should the effect die then this error will be thrown. This function should be run "at the edge of the world" to evaluate the suspended side-effects in the IO. */ export declare const unsafeRunAsyncOrDie: (onFailure: (e: E) => unit, onSuccess: (a: A) => unit) => (io: IO) => unit; /** IO.**toPromise** runs the effectual IO and lifts the outcome into a `Promise`. In doing so it throws away the failure channel (E) type information. This function should be run "at the edge of the world" to evaluate the suspended side-effects in the IO. */ export declare const toPromise: (io: IO) => Promise; export declare class GenIO { readonly op: IO; constructor(op: IO); [Symbol.iterator](): Generator, A, any>; } export declare const gen: , AEff>(f: (i: (_: IO) => GenIO) => Generator) => IO<_E, AEff>; export declare type _E = T extends Fail | Suspend | Async | FlatMap ? E : never; export {};