// ets_tracing: off import type * as Tp from "../Collections/Immutable/Tuple/index.js" import type { Either } from "../Either/core.js" import { pipe } from "../Function/index.js" import type { _A, _E, _R, HasUnify } from "../Utils/index.js" import * as X from "../XPure/index.js" export interface Sync extends X.XPure, HasUnify {} export interface UIO extends Sync {} export interface RIO extends Sync {} export interface IO extends Sync {} /** * 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 const chain: ( f: (a: A) => Sync ) => (self: Sync) => Sync = X.chain /** * 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 const chain_: ( self: Sync, f: (a: A) => Sync ) => Sync = X.chain_ /** * Returns a computation that effectfully "peeks" at the success of this one. * * @ets_data_first tap_ */ export const tap: ( f: (a: A) => Sync ) => (self: Sync) => Sync = X.tap /** * Returns a computation that effectfully "peeks" at the success of this one. */ export const tap_: ( self: Sync, f: (a: A) => Sync ) => Sync = X.tap_ /** * Constructs a computation that always succeeds with the specified value, * passing the state through unchanged. */ export const succeed = (a: A): Sync => X.succeed(a) /** * Constructs a computation that always succeeds with the specified value, * passing the state through unchanged. */ export const fail: (a: E) => Sync = X.fail /** * 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 const map_: (self: Sync, f: (a: A) => B) => Sync = X.map_ /** * 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 const map: ( f: (a: A) => B ) => (self: Sync) => Sync = X.map /** * 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 const foldM_: ( self: Sync, failure: (e: E) => Sync, success: (a: A) => Sync ) => Sync = X.foldM_ /** * 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 const foldM: ( failure: (e: E) => Sync, success: (a: A) => Sync ) => (self: Sync) => Sync = X.foldM /** * 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`. * * @ets_data_first fold_ */ export const fold: ( failure: (e: E) => B, success: (a: A) => C ) => (self: Sync) => Sync = X.fold /** * 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 const fold_: ( self: Sync, failure: (e: E) => B, success: (a: A) => C ) => Sync = X.fold_ /** * Recovers from all errors. * * @ets_data_first catchAll_ */ export const catchAll: ( failure: (e: E) => Sync ) => (self: Sync) => Sync = X.catchAll /** * Recovers from all errors. */ export const catchAll_: ( self: Sync, failure: (e: E) => Sync ) => Sync = X.catchAll_ /** * Returns a computation whose error and success channels have been mapped * by the specified functions, `f` and `g`. * * @ets_data_first bimap_ */ export const bimap: ( f: (e: E) => E1, g: (a: A) => A1 ) => (self: Sync) => Sync = X.bimap /** * Returns a computation whose error and success channels have been mapped * by the specified functions, `f` and `g`. */ export const bimap_: ( self: Sync, f: (e: E) => E1, g: (a: A) => A1 ) => Sync = X.bimap_ /** * Transforms the error type of this computation with the specified * function. * * @ets_data_first mapError_ */ export const mapError: ( f: (e: E) => E1 ) => (self: Sync) => Sync = X.mapError /** * Transforms the error type of this computation with the specified * function. */ export const mapError_: ( self: Sync, f: (e: E) => E1 ) => Sync = X.mapError_ /** * Constructs a computation that always returns the `Unit` value, passing the * state through unchanged. */ export const unit = succeed(undefined) /** * Transforms the initial state of this computation` with the specified * function. */ export const provideSome: ( f: (s: R0) => R1 ) => (self: Sync) => Sync = X.provideSome /** * Provides some of the environment required to run this effect, * leaving the remainder `R0` and combining it automatically using spread. */ export const provide: ( r: R ) => (next: Sync) => Sync = X.provide /** * Provides this computation with its required environment. * * @ets_data_first provideAll_ */ export const provideAll: ( r: R ) => (self: Sync) => Sync = X.provideAll /** * Provides this computation with its required environment. */ export const provideAll_: (self: Sync, r: R) => Sync = X.provideAll_ /** * Access the environment monadically */ export const accessM: (f: (_: R) => Sync) => Sync = X.accessM /** * Access the environment with the function f */ export const access: (f: (_: R) => A) => Sync = X.access /** * Access the environment */ export const environment = (): Sync => X.environment() /** * 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 const either: (self: Sync) => Sync> = X.either /** * Executes this computation and returns its value, if it succeeds, but * otherwise executes the specified computation. * * @ets_data_first orElseEither_ */ export const orElseEither: ( that: () => Sync ) => (self: Sync) => Sync> = X.orElseEither /** * Executes this computation and returns its value, if it succeeds, but * otherwise executes the specified computation. */ export const orElseEither_: ( self: Sync, that: () => Sync ) => Sync> = X.orElseEither_ /** * 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 const zipWith: ( that: Sync, f: (a: A, b: B) => C ) => (self: Sync) => Sync = X.zipWith /** * 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 const zipWith_: ( self: Sync, that: Sync, f: (a: A, b: B) => C ) => Sync = X.zipWith_ /** * 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 const zip: ( that: Sync ) => (self: Sync) => Sync> = X.zip /** * 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 const zip_: ( self: Sync, that: Sync ) => Sync> = X.zip_ /** * Suspend a computation, useful in recursion */ export const suspend: (f: () => Sync) => Sync = X.suspend /** * Lift a sync (non failable) computation */ export const succeedWith: (f: () => A) => Sync = X.succeedWith /** * Lift a sync (non failable) computation */ export const tryCatch: ( onThrow: (u: unknown) => E ) => (f: () => A) => Sync = X.tryCatch /** * Runs this computation returning either an error of type E or a success of type A */ export const runEither: (self: Sync) => Either = X.runEither /** * Runs this computation returning either an error of type E or a success of type A */ export const runEitherEnv: (r: R) => (self: Sync) => Either = (r) => (x) => pipe(x, provideAll(r), runEither) /** * Runs this non failable computation returning a success of type A */ export const run: (self: Sync) => A = X.run /** * Compact the union produced by the result of f * * @ets_optimize identity */ export function unionFn>( _: (...args: ARGS) => Ret ): (...args: ARGS) => Sync<_R, _E, _A> { return _ as any } /** * Compact the union * * @ets_optimize identity */ export function union>( _: Ret ): Sync<_R, _E, _A> { return _ as any }