import type * as Context from "@effect/data/Context"; import type * as Either from "@effect/data/Either"; import type { LazyArg } from "@effect/data/Function"; import type { TypeLambda } from "@effect/data/HKT"; import type * as Option from "@effect/data/Option"; import type { Pipeable } from "@effect/data/Pipeable"; import type { Predicate, Refinement } from "@effect/data/Predicate"; import type * as Unify from "@effect/data/Unify"; import * as Cause from "@effect/io/Cause"; import type * as Effect from "@effect/io/Effect"; import type * as FiberId from "@effect/io/FiberId"; /** * @since 1.0.0 * @category symbols */ export declare const STMTypeId: unique symbol; /** * @since 1.0.0 * @category symbols */ export type STMTypeId = typeof STMTypeId; /** * `STM` represents an effect that can be performed transactionally, * resulting in a failure `E` or a value `A` that may require an environment * `R` to execute. * * Software Transactional Memory is a technique which allows composition of * arbitrary atomic operations. It is the software analog of transactions in * database systems. * * The API is lifted directly from the Haskell package Control.Concurrent.STM * although the implementation does not resemble the Haskell one at all. * * See http://hackage.haskell.org/package/stm-2.5.0.0/docs/Control-Concurrent-STM.html * * STM in Haskell was introduced in: * * Composable memory transactions, by Tim Harris, Simon Marlow, Simon Peyton * Jones, and Maurice Herlihy, in ACM Conference on Principles and Practice of * Parallel Programming 2005. * * See https://www.microsoft.com/en-us/research/publication/composable-memory-transactions/ * * See also: * Lock Free Data Structures using STMs in Haskell, by Anthony Discolo, Tim * Harris, Simon Marlow, Simon Peyton Jones, Satnam Singh) FLOPS 2006: Eighth * International Symposium on Functional and Logic Programming, Fuji Susono, * JAPAN, April 2006 * * https://www.microsoft.com/en-us/research/publication/lock-free-data-structures-using-stms-in-haskell/ * * The implemtation is based on the ZIO STM module, while JS environments have * no race conditions from multiple threads STM provides greater benefits for * synchronization of Fibers and transactional data-types can be quite useful. * * @since 1.0.0 * @category models */ export interface STM extends Effect.Effect, STM.Variance, Pipeable { [Unify.typeSymbol]?: unknown; [Unify.unifySymbol]?: STMUnify; [Unify.blacklistSymbol]?: STMUnifyBlacklist; } /** * @since 1.0.0 * @category models */ export interface STMUnify extends Effect.EffectUnify { STM?: () => A[Unify.typeSymbol] extends STM | infer _ ? STM : never; } /** * @category models * @since 1.0.0 */ export interface STMUnifyBlacklist extends Effect.EffectUnifyBlacklist { Effect?: true; } /** * @category type lambdas * @since 1.0.0 */ export interface STMTypeLambda extends TypeLambda { readonly type: STM; } /** * @since 1.0.0 * @category models */ declare module "@effect/data/Context" { interface Tag extends STM { } } /** * @since 1.0.0 * @category models */ declare module "@effect/data/Either" { interface Left extends STM { readonly _tag: "Left"; } interface Right extends STM { readonly _tag: "Right"; } } /** * @since 1.0.0 * @category models */ declare module "@effect/data/Option" { interface None extends STM { readonly _tag: "None"; } interface Some extends STM { readonly _tag: "Some"; } } /** * @since 1.0.0 */ export declare namespace STM { /** * @since 1.0.0 * @category models */ interface Variance { readonly [STMTypeId]: { readonly _R: (_: never) => R; readonly _E: (_: never) => E; readonly _A: (_: never) => A; }; } } /** * @category models * @since 1.0.0 */ export interface STMGen { readonly _R: () => R; readonly _E: () => E; readonly _A: () => A; readonly value: STM; [Symbol.iterator](): Generator, A>; } /** * Returns `true` if the provided value is an `STM`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isSTM: (u: unknown) => u is STM; /** * Treats the specified `acquire` transaction as the acquisition of a * resource. The `acquire` transaction will be executed interruptibly. If it * is a success and is committed the specified `release` workflow will be * executed uninterruptibly as soon as the `use` workflow completes execution. * * @since 1.0.0 * @category constructors */ export declare const acquireUseRelease: { (use: (resource: A) => STM, release: (resource: A) => STM): (acquire: STM) => Effect.Effect; (acquire: STM, use: (resource: A) => STM, release: (resource: A) => STM): Effect.Effect; }; /** * @since 1.0.0 * @category utils */ export declare namespace All { type STMAny = STM; type ReturnTuple>, Discard extends boolean> = STM infer R; }; }] ? R : never, T[number] extends never ? never : [T[number]] extends [{ [STMTypeId]: { _E: (_: never) => infer E; }; }] ? E : never, Discard extends true ? void : T[number] extends never ? [] : { -readonly [K in keyof T]: [T[K]] extends [STM] ? A : never; }> extends infer X ? X : never; type ReturnIterable, Discard extends boolean> = [T] extends [ Iterable> ] ? STM> : never; type ReturnObject, Discard extends boolean> = STM infer R; }; }] ? R : never, keyof T extends never ? never : [T[keyof T]] extends [{ [STMTypeId]: { _E: (_: never) => infer E; }; }] ? E : never, Discard extends true ? void : { -readonly [K in keyof T]: [T[K]] extends [STM.Variance] ? A : never; }>; /** * @since 1.0.0 * @category utils */ type Options = { readonly discard?: boolean; }; type IsDiscard = [Extract] extends [never] ? false : true; type Narrow = (A extends [] ? [] : never) | A; /** * @since 1.0.0 * @category utils */ interface Signature { | Iterable | Record, O extends Options>(arg: Narrow, options?: O): [Arg] extends [ReadonlyArray] ? ReturnTuple> : [Arg] extends [Iterable] ? ReturnIterable> : [Arg] extends [Record] ? ReturnObject> : never; } } /** * Runs all the provided transactional effects in sequence respecting the * structure provided in input. * * Supports multiple arguments, a single argument tuple / array or record / * struct. * * @since 1.0.0 * @category constructors */ export declare const all: All.Signature; /** * Maps the success value of this effect to the specified constant value. * * @since 1.0.0 * @category mapping */ export declare const as: { (value: A2): (self: STM) => STM; (self: STM, value: A2): STM; }; /** * Maps the success value of this effect to an optional value. * * @since 1.0.0 * @category mapping */ export declare const asSome: (self: STM) => STM>; /** * Maps the error value of this effect to an optional value. * * @since 1.0.0 * @category mapping */ export declare const asSomeError: (self: STM) => STM, A>; /** * This function maps the success value of an `STM` to `void`. If the original * `STM` succeeds, the returned `STM` will also succeed. If the original `STM` * fails, the returned `STM` will fail with the same error. * * @since 1.0.0 * @category mapping */ export declare const asUnit: (self: STM) => STM; /** * Creates an `STM` value from a partial (but pure) function. * * @since 1.0.0 * @category constructors */ export declare const attempt: (evaluate: LazyArg) => STM; /** * Recovers from all errors. * * @since 1.0.0 * @category error handling */ export declare const catchAll: { (f: (e: E) => STM): (self: STM) => STM; (self: STM, f: (e: E) => STM): STM; }; /** * Recovers from some or all of the error cases. * * @since 1.0.0 * @category error handling */ export declare const catchSome: { (pf: (error: E) => Option.Option>): (self: STM) => STM; (self: STM, pf: (error: E) => Option.Option>): STM; }; /** * Recovers from the specified tagged error. * * @since 1.0.0 * @category error handling */ export declare const catchTag: { (k: K, f: (e: Extract) => STM): (self: STM) => STM, A1 | A>; (self: STM, k: K, f: (e: Extract) => STM): STM, A | A1>; }; /** * Recovers from multiple tagged errors. * * @since 1.0.0 * @category error handling */ export declare const catchTags: { ) => STM); }>(cases: Cases): (self: STM) => STM) => STM ? R : never; }[keyof Cases], Exclude | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? E : never; }[keyof Cases], A | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? A : never; }[keyof Cases]>; ) => STM); }>(self: STM, cases: Cases): STM) => STM ? R : never; }[keyof Cases], Exclude | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? E : never; }[keyof Cases], A | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? A : never; }[keyof Cases]>; }; /** * Checks the condition, and if it's true, returns unit, otherwise, retries. * * @since 1.0.0 * @category constructors */ export declare const check: (predicate: LazyArg) => STM; /** * Simultaneously filters and maps the value produced by this effect. * * @since 1.0.0 * @category mutations */ export declare const collect: { (pf: (a: A) => Option.Option): (self: STM) => STM; (self: STM, pf: (a: A) => Option.Option): STM; }; /** * Simultaneously filters and maps the value produced by this effect. * * @since 1.0.0 * @category mutations */ export declare const collectSTM: { (pf: (a: A) => Option.Option>): (self: STM) => STM; (self: STM, pf: (a: A) => Option.Option>): STM; }; /** * Commits this transaction atomically. * * @since 1.0.0 * @category destructors */ export declare const commit: (self: STM) => Effect.Effect; /** * Commits this transaction atomically, regardless of whether the transaction * is a success or a failure. * * @since 1.0.0 * @category destructors */ export declare const commitEither: (self: STM) => Effect.Effect; /** * Similar to Either.cond, evaluate the predicate, return the given A as * success if predicate returns true, and the given E as error otherwise * * @since 1.0.0 * @category constructors */ export declare const cond: (predicate: LazyArg, error: LazyArg, result: LazyArg) => STM; /** * Retrieves the environment inside an stm. * * @since 1.0.0 * @category constructors */ export declare const context: () => STM>; /** * Accesses the environment of the transaction to perform a transaction. * * @since 1.0.0 * @category constructors */ export declare const contextWith: (f: (environment: Context.Context) => R) => STM; /** * Accesses the environment of the transaction to perform a transaction. * * @since 1.0.0 * @category constructors */ export declare const contextWithSTM: (f: (environment: Context.Context) => STM) => STM; /** * Transforms the environment being provided to this effect with the specified * function. * * @since 1.0.0 * @category context */ export declare const mapInputContext: { (f: (context: Context.Context) => Context.Context): (self: STM) => STM; (self: STM, f: (context: Context.Context) => Context.Context): STM; }; /** * Fails the transactional effect with the specified defect. * * @since 1.0.0 * @category constructors */ export declare const die: (defect: unknown) => STM; /** * Kills the fiber running the effect with a `Cause.RuntimeException` that * contains the specified message. * * @since 1.0.0 * @category constructors */ export declare const dieMessage: (message: string) => STM; /** * Fails the transactional effect with the specified lazily evaluated defect. * * @since 1.0.0 * @category constructors */ export declare const dieSync: (evaluate: LazyArg) => STM; /** * Converts the failure channel into an `Either`. * * @since 1.0.0 * @category mutations */ export declare const either: (self: STM) => STM>; /** * Executes the specified finalization transaction whether or not this effect * succeeds. Note that as with all STM transactions, if the full transaction * fails, everything will be rolled back. * * @since 1.0.0 * @category finalization */ export declare const ensuring: { (finalizer: STM): (self: STM) => STM; (self: STM, finalizer: STM): STM; }; /** * Returns an effect that ignores errors and runs repeatedly until it * eventually succeeds. * * @since 1.0.0 * @category mutations */ export declare const eventually: (self: STM) => STM; /** * Determines whether all elements of the `Iterable` satisfy the effectual * predicate. * * @since 1.0.0 * @category constructors */ export declare const every: { (predicate: (a: A) => STM): (iterable: Iterable) => STM; (iterable: Iterable, predicate: (a: A) => STM): STM; }; /** * Determines whether any element of the `Iterable[A]` satisfies the effectual * predicate `f`. * * @since 1.0.0 * @category constructors */ export declare const exists: { (predicate: (a: A) => STM): (iterable: Iterable) => STM; (iterable: Iterable, predicate: (a: A) => STM): STM; }; /** * Fails the transactional effect with the specified error. * * @since 1.0.0 * @category constructors */ export declare const fail: (error: E) => STM; /** * Fails the transactional effect with the specified lazily evaluated error. * * @since 1.0.0 * @category constructors */ export declare const failSync: (evaluate: LazyArg) => STM; /** * Returns the fiber id of the fiber committing the transaction. * * @since 1.0.0 * @category constructors */ export declare const fiberId: STM; /** * Filters the collection using the specified effectual predicate. * * @since 1.0.0 * @category constructors */ export declare const filter: { (predicate: (a: A) => STM): (iterable: Iterable) => STM>; (iterable: Iterable, predicate: (a: A) => STM): STM>; }; /** * Filters the collection using the specified effectual predicate, removing * all elements that satisfy the predicate. * * @since 1.0.0 * @category constructors */ export declare const filterNot: { (predicate: (a: A) => STM): (iterable: Iterable) => STM>; (iterable: Iterable, predicate: (a: A) => STM): STM>; }; /** * Dies with specified defect if the predicate fails. * * @since 1.0.0 * @category filtering */ export declare const filterOrDie: { (refinement: Refinement, defect: LazyArg): (self: STM) => STM; (predicate: Predicate, defect: LazyArg): (self: STM) => STM; (self: STM, refinement: Refinement, defect: LazyArg): STM; (self: STM, predicate: Predicate, defect: LazyArg): STM; }; /** * Dies with a `Cause.RuntimeException` having the specified message if the * predicate fails. * * @since 1.0.0 * @category filtering */ export declare const filterOrDieMessage: { (refinement: Refinement, message: string): (self: STM) => STM; (predicate: Predicate, message: string): (self: STM) => STM; (self: STM, refinement: Refinement, message: string): STM; (self: STM, predicate: Predicate, message: string): STM; }; /** * Supplies `orElse` if the predicate fails. * * @since 1.0.0 * @category filtering */ export declare const filterOrElse: { (refinement: Refinement, orElse: (a: X) => STM): (self: STM) => STM; (predicate: Predicate, orElse: (a: Y) => STM): (self: STM) => STM; (self: STM, refinement: Refinement, orElse: (a: X) => STM): STM; (self: STM, predicate: Predicate, orElse: (a: Y) => STM): STM; }; /** * Fails with the specified error if the predicate fails. * * @since 1.0.0 * @category filtering */ export declare const filterOrFail: { (refinement: Refinement, orFailWith: (a: X) => E2): (self: STM) => STM; (predicate: Predicate, orFailWith: (a: Y) => E2): (self: STM) => STM; (self: STM, refinement: Refinement, orFailWith: (a: X) => E2): STM; (self: STM, predicate: Predicate, orFailWith: (a: Y) => E2): STM; }; /** * Feeds the value produced by this effect to the specified function, and then * runs the returned effect as well to produce its results. * * @since 1.0.0 * @category sequencing */ export declare const flatMap: { (f: (a: A) => STM): (self: STM) => STM; (self: STM, f: (a: A) => STM): STM; }; /** * Flattens out a nested `STM` effect. * * @since 1.0.0 * @category sequencing */ export declare const flatten: (self: STM>) => STM; /** * Flips the success and failure channels of this transactional effect. This * allows you to use all methods on the error channel, possibly before * flipping back. * * @since 1.0.0 * @category mutations */ export declare const flip: (self: STM) => STM; /** * Swaps the error/value parameters, applies the function `f` and flips the * parameters back * * @since 1.0.0 * @category mutations */ export declare const flipWith: { (f: (stm: STM) => STM): (self: STM) => STM; (self: STM, f: (stm: STM) => STM): STM; }; /** * Folds over the `STM` effect, handling both failure and success, but not * retry. * * @since 1.0.0 * @category folding */ export declare const match: { (options: { readonly onFailure: (error: E) => A2; readonly onSuccess: (value: A) => A3; }): (self: STM) => STM; (self: STM, options: { readonly onFailure: (error: E) => A2; readonly onSuccess: (value: A) => A3; }): STM; }; /** * Effectfully folds over the `STM` effect, handling both failure and success. * * @since 1.0.0 * @category folding */ export declare const matchSTM: { (options: { readonly onFailure: (e: E) => STM; readonly onSuccess: (a: A) => STM; }): (self: STM) => STM; (self: STM, options: { readonly onFailure: (e: E) => STM; readonly onSuccess: (a: A) => STM; }): STM; }; /** * Applies the function `f` to each element of the `Iterable` and returns * a transactional effect that produces a new `Chunk`. * * @since 1.0.0 * @category traversing */ export declare const forEach: { (f: (a: A) => STM, options?: { readonly discard?: false; }): (elements: Iterable) => STM>; (f: (a: A) => STM, options: { readonly discard: true; }): (elements: Iterable) => STM; (elements: Iterable, f: (a: A) => STM, options?: { readonly discard?: false; }): STM>; (elements: Iterable, f: (a: A) => STM, options: { readonly discard: true; }): STM; }; /** * Lifts an `Either` into a `STM`. * * @since 1.0.0 * @category constructors */ export declare const fromEither: (either: Either.Either) => STM; /** * Lifts an `Option` into a `STM`. * * @since 1.0.0 * @category constructors */ export declare const fromOption: (option: Option.Option) => STM, A>; /** * @since 1.0.0 * @category models */ export interface Adapter { (self: STM): STMGen; (a: A, ab: (a: A) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: F) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (g: H) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => T, tu: (s: T) => STM<_R, _E, _A>): STMGen<_R, _E, _A>; } /** * @since 1.0.0 * @category constructors */ export declare const gen: , AEff>(f: (resume: Adapter) => Generator) => STM<[ Eff ] extends [never] ? never : [Eff] extends [STMGen] ? R : never, [ Eff ] extends [never] ? never : [Eff] extends [STMGen] ? E : never, AEff>; /** * Returns a successful effect with the head of the list if the list is * non-empty or fails with the error `None` if the list is empty. * * @since 1.0.0 * @category getters */ export declare const head: (self: STM>) => STM, A>; declare const if_: { (options: { readonly onTrue: STM; readonly onFalse: STM; }): (self: boolean | STM) => STM; (self: boolean, options: { readonly onTrue: STM; readonly onFalse: STM; }): STM; (self: STM, options: { readonly onTrue: STM; readonly onFalse: STM; }): STM; }; export { /** * Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise. * * @since 1.0.0 * @category mutations */ if_ as if }; /** * Returns a new effect that ignores the success or failure of this effect. * * @since 1.0.0 * @category mutations */ export declare const ignore: (self: STM) => STM; /** * Interrupts the fiber running the effect. * * @since 1.0.0 * @category constructors */ export declare const interrupt: STM; /** * Interrupts the fiber running the effect with the specified `FiberId`. * * @since 1.0.0 * @category constructors */ export declare const interruptAs: (fiberId: FiberId.FiberId) => STM; /** * Returns whether this transactional effect is a failure. * * @since 1.0.0 * @category getters */ export declare const isFailure: (self: STM) => STM; /** * Returns whether this transactional effect is a success. * * @since 1.0.0 * @category getters */ export declare const isSuccess: (self: STM) => STM; /** * Iterates with the specified transactional function. The moral equivalent * of: * * ```ts * const s = initial * * while (cont(s)) { * s = body(s) * } * * return s * ``` * * @since 1.0.0 * @category constructors */ export declare const iterate: (initial: Z, options: { readonly while: (z: Z) => boolean; readonly body: (z: Z) => STM; }) => STM; /** * Loops with the specified transactional function, collecting the results * into a list. The moral equivalent of: * * ```ts * const as = [] * let s = initial * * while (cont(s)) { * as.push(body(s)) * s = inc(s) * } * * return as * ``` * * @since 1.0.0 * @category constructors */ export declare const loop: { (initial: Z, options: { readonly while: (z: Z) => boolean; readonly step: (z: Z) => Z; readonly body: (z: Z) => STM; readonly discard?: false; }): STM>; (initial: Z, options: { readonly while: (z: Z) => boolean; readonly step: (z: Z) => Z; readonly body: (z: Z) => STM; readonly discard: true; }): STM; }; /** * Maps the value produced by the effect. * * @since 1.0.0 * @category mapping */ export declare const map: { (f: (a: A) => B): (self: STM) => STM; (self: STM, f: (a: A) => B): STM; }; /** * Maps the value produced by the effect with the specified function that may * throw exceptions but is otherwise pure, translating any thrown exceptions * into typed failed effects. * * @since 1.0.0 * @category mapping */ export declare const mapAttempt: { (f: (a: A) => B): (self: STM) => STM; (self: STM, f: (a: A) => B): STM; }; /** * Returns an `STM` effect whose failure and success channels have been mapped * by the specified pair of functions, `f` and `g`. * * @since 1.0.0 * @category mapping */ export declare const mapBoth: { (options: { readonly onFailure: (error: E) => E2; readonly onSuccess: (value: A) => A2; }): (self: STM) => STM; (self: STM, options: { readonly onFailure: (error: E) => E2; readonly onSuccess: (value: A) => A2; }): STM; }; /** * Maps from one error type to another. * * @since 1.0.0 * @category mapping */ export declare const mapError: { (f: (error: E) => E2): (self: STM) => STM; (self: STM, f: (error: E) => E2): STM; }; /** * Returns a new effect where the error channel has been merged into the * success channel to their common combined type. * * @since 1.0.0 * @category mutations */ export declare const merge: (self: STM) => STM; /** * Merges an `Iterable` to a single `STM`, working sequentially. * * @since 1.0.0 * @category constructors */ export declare const mergeAll: { (zero: A2, f: (a2: A2, a: A) => A2): (iterable: Iterable>) => STM; (iterable: Iterable>, zero: A2, f: (a2: A2, a: A) => A2): STM; }; /** * Returns a new effect where boolean value of this effect is negated. * * @since 1.0.0 * @category mutations */ export declare const negate: (self: STM) => STM; /** * Requires the option produced by this value to be `None`. * * @since 1.0.0 * @category mutations */ export declare const none: (self: STM>) => STM, void>; /** * Converts the failure channel into an `Option`. * * @since 1.0.0 * @category mutations */ export declare const option: (self: STM) => STM>; /** * Translates `STM` effect failure into death of the fiber, making all * failures unchecked and not a part of the type of the effect. * * @since 1.0.0 * @category error handling */ export declare const orDie: (self: STM) => STM; /** * Keeps none of the errors, and terminates the fiber running the `STM` effect * with them, using the specified function to convert the `E` into a defect. * * @since 1.0.0 * @category error handling */ export declare const orDieWith: { (f: (error: E) => unknown): (self: STM) => STM; (self: STM, f: (error: E) => unknown): STM; }; /** * Tries this effect first, and if it fails or retries, tries the other * effect. * * @since 1.0.0 * @category error handling */ export declare const orElse: { (that: LazyArg>): (self: STM) => STM; (self: STM, that: LazyArg>): STM; }; /** * Returns a transactional effect that will produce the value of this effect * in left side, unless it fails or retries, in which case, it will produce * the value of the specified effect in right side. * * @since 1.0.0 * @category error handling */ export declare const orElseEither: { (that: LazyArg>): (self: STM) => STM>; (self: STM, that: LazyArg>): STM>; }; /** * Tries this effect first, and if it fails or retries, fails with the * specified error. * * @since 1.0.0 * @category error handling */ export declare const orElseFail: { (error: LazyArg): (self: STM) => STM; (self: STM, error: LazyArg): STM; }; /** * Returns an effect that will produce the value of this effect, unless it * fails with the `None` value, in which case it will produce the value of the * specified effect. * * @since 1.0.0 * @category error handling */ export declare const orElseOptional: { (that: LazyArg, A2>>): (self: STM, A>) => STM, A2 | A>; (self: STM, A>, that: LazyArg, A2>>): STM, A | A2>; }; /** * Tries this effect first, and if it fails or retries, succeeds with the * specified value. * * @since 1.0.0 * @category error handling */ export declare const orElseSucceed: { (value: LazyArg): (self: STM) => STM; (self: STM, value: LazyArg): STM; }; /** * Tries this effect first, and if it enters retry, then it tries the other * effect. This is an equivalent of Haskell's orElse. * * @since 1.0.0 * @category error handling */ export declare const orTry: { (that: LazyArg>): (self: STM) => STM; (self: STM, that: LazyArg>): STM; }; /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in a tupled fashion. * * @since 1.0.0 * @category traversing */ export declare const partition: { (f: (a: A) => STM): (elements: Iterable) => STM, Array]>; (elements: Iterable, f: (a: A) => STM): STM, Array]>; }; /** * Provides the transaction its required environment, which eliminates its * dependency on `R`. * * @since 1.0.0 * @category context */ export declare const provideContext: { (env: Context.Context): (self: STM) => STM; (self: STM, env: Context.Context): STM; }; /** * Splits the context into two parts, providing one part using the * specified layer and leaving the remainder `R0`. * * @since 1.0.0 * @category context */ export declare const provideSomeContext: { (context: Context.Context): (self: STM) => STM, E, A>; (self: STM, context: Context.Context): STM, E, A>; }; /** * Provides the effect with the single service it requires. If the transactional * effect requires more than one service use `provideEnvironment` instead. * * @since 1.0.0 * @category context */ export declare const provideService: { >(tag: T, resource: Context.Tag.Service): (self: STM) => STM>, E, A>; >(self: STM, tag: T, resource: Context.Tag.Service): STM>, E, A>; }; /** * Provides the effect with the single service it requires. If the transactional * effect requires more than one service use `provideEnvironment` instead. * * @since 1.0.0 * @category context */ export declare const provideServiceSTM: { , R1, E1>(tag: T, stm: STM>): (self: STM) => STM>, E1 | E, A>; , R1, E1>(self: STM, tag: T, stm: STM>): STM>, E | E1, A>; }; /** * Folds an `Iterable` using an effectual function f, working sequentially * from left to right. * * @since 1.0.0 * @category constructors */ export declare const reduce: { (zero: S, f: (s: S, a: A) => STM): (iterable: Iterable) => STM; (iterable: Iterable, zero: S, f: (s: S, a: A) => STM): STM; }; /** * Reduces an `Iterable` to a single `STM`, working sequentially. * * @since 1.0.0 * @category constructors */ export declare const reduceAll: { (initial: STM, f: (x: A, y: A) => A): (iterable: Iterable>) => STM; (iterable: Iterable>, initial: STM, f: (x: A, y: A) => A): STM; }; /** * Folds an `Iterable` using an effectual function f, working sequentially * from right to left. * * @since 1.0.0 * @category constructors */ export declare const reduceRight: { (zero: S, f: (s: S, a: A) => STM): (iterable: Iterable) => STM; (iterable: Iterable, zero: S, f: (s: S, a: A) => STM): STM; }; /** * Keeps some of the errors, and terminates the fiber with the rest. * * @since 1.0.0 * @category mutations */ export declare const refineOrDie: { (pf: (error: E) => Option.Option): (self: STM) => STM; (self: STM, pf: (error: E) => Option.Option): STM; }; /** * Keeps some of the errors, and terminates the fiber with the rest, using the * specified function to convert the `E` into a `Throwable`. * * @since 1.0.0 * @category mutations */ export declare const refineOrDieWith: { (pf: (error: E) => Option.Option, f: (error: E) => unknown): (self: STM) => STM; (self: STM, pf: (error: E) => Option.Option, f: (error: E) => unknown): STM; }; /** * Fail with the returned value if the `PartialFunction` matches, otherwise * continue with our held value. * * @since 1.0.0 * @category mutations */ export declare const reject: { (pf: (a: A) => Option.Option): (self: STM) => STM; (self: STM, pf: (a: A) => Option.Option): STM; }; /** * Continue with the returned computation if the specified partial function * matches, translating the successful match into a failure, otherwise continue * with our held value. * * @since 1.0.0 * @category mutations */ export declare const rejectSTM: { (pf: (a: A) => Option.Option>): (self: STM) => STM; (self: STM, pf: (a: A) => Option.Option>): STM; }; /** * Repeats this `STM` effect until its result satisfies the specified * predicate. * * **WARNING**: `repeatUntil` uses a busy loop to repeat the effect and will * consume a thread until it completes (it cannot yield). This is because STM * describes a single atomic transaction which must either complete, retry or * fail a transaction before yielding back to the Effect runtime. * - Use `retryUntil` instead if you don't need to maintain transaction * state for repeats. * - Ensure repeating the STM effect will eventually satisfy the predicate. * * @since 1.0.0 * @category mutations */ export declare const repeatUntil: { (predicate: Predicate): (self: STM) => STM; (self: STM, predicate: Predicate): STM; }; /** * Repeats this `STM` effect while its result satisfies the specified * predicate. * * **WARNING**: `repeatWhile` uses a busy loop to repeat the effect and will * consume a thread until it completes (it cannot yield). This is because STM * describes a single atomic transaction which must either complete, retry or * fail a transaction before yielding back to the Effect runtime. * - Use `retryWhile` instead if you don't need to maintain transaction * state for repeats. * - Ensure repeating the STM effect will eventually not satisfy the * predicate. * * @since 1.0.0 * @category mutations */ export declare const repeatWhile: { (predicate: Predicate): (self: STM) => STM; (self: STM, predicate: Predicate): STM; }; /** * Replicates the given effect n times. If 0 or negative numbers are given, an * empty `Chunk` will be returned. * * @since 1.0.0 * @category constructors */ export declare const replicate: { (n: number): (self: STM) => Array>; (self: STM, n: number): Array>; }; /** * Performs this transaction the specified number of times and collects the * results. * * @since 1.0.0 * @category constructors */ export declare const replicateSTM: { (n: number): (self: STM) => STM>; (self: STM, n: number): STM>; }; /** * Performs this transaction the specified number of times, discarding the * results. * * @since 1.0.0 * @category constructors */ export declare const replicateSTMDiscard: { (n: number): (self: STM) => STM; (self: STM, n: number): STM; }; /** * Abort and retry the whole transaction when any of the underlying * transactional variables have changed. * * @since 1.0.0 * @category error handling */ export declare const retry: STM; /** * Filters the value produced by this effect, retrying the transaction until * the predicate returns `true` for the value. * * @since 1.0.0 * @category mutations */ export declare const retryUntil: { (predicate: Predicate): (self: STM) => STM; (self: STM, predicate: Predicate): STM; }; /** * Filters the value produced by this effect, retrying the transaction while * the predicate returns `true` for the value. * * @since 1.0.0 * @category mutations */ export declare const retryWhile: { (predicate: Predicate): (self: STM) => STM; (self: STM, predicate: Predicate): STM; }; /** * Converts an option on values into an option on errors. * * @since 1.0.0 * @category getters */ export declare const some: (self: STM>) => STM, A>; /** * Returns an `STM` effect that succeeds with the specified value. * * @since 1.0.0 * @category constructors */ export declare const succeed: (value: A) => STM; /** * Returns an effect with the empty value. * * @since 1.0.0 * @category constructors */ export declare const succeedNone: STM>; /** * Returns an effect with the optional value. * * @since 1.0.0 * @category constructors */ export declare const succeedSome: (value: A) => STM>; /** * Summarizes a `STM` effect by computing a provided value before and after * execution, and then combining the values to produce a summary, together * with the result of execution. * * @since 1.0.0 * @category mutations */ export declare const summarized: { (summary: STM, f: (before: A2, after: A2) => A3): (self: STM) => STM; (self: STM, summary: STM, f: (before: A2, after: A2) => A3): STM; }; /** * Suspends creation of the specified transaction lazily. * * @since 1.0.0 * @category constructors */ export declare const suspend: (evaluate: LazyArg>) => STM; /** * Returns an `STM` effect that succeeds with the specified lazily evaluated * value. * * @since 1.0.0 * @category constructors */ export declare const sync: (evaluate: () => A) => STM; /** * "Peeks" at the success of transactional effect. * * @since 1.0.0 * @category sequencing */ export declare const tap: { (f: (a: X) => STM): (self: STM) => STM; (self: STM, f: (a: X) => STM): STM; }; /** * "Peeks" at both sides of an transactional effect. * * @since 1.0.0 * @category sequencing */ export declare const tapBoth: { (options: { readonly onFailure: (error: XE) => STM; readonly onSuccess: (value: XA) => STM; }): (self: STM) => STM; (self: STM, options: { readonly onFailure: (error: XE) => STM; readonly onSuccess: (value: XA) => STM; }): STM; }; /** * "Peeks" at the error of the transactional effect. * * @since 1.0.0 * @category sequencing */ export declare const tapError: { (f: (error: X) => STM): (self: STM) => STM; (self: STM, f: (error: X) => STM): STM; }; declare const try_: { (options: { readonly try: LazyArg; readonly catch: (u: unknown) => E; }): STM; (try_: LazyArg): STM; }; export { /** * Imports a synchronous side-effect into a pure value, translating any thrown * exceptions into typed failed effects. * * @since 1.0.0 * @category constructors */ try_ as try }; /** * The moral equivalent of `if (!p) exp` * * @since 1.0.0 * @category mutations */ export declare const unless: { (predicate: LazyArg): (self: STM) => STM>; (self: STM, predicate: LazyArg): STM>; }; /** * The moral equivalent of `if (!p) exp` when `p` has side-effects * * @since 1.0.0 * @category mutations */ export declare const unlessSTM: { (predicate: STM): (self: STM) => STM>; (self: STM, predicate: STM): STM>; }; /** * Converts an option on errors into an option on values. * * @since 1.0.0 * @category getters */ export declare const unsome: (self: STM, A>) => STM>; /** * Returns an `STM` effect that succeeds with `Unit`. * * @since 1.0.0 * @category constructors */ export declare const unit: STM; /** * Feeds elements of type `A` to `f` and accumulates all errors in error * channel or successes in success channel. * * This combinator is lossy meaning that if there are errors all successes * will be lost. To retain all information please use `STM.partition`. * * @since 1.0.0 * @category mutations */ export declare const validateAll: { (f: (a: A) => STM): (elements: Iterable) => STM], Array>; (elements: Iterable, f: (a: A) => STM): STM], Array>; }; /** * Feeds elements of type `A` to `f` until it succeeds. Returns first success * or the accumulation of all errors. * * @since 1.0.0 * @category mutations */ export declare const validateFirst: { (f: (a: A) => STM): (elements: Iterable) => STM, B>; (elements: Iterable, f: (a: A) => STM): STM, B>; }; /** * The moral equivalent of `if (p) exp`. * * @since 1.0.0 * @category mutations */ export declare const when: { (predicate: LazyArg): (self: STM) => STM>; (self: STM, predicate: LazyArg): STM>; }; /** * The moral equivalent of `if (p) exp` when `p` has side-effects. * * @since 1.0.0 * @category mutations */ export declare const whenSTM: { (predicate: STM): (self: STM) => STM>; (self: STM, predicate: STM): STM>; }; /** * Sequentially zips this value with the specified one. * * @since 1.0.0 * @category zipping */ export declare const zip: { (that: STM): (self: STM) => STM; (self: STM, that: STM): STM; }; /** * Sequentially zips this value with the specified one, discarding the second * element of the tuple. * * @since 1.0.0 * @category zipping */ export declare const zipLeft: { (that: STM): (self: STM) => STM; (self: STM, that: STM): STM; }; /** * Sequentially zips this value with the specified one, discarding the first * element of the tuple. * * @since 1.0.0 * @category zipping */ export declare const zipRight: { (that: STM): (self: STM) => STM; (self: STM, that: STM): STM; }; /** * Sequentially zips this value with the specified one, combining the values * using the specified combiner function. * * @since 1.0.0 * @category zipping */ export declare const zipWith: { (that: STM, f: (a: A, b: A1) => A2): (self: STM) => STM; (self: STM, that: STM, f: (a: A, b: A1) => A2): STM; }; /** * This function takes an iterable of `STM` values and returns a new * `STM` value that represents the first `STM` value in the iterable * that succeeds. If all of the `Effect` values in the iterable fail, then * the resulting `STM` value will fail as well. * * This function is sequential, meaning that the `STM` values in the * iterable will be executed in sequence, and the first one that succeeds * will determine the outcome of the resulting `STM` value. * * @param effects - The iterable of `STM` values to evaluate. * * @returns A new `STM` value that represents the first successful * `STM` value in the iterable, or a failed `STM` value if all of the * `STM` values in the iterable fail. * * @since 1.0.0 * @category elements */ export declare const firstSuccessOf: (effects: Iterable>) => STM; /** * @category do notation * @since 1.0.0 */ export declare const Do: STM; /** * @category do notation * @since 1.0.0 */ export declare const bind: { (tag: Exclude, f: (_: K) => STM): (self: STM) => STM>; (self: STM, tag: Exclude, f: (_: K) => STM): STM>; }; declare const let_: { (tag: Exclude, f: (_: K) => A): (self: STM) => STM>; (self: STM, tag: Exclude, f: (_: K) => A): STM>; }; export { /** * @category do notation * @since 1.0.0 */ let_ as let }; /** * @category do notation * @since 1.0.0 */ export declare const bindTo: { (tag: N): (self: STM) => STM>; (self: STM, tag: N): STM>; }; //# sourceMappingURL=STM.d.ts.map