/** * @since 2.0.0 */ import * as Cause from "./Cause.js" import * as Chunk from "./Chunk.js" import type * as Context from "./Context.js" import type * as Effect from "./Effect.js" import type * as Either from "./Either.js" import type * as FiberId from "./FiberId.js" import type { LazyArg } from "./Function.js" import type { TypeLambda } from "./HKT.js" import * as core from "./internal/stm/core.js" import * as stm from "./internal/stm/stm.js" import type * as Option from "./Option.js" import type { Pipeable } from "./Pipeable.js" import type { Predicate, Refinement } from "./Predicate.js" import type { Covariant, MergeRecord, NoExcessProperties, NoInfer } from "./Types.js" import type * as Unify from "./Unify.js" import type { YieldWrap } from "./Utils.js" /** * @since 2.0.0 * @category symbols */ export const STMTypeId: unique symbol = core.STMTypeId /** * @since 2.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 2.0.0 * @category models */ export interface STM extends Effect.Effect, STM.Variance, Pipeable { [Unify.typeSymbol]?: unknown [Unify.unifySymbol]?: STMUnify [Unify.ignoreSymbol]?: STMUnifyIgnore [Symbol.iterator](): Effect.EffectGenerator> } /** * @since 2.0.0 * @category models */ export interface STMUnify extends Effect.EffectUnify { STM?: () => A[Unify.typeSymbol] extends STM | infer _ ? STM : never } /** * @category models * @since 2.0.0 */ export interface STMUnifyIgnore extends Effect.EffectUnifyIgnore { Effect?: true } /** * @category type lambdas * @since 2.0.0 */ export interface STMTypeLambda extends TypeLambda { readonly type: STM } /** * @since 2.0.0 * @category models */ declare module "./Context.js" { interface Tag extends STM {} // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Reference extends STM {} } /** * @since 2.0.0 * @category models */ declare module "./Either.js" { interface Left extends STM { readonly _tag: "Left" } interface Right extends STM { readonly _tag: "Right" } } /** * @since 2.0.0 * @category models */ declare module "./Option.js" { interface None extends STM { readonly _tag: "None" } interface Some extends STM { readonly _tag: "Some" } } /** * @since 2.0.0 */ export declare namespace STM { /** * @since 2.0.0 * @category models */ export interface Variance { readonly [STMTypeId]: { readonly _A: Covariant readonly _E: Covariant readonly _R: Covariant } } } /** * Returns `true` if the provided value is an `STM`, `false` otherwise. * * @since 2.0.0 * @category refinements */ export const isSTM: (u: unknown) => u is STM = core.isSTM /** * 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 2.0.0 * @category constructors */ export const acquireUseRelease: { /** * 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 2.0.0 * @category constructors */ ( use: (resource: A) => STM, release: (resource: A) => STM ): (acquire: STM) => Effect.Effect /** * 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 2.0.0 * @category constructors */ ( acquire: STM, use: (resource: A) => STM, release: (resource: A) => STM ): Effect.Effect } = stm.acquireUseRelease /** * @since 2.0.0 * @category utils */ export declare namespace All { type STMAny = STM type ReturnTuple>, Discard extends boolean> = STM< Discard extends true ? void : T[number] extends never ? [] : { -readonly [K in keyof T]: [T[K]] extends [STM] ? A : never }, T[number] extends never ? never : [T[number]] extends [{ [STMTypeId]: { _E: (_: never) => infer E } }] ? E : never, T[number] extends never ? never : [T[number]] extends [{ [STMTypeId]: { _R: (_: never) => infer R } }] ? R : never > extends infer X ? X : never type ReturnIterable, Discard extends boolean> = [T] extends [Iterable>] ? STM, E, R> : never type ReturnObject, Discard extends boolean> = STM< Discard extends true ? void : { -readonly [K in keyof T]: [T[K]] extends [STM.Variance] ? A : never }, keyof T extends never ? never : [T[keyof T]] extends [{ [STMTypeId]: { _E: (_: never) => infer E } }] ? E : never, keyof T extends never ? never : [T[keyof T]] extends [{ [STMTypeId]: { _R: (_: never) => infer R } }] ? R : never > /** * @since 2.0.0 * @category utils */ export type Options = { readonly discard?: boolean | undefined } type IsDiscard = [Extract] extends [never] ? false : true type Narrow = (A extends [] ? [] : never) | A /** * @since 2.0.0 * @category utils */ export interface Signature { < Arg extends ReadonlyArray | Iterable | Record, O extends NoExcessProperties >( 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 2.0.0 * @category constructors */ export const all: All.Signature = stm.all /** * Maps the success value of this effect to the specified constant value. * * @since 2.0.0 * @category mapping */ export const as: { /** * Maps the success value of this effect to the specified constant value. * * @since 2.0.0 * @category mapping */ (value: A2): (self: STM) => STM /** * Maps the success value of this effect to the specified constant value. * * @since 2.0.0 * @category mapping */ (self: STM, value: A2): STM } = stm.as /** * Maps the success value of this effect to an optional value. * * @since 2.0.0 * @category mapping */ export const asSome: (self: STM) => STM, E, R> = stm.asSome /** * Maps the error value of this effect to an optional value. * * @since 2.0.0 * @category mapping */ export const asSomeError: (self: STM) => STM, R> = stm.asSomeError /** * 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 2.0.0 * @category mapping */ export const asVoid: (self: STM) => STM = stm.asVoid /** * Creates an `STM` value from a partial (but pure) function. * * @since 2.0.0 * @category constructors */ export const attempt: (evaluate: LazyArg) => STM = stm.attempt /** * Recovers from all errors. * * @since 2.0.0 * @category error handling */ export const catchAll: { /** * Recovers from all errors. * * @since 2.0.0 * @category error handling */ (f: (e: E) => STM): (self: STM) => STM /** * Recovers from all errors. * * @since 2.0.0 * @category error handling */ (self: STM, f: (e: E) => STM): STM } = core.catchAll /** * Recovers from some or all of the error cases. * * @since 2.0.0 * @category error handling */ export const catchSome: { /** * Recovers from some or all of the error cases. * * @since 2.0.0 * @category error handling */ (pf: (error: E) => Option.Option>): (self: STM) => STM /** * Recovers from some or all of the error cases. * * @since 2.0.0 * @category error handling */ (self: STM, pf: (error: E) => Option.Option>): STM } = stm.catchSome /** * Recovers from the specified tagged error. * * @since 2.0.0 * @category error handling */ export const catchTag: { /** * Recovers from the specified tagged error. * * @since 2.0.0 * @category error handling */ (k: K, f: (e: Extract) => STM): (self: STM) => STM, R1 | R> /** * Recovers from the specified tagged error. * * @since 2.0.0 * @category error handling */ ( self: STM, k: K, f: (e: Extract) => STM ): STM, R | R1> } = stm.catchTag /** * Recovers from multiple tagged errors. * * @since 2.0.0 * @category error handling */ export const catchTags: { /** * Recovers from multiple tagged errors. * * @since 2.0.0 * @category error handling */ < E extends { _tag: string }, Cases extends { [K in E["_tag"]]+?: ((error: Extract) => STM) } >(cases: Cases): ( self: STM ) => STM< | A | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? A : never }[keyof Cases], | Exclude | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? E : never }[keyof Cases], | R | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? R : never }[keyof Cases] > /** * Recovers from multiple tagged errors. * * @since 2.0.0 * @category error handling */ < R, E extends { _tag: string }, A, Cases extends { [K in E["_tag"]]+?: ((error: Extract) => STM) } >(self: STM, cases: Cases): STM< | A | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? A : never }[keyof Cases], | Exclude | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? E : never }[keyof Cases], | R | { [K in keyof Cases]: Cases[K] extends (...args: Array) => STM ? R : never }[keyof Cases] > } = stm.catchTags /** * Checks the condition, and if it's true, returns unit, otherwise, retries. * * @since 2.0.0 * @category constructors */ export const check: (predicate: LazyArg) => STM = stm.check /** * Simultaneously filters and maps the value produced by this effect. * * @since 2.0.0 * @category mutations */ export const collect: { /** * Simultaneously filters and maps the value produced by this effect. * * @since 2.0.0 * @category mutations */ (pf: (a: A) => Option.Option): (self: STM) => STM /** * Simultaneously filters and maps the value produced by this effect. * * @since 2.0.0 * @category mutations */ (self: STM, pf: (a: A) => Option.Option): STM } = stm.collect /** * Simultaneously filters and maps the value produced by this effect. * * @since 2.0.0 * @category mutations */ export const collectSTM: { /** * Simultaneously filters and maps the value produced by this effect. * * @since 2.0.0 * @category mutations */ (pf: (a: A) => Option.Option>): (self: STM) => STM /** * Simultaneously filters and maps the value produced by this effect. * * @since 2.0.0 * @category mutations */ (self: STM, pf: (a: A) => Option.Option>): STM } = stm.collectSTM /** * Commits this transaction atomically. * * @since 2.0.0 * @category destructors */ export const commit: (self: STM) => Effect.Effect = core.commit /** * Commits this transaction atomically, regardless of whether the transaction * is a success or a failure. * * @since 2.0.0 * @category destructors */ export const commitEither: (self: STM) => Effect.Effect = stm.commitEither /** * 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 2.0.0 * @category constructors */ export const cond: (predicate: LazyArg, error: LazyArg, result: LazyArg) => STM = stm.cond /** * Retrieves the environment inside an stm. * * @since 2.0.0 * @category constructors */ export const context: () => STM, never, R> = core.context /** * Accesses the environment of the transaction to perform a transaction. * * @since 2.0.0 * @category constructors */ export const contextWith: (f: (environment: Context.Context) => R) => STM = core.contextWith /** * Accesses the environment of the transaction to perform a transaction. * * @since 2.0.0 * @category constructors */ export const contextWithSTM: ( f: (environment: Context.Context) => STM ) => STM = core.contextWithSTM /** * Transforms the environment being provided to this effect with the specified * function. * * @since 2.0.0 * @category context */ export const mapInputContext: { /** * Transforms the environment being provided to this effect with the specified * function. * * @since 2.0.0 * @category context */ (f: (context: Context.Context) => Context.Context): (self: STM) => STM /** * Transforms the environment being provided to this effect with the specified * function. * * @since 2.0.0 * @category context */ ( self: STM, f: (context: Context.Context) => Context.Context ): STM } = core.mapInputContext /** * Fails the transactional effect with the specified defect. * * @since 2.0.0 * @category constructors */ export const die: (defect: unknown) => STM = core.die /** * Kills the fiber running the effect with a `Cause.RuntimeException` that * contains the specified message. * * @since 2.0.0 * @category constructors */ export const dieMessage: (message: string) => STM = core.dieMessage /** * Fails the transactional effect with the specified lazily evaluated defect. * * @since 2.0.0 * @category constructors */ export const dieSync: (evaluate: LazyArg) => STM = core.dieSync /** * Converts the failure channel into an `Either`. * * @since 2.0.0 * @category mutations */ export const either: (self: STM) => STM, never, R> = stm.either /** * 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 2.0.0 * @category finalization */ export const ensuring: { /** * 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 2.0.0 * @category finalization */ (finalizer: STM): (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 2.0.0 * @category finalization */ (self: STM, finalizer: STM): STM } = core.ensuring /** * Returns an effect that ignores errors and runs repeatedly until it * eventually succeeds. * * @since 2.0.0 * @category mutations */ export const eventually: (self: STM) => STM = stm.eventually /** * Determines whether all elements of the `Iterable` satisfy the effectual * predicate. * * @since 2.0.0 * @category constructors */ export const every: { /** * Determines whether all elements of the `Iterable` satisfy the effectual * predicate. * * @since 2.0.0 * @category constructors */ (predicate: (a: NoInfer) => STM): (iterable: Iterable) => STM /** * Determines whether all elements of the `Iterable` satisfy the effectual * predicate. * * @since 2.0.0 * @category constructors */ (iterable: Iterable, predicate: (a: A) => STM): STM } = stm.every /** * Determines whether any element of the `Iterable[A]` satisfies the effectual * predicate `f`. * * @since 2.0.0 * @category constructors */ export const exists: { /** * Determines whether any element of the `Iterable[A]` satisfies the effectual * predicate `f`. * * @since 2.0.0 * @category constructors */ (predicate: (a: NoInfer) => STM): (iterable: Iterable) => STM /** * Determines whether any element of the `Iterable[A]` satisfies the effectual * predicate `f`. * * @since 2.0.0 * @category constructors */ (iterable: Iterable, predicate: (a: A) => STM): STM } = stm.exists /** * Fails the transactional effect with the specified error. * * @since 2.0.0 * @category constructors */ export const fail: (error: E) => STM = core.fail /** * Fails the transactional effect with the specified lazily evaluated error. * * @since 2.0.0 * @category constructors */ export const failSync: (evaluate: LazyArg) => STM = core.failSync /** * Returns the fiber id of the fiber committing the transaction. * * @since 2.0.0 * @category constructors */ export const fiberId: STM = stm.fiberId /** * Filters the collection using the specified effectual predicate. * * @since 2.0.0 * @category constructors */ export const filter: { /** * Filters the collection using the specified effectual predicate. * * @since 2.0.0 * @category constructors */ (predicate: (a: NoInfer) => STM): (iterable: Iterable) => STM, E, R> /** * Filters the collection using the specified effectual predicate. * * @since 2.0.0 * @category constructors */ (iterable: Iterable, predicate: (a: A) => STM): STM, E, R> } = stm.filter /** * Filters the collection using the specified effectual predicate, removing * all elements that satisfy the predicate. * * @since 2.0.0 * @category constructors */ export const filterNot: { /** * Filters the collection using the specified effectual predicate, removing * all elements that satisfy the predicate. * * @since 2.0.0 * @category constructors */ (predicate: (a: NoInfer) => STM): (iterable: Iterable) => STM, E, R> /** * Filters the collection using the specified effectual predicate, removing * all elements that satisfy the predicate. * * @since 2.0.0 * @category constructors */ (iterable: Iterable, predicate: (a: A) => STM): STM, E, R> } = stm.filterNot /** * Dies with specified defect if the predicate fails. * * @since 2.0.0 * @category filtering */ export const filterOrDie: { /** * Dies with specified defect if the predicate fails. * * @since 2.0.0 * @category filtering */ (refinement: Refinement, B>, defect: LazyArg): (self: STM) => STM /** * Dies with specified defect if the predicate fails. * * @since 2.0.0 * @category filtering */ (predicate: Predicate>, defect: LazyArg): (self: STM) => STM /** * Dies with specified defect if the predicate fails. * * @since 2.0.0 * @category filtering */ (self: STM, refinement: Refinement, defect: LazyArg): STM /** * Dies with specified defect if the predicate fails. * * @since 2.0.0 * @category filtering */ (self: STM, predicate: Predicate, defect: LazyArg): STM } = stm.filterOrDie /** * Dies with a `Cause.RuntimeException` having the specified message if the * predicate fails. * * @since 2.0.0 * @category filtering */ export const filterOrDieMessage: { /** * Dies with a `Cause.RuntimeException` having the specified message if the * predicate fails. * * @since 2.0.0 * @category filtering */ (refinement: Refinement, B>, message: string): (self: STM) => STM /** * Dies with a `Cause.RuntimeException` having the specified message if the * predicate fails. * * @since 2.0.0 * @category filtering */ (predicate: Predicate>, message: string): (self: STM) => STM /** * Dies with a `Cause.RuntimeException` having the specified message if the * predicate fails. * * @since 2.0.0 * @category filtering */ (self: STM, refinement: Refinement, message: string): STM /** * Dies with a `Cause.RuntimeException` having the specified message if the * predicate fails. * * @since 2.0.0 * @category filtering */ (self: STM, predicate: Predicate, message: string): STM } = stm.filterOrDieMessage /** * Supplies `orElse` if the predicate fails. * * @since 2.0.0 * @category filtering */ export const filterOrElse: { /** * Supplies `orElse` if the predicate fails. * * @since 2.0.0 * @category filtering */ ( refinement: Refinement, B>, orElse: (a: NoInfer) => STM ): (self: STM) => STM /** * Supplies `orElse` if the predicate fails. * * @since 2.0.0 * @category filtering */ ( predicate: Predicate>, orElse: (a: NoInfer) => STM ): (self: STM) => STM /** * Supplies `orElse` if the predicate fails. * * @since 2.0.0 * @category filtering */ ( self: STM, refinement: Refinement, orElse: (a: A) => STM ): STM /** * Supplies `orElse` if the predicate fails. * * @since 2.0.0 * @category filtering */ ( self: STM, predicate: Predicate, orElse: (a: A) => STM ): STM } = stm.filterOrElse /** * Fails with the specified error if the predicate fails. * * @since 2.0.0 * @category filtering */ export const filterOrFail: { /** * Fails with the specified error if the predicate fails. * * @since 2.0.0 * @category filtering */ (refinement: Refinement, B>, orFailWith: (a: NoInfer) => E2): (self: STM) => STM /** * Fails with the specified error if the predicate fails. * * @since 2.0.0 * @category filtering */ (predicate: Predicate>, orFailWith: (a: NoInfer) => E2): (self: STM) => STM /** * Fails with the specified error if the predicate fails. * * @since 2.0.0 * @category filtering */ (self: STM, refinement: Refinement, orFailWith: (a: A) => E2): STM /** * Fails with the specified error if the predicate fails. * * @since 2.0.0 * @category filtering */ (self: STM, predicate: Predicate, orFailWith: (a: A) => E2): STM } = stm.filterOrFail /** * Feeds the value produced by this effect to the specified function, and then * runs the returned effect as well to produce its results. * * @since 2.0.0 * @category sequencing */ export const flatMap: { /** * Feeds the value produced by this effect to the specified function, and then * runs the returned effect as well to produce its results. * * @since 2.0.0 * @category sequencing */ (f: (a: A) => STM): (self: STM) => 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 2.0.0 * @category sequencing */ (self: STM, f: (a: A) => STM): STM } = core.flatMap /** * Flattens out a nested `STM` effect. * * @since 2.0.0 * @category sequencing */ export const flatten: (self: STM, E, R>) => STM = stm.flatten /** * 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 2.0.0 * @category mutations */ export const flip: (self: STM) => STM = stm.flip /** * Swaps the error/value parameters, applies the function `f` and flips the * parameters back * * @since 2.0.0 * @category mutations */ export const flipWith: { /** * Swaps the error/value parameters, applies the function `f` and flips the * parameters back * * @since 2.0.0 * @category mutations */ (f: (stm: STM) => STM): (self: STM) => STM /** * Swaps the error/value parameters, applies the function `f` and flips the * parameters back * * @since 2.0.0 * @category mutations */ (self: STM, f: (stm: STM) => STM): STM } = stm.flipWith /** * Folds over the `STM` effect, handling both failure and success, but not * retry. * * @since 2.0.0 * @category folding */ export const match: { /** * Folds over the `STM` effect, handling both failure and success, but not * retry. * * @since 2.0.0 * @category folding */ ( options: { readonly onFailure: (error: E) => A2; readonly onSuccess: (value: A) => A3 } ): (self: STM) => STM /** * Folds over the `STM` effect, handling both failure and success, but not * retry. * * @since 2.0.0 * @category folding */ ( self: STM, options: { readonly onFailure: (error: E) => A2; readonly onSuccess: (value: A) => A3 } ): STM } = stm.match /** * Effectfully folds over the `STM` effect, handling both failure and success. * * @since 2.0.0 * @category folding */ export const matchSTM: { /** * Effectfully folds over the `STM` effect, handling both failure and success. * * @since 2.0.0 * @category folding */ ( options: { readonly onFailure: (e: E) => STM; readonly onSuccess: (a: A) => STM } ): (self: STM) => STM /** * Effectfully folds over the `STM` effect, handling both failure and success. * * @since 2.0.0 * @category folding */ ( self: STM, options: { readonly onFailure: (e: E) => STM; readonly onSuccess: (a: A) => STM } ): STM } = core.matchSTM /** * Applies the function `f` to each element of the `Iterable` and returns * a transactional effect that produces a new `Chunk`. * * @since 2.0.0 * @category traversing */ export const forEach: { /** * Applies the function `f` to each element of the `Iterable` and returns * a transactional effect that produces a new `Chunk`. * * @since 2.0.0 * @category traversing */ ( f: (a: A) => STM, options?: { readonly discard?: false | undefined } | undefined ): (elements: Iterable) => STM, E, R> /** * Applies the function `f` to each element of the `Iterable` and returns * a transactional effect that produces a new `Chunk`. * * @since 2.0.0 * @category traversing */ (f: (a: A) => STM, options: { readonly discard: true }): (elements: Iterable) => STM /** * Applies the function `f` to each element of the `Iterable` and returns * a transactional effect that produces a new `Chunk`. * * @since 2.0.0 * @category traversing */ ( elements: Iterable, f: (a: A) => STM, options?: { readonly discard?: false | undefined } | undefined ): STM, E, R> /** * Applies the function `f` to each element of the `Iterable` and returns * a transactional effect that produces a new `Chunk`. * * @since 2.0.0 * @category traversing */ ( elements: Iterable, f: (a: A) => STM, options: { readonly discard: true } ): STM } = stm.forEach /** * Lifts an `Either` into a `STM`. * * @since 2.0.0 * @category constructors */ export const fromEither: (either: Either.Either) => STM = stm.fromEither /** * Lifts an `Option` into a `STM`. * * @since 2.0.0 * @category constructors */ export const fromOption: (option: Option.Option) => STM> = stm.fromOption /** * @since 2.0.0 * @category models */ export interface Adapter { (self: STM): STM (a: A, ab: (a: A) => STM<_A, _E, _R>): STM<_A, _E, _R> (a: A, ab: (a: A) => B, bc: (b: B) => STM<_A, _E, _R>): STM<_A, _E, _R> (a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => STM<_A, _E, _R>): STM<_A, _E, _R> ( a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => STM<_A, _E, _R> ): STM<_A, _E, _R> ( a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => STM<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> ( 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<_A, _E, _R> ): STM<_A, _E, _R> } /** * @since 2.0.0 * @category constructors */ export const gen: >, AEff>( ...args: | [ self: Self, body: (this: Self, resume: Adapter) => Generator ] | [body: (resume: Adapter) => Generator] ) => STM< AEff, [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? E : never, [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? R : never > = stm.gen /** * 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 2.0.0 * @category getters */ export const head: (self: STM, E, R>) => STM, R> = stm.head const if_: { (options: { readonly onTrue: STM readonly onFalse: STM /** * Flattens out a nested `STM` effect. * * @since 2.0.0 * @category sequencing */ }): (self: boolean | STM) => STM ( self: boolean, options: { readonly onTrue: STM; readonly onFalse: STM } ): STM ( self: STM, options: { readonly onTrue: STM; readonly onFalse: STM } ): STM } = stm.if_ export { /** * Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise. * * @since 2.0.0 * @category mutations */ if_ as if } /** * Returns a new effect that ignores the success or failure of this effect. * * @since 2.0.0 * @category mutations */ export const ignore: (self: STM) => STM = stm.ignore /** * Interrupts the fiber running the effect. * * @since 2.0.0 * @category constructors */ export const interrupt: STM = core.interrupt /** * Interrupts the fiber running the effect with the specified `FiberId`. * * @since 2.0.0 * @category constructors */ export const interruptAs: (fiberId: FiberId.FiberId) => STM = core.interruptAs /** * Returns whether this transactional effect is a failure. * * @since 2.0.0 * @category getters */ export const isFailure: (self: STM) => STM = stm.isFailure /** * Returns whether this transactional effect is a success. * * @since 2.0.0 * @category getters */ export const isSuccess: (self: STM) => STM = stm.isSuccess /** * Iterates with the specified transactional function. The moral equivalent * of: * * ```ts skip-type-checking * const s = initial * * while (cont(s)) { * s = body(s) * } * * return s * ``` * * @since 2.0.0 * @category constructors */ export const iterate: ( initial: Z, options: { readonly while: Predicate readonly body: (z: Z) => STM } ) => STM = stm.iterate /** * Loops with the specified transactional function, collecting the results * into a list. The moral equivalent of: * * ```ts skip-type-checking * const as = [] * let s = initial * * while (cont(s)) { * as.push(body(s)) * s = inc(s) * } * * return as * ``` * * @since 2.0.0 * @category constructors */ export const loop: { /** * Loops with the specified transactional function, collecting the results * into a list. The moral equivalent of: * * ```ts skip-type-checking * const as = [] * let s = initial * * while (cont(s)) { * as.push(body(s)) * s = inc(s) * } * * return as * ``` * * @since 2.0.0 * @category constructors */ ( initial: Z, options: { readonly while: (z: Z) => boolean readonly step: (z: Z) => Z readonly body: (z: Z) => STM readonly discard?: false | undefined } ): STM, E, R> /** * Loops with the specified transactional function, collecting the results * into a list. The moral equivalent of: * * ```ts skip-type-checking * const as = [] * let s = initial * * while (cont(s)) { * as.push(body(s)) * s = inc(s) * } * * return as * ``` * * @since 2.0.0 * @category constructors */ ( initial: Z, options: { readonly while: (z: Z) => boolean readonly step: (z: Z) => Z readonly body: (z: Z) => STM readonly discard: true } ): STM } = stm.loop /** * Maps the value produced by the effect. * * @since 2.0.0 * @category mapping */ export const map: { /** * Maps the value produced by the effect. * * @since 2.0.0 * @category mapping */ (f: (a: A) => B): (self: STM) => STM /** * Maps the value produced by the effect. * * @since 2.0.0 * @category mapping */ (self: STM, f: (a: A) => B): STM } = core.map /** * 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 2.0.0 * @category mapping */ export const mapAttempt: { /** * 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 2.0.0 * @category mapping */ (f: (a: A) => B): (self: STM) => 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 2.0.0 * @category mapping */ (self: STM, f: (a: A) => B): STM } = stm.mapAttempt /** * Returns an `STM` effect whose failure and success channels have been mapped * by the specified pair of functions, `f` and `g`. * * @since 2.0.0 * @category mapping */ export const mapBoth: { /** * Returns an `STM` effect whose failure and success channels have been mapped * by the specified pair of functions, `f` and `g`. * * @since 2.0.0 * @category mapping */ ( options: { readonly onFailure: (error: E) => E2; readonly onSuccess: (value: A) => A2 } ): (self: STM) => STM /** * Returns an `STM` effect whose failure and success channels have been mapped * by the specified pair of functions, `f` and `g`. * * @since 2.0.0 * @category mapping */ ( self: STM, options: { readonly onFailure: (error: E) => E2; readonly onSuccess: (value: A) => A2 } ): STM } = stm.mapBoth /** * Maps from one error type to another. * * @since 2.0.0 * @category mapping */ export const mapError: { /** * Maps from one error type to another. * * @since 2.0.0 * @category mapping */ (f: (error: E) => E2): (self: STM) => STM /** * Maps from one error type to another. * * @since 2.0.0 * @category mapping */ (self: STM, f: (error: E) => E2): STM } = stm.mapError /** * Returns a new effect where the error channel has been merged into the * success channel to their common combined type. * * @since 2.0.0 * @category mutations */ export const merge: (self: STM) => STM = stm.merge /** * Merges an `Iterable` to a single `STM`, working sequentially. * * @since 2.0.0 * @category constructors */ export const mergeAll: { /** * Merges an `Iterable` to a single `STM`, working sequentially. * * @since 2.0.0 * @category constructors */ (zero: A2, f: (a2: A2, a: A) => A2): (iterable: Iterable>) => STM /** * Merges an `Iterable` to a single `STM`, working sequentially. * * @since 2.0.0 * @category constructors */ (iterable: Iterable>, zero: A2, f: (a2: A2, a: A) => A2): STM } = stm.mergeAll /** * Returns a new effect where boolean value of this effect is negated. * * @since 2.0.0 * @category mutations */ export const negate: (self: STM) => STM = stm.negate /** * Requires the option produced by this value to be `None`. * * @since 2.0.0 * @category mutations */ export const none: (self: STM, E, R>) => STM, R> = stm.none /** * Converts the failure channel into an `Option`. * * @since 2.0.0 * @category mutations */ export const option: (self: STM) => STM, never, R> = stm.option /** * Translates `STM` effect failure into death of the fiber, making all * failures unchecked and not a part of the type of the effect. * * @since 2.0.0 * @category error handling */ export const orDie: (self: STM) => STM = stm.orDie /** * 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 2.0.0 * @category error handling */ export const orDieWith: { /** * 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 2.0.0 * @category error handling */ (f: (error: E) => unknown): (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 2.0.0 * @category error handling */ (self: STM, f: (error: E) => unknown): STM } = stm.orDieWith /** * Tries this effect first, and if it fails or retries, tries the other * effect. * * @since 2.0.0 * @category error handling */ export const orElse: { /** * Tries this effect first, and if it fails or retries, tries the other * effect. * * @since 2.0.0 * @category error handling */ (that: LazyArg>): (self: STM) => STM /** * Tries this effect first, and if it fails or retries, tries the other * effect. * * @since 2.0.0 * @category error handling */ (self: STM, that: LazyArg>): STM } = stm.orElse /** * 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 2.0.0 * @category error handling */ export const orElseEither: { /** * 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 2.0.0 * @category error handling */ (that: LazyArg>): (self: STM) => STM, E2, R2 | R> /** * 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 2.0.0 * @category error handling */ (self: STM, that: LazyArg>): STM, E2, R | R2> } = stm.orElseEither /** * Tries this effect first, and if it fails or retries, fails with the * specified error. * * @since 2.0.0 * @category error handling */ export const orElseFail: { /** * Tries this effect first, and if it fails or retries, fails with the * specified error. * * @since 2.0.0 * @category error handling */ (error: LazyArg): (self: STM) => STM /** * Tries this effect first, and if it fails or retries, fails with the * specified error. * * @since 2.0.0 * @category error handling */ (self: STM, error: LazyArg): STM } = stm.orElseFail /** * 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 2.0.0 * @category error handling */ export const orElseOptional: { /** * 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 2.0.0 * @category error handling */ (that: LazyArg, R2>>): (self: STM, R>) => STM, R2 | R> /** * 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 2.0.0 * @category error handling */ ( self: STM, R>, that: LazyArg, R2>> ): STM, R | R2> } = stm.orElseOptional /** * Tries this effect first, and if it fails or retries, succeeds with the * specified value. * * @since 2.0.0 * @category error handling */ export const orElseSucceed: { /** * Tries this effect first, and if it fails or retries, succeeds with the * specified value. * * @since 2.0.0 * @category error handling */ (value: LazyArg): (self: STM) => STM /** * Tries this effect first, and if it fails or retries, succeeds with the * specified value. * * @since 2.0.0 * @category error handling */ (self: STM, value: LazyArg): STM } = stm.orElseSucceed /** * Tries this effect first, and if it enters retry, then it tries the other * effect. This is an equivalent of Haskell's orElse. * * @since 2.0.0 * @category error handling */ export const orTry: { /** * Tries this effect first, and if it enters retry, then it tries the other * effect. This is an equivalent of Haskell's orElse. * * @since 2.0.0 * @category error handling */ (that: LazyArg>): (self: STM) => 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 2.0.0 * @category error handling */ (self: STM, that: LazyArg>): STM } = core.orTry /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in a tupled fashion. * * @since 2.0.0 * @category traversing */ export const partition: { /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in a tupled fashion. * * @since 2.0.0 * @category traversing */ (f: (a: A) => STM): (elements: Iterable) => STM<[excluded: Array, satisfying: Array], never, R> /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in a tupled fashion. * * @since 2.0.0 * @category traversing */ (elements: Iterable, f: (a: A) => STM): STM<[excluded: Array, satisfying: Array], never, R> } = stm.partition /** * Provides the transaction its required environment, which eliminates its * dependency on `R`. * * @since 2.0.0 * @category context */ export const provideContext: { /** * Provides the transaction its required environment, which eliminates its * dependency on `R`. * * @since 2.0.0 * @category context */ (env: Context.Context): (self: STM) => STM /** * Provides the transaction its required environment, which eliminates its * dependency on `R`. * * @since 2.0.0 * @category context */ (self: STM, env: Context.Context): STM } = stm.provideContext /** * Splits the context into two parts, providing one part using the * specified layer and leaving the remainder `R0`. * * @since 2.0.0 * @category context */ export const provideSomeContext: { /** * Splits the context into two parts, providing one part using the * specified layer and leaving the remainder `R0`. * * @since 2.0.0 * @category context */ (context: Context.Context): (self: STM) => STM> /** * Splits the context into two parts, providing one part using the * specified layer and leaving the remainder `R0`. * * @since 2.0.0 * @category context */ (self: STM, context: Context.Context): STM> } = stm.provideSomeContext /** * Provides the effect with the single service it requires. If the transactional * effect requires more than one service use `provideEnvironment` instead. * * @since 2.0.0 * @category context */ export const provideService: { /** * Provides the effect with the single service it requires. If the transactional * effect requires more than one service use `provideEnvironment` instead. * * @since 2.0.0 * @category context */ (tag: Context.Tag, resource: NoInfer): (self: STM) => STM> /** * Provides the effect with the single service it requires. If the transactional * effect requires more than one service use `provideEnvironment` instead. * * @since 2.0.0 * @category context */ (self: STM, tag: Context.Tag, resource: NoInfer): STM> } = stm.provideService /** * Provides the effect with the single service it requires. If the transactional * effect requires more than one service use `provideEnvironment` instead. * * @since 2.0.0 * @category context */ export const provideServiceSTM: { /** * Provides the effect with the single service it requires. If the transactional * effect requires more than one service use `provideEnvironment` instead. * * @since 2.0.0 * @category context */ (tag: Context.Tag, stm: STM, E1, R1>): (self: STM) => STM> /** * Provides the effect with the single service it requires. If the transactional * effect requires more than one service use `provideEnvironment` instead. * * @since 2.0.0 * @category context */ (self: STM, tag: Context.Tag, stm: STM, E1, R1>): STM> } = stm.provideServiceSTM /** * Folds an `Iterable` using an effectual function f, working sequentially * from left to right. * * @since 2.0.0 * @category constructors */ export const reduce: { /** * Folds an `Iterable` using an effectual function f, working sequentially * from left to right. * * @since 2.0.0 * @category constructors */ (zero: S, f: (s: S, a: A) => STM): (iterable: Iterable) => STM /** * Folds an `Iterable` using an effectual function f, working sequentially * from left to right. * * @since 2.0.0 * @category constructors */ (iterable: Iterable, zero: S, f: (s: S, a: A) => STM): STM } = stm.reduce /** * Reduces an `Iterable` to a single `STM`, working sequentially. * * @since 2.0.0 * @category constructors */ export const reduceAll: { /** * Reduces an `Iterable` to a single `STM`, working sequentially. * * @since 2.0.0 * @category constructors */ (initial: STM, f: (x: A, y: A) => A): (iterable: Iterable>) => STM /** * Reduces an `Iterable` to a single `STM`, working sequentially. * * @since 2.0.0 * @category constructors */ ( iterable: Iterable>, initial: STM, f: (x: A, y: A) => A ): STM } = stm.reduceAll /** * Folds an `Iterable` using an effectual function f, working sequentially * from right to left. * * @since 2.0.0 * @category constructors */ export const reduceRight: { /** * Folds an `Iterable` using an effectual function f, working sequentially * from right to left. * * @since 2.0.0 * @category constructors */ (zero: S, f: (s: S, a: A) => STM): (iterable: Iterable) => STM /** * Folds an `Iterable` using an effectual function f, working sequentially * from right to left. * * @since 2.0.0 * @category constructors */ (iterable: Iterable, zero: S, f: (s: S, a: A) => STM): STM } = stm.reduceRight /** * Keeps some of the errors, and terminates the fiber with the rest. * * @since 2.0.0 * @category mutations */ export const refineOrDie: { /** * Keeps some of the errors, and terminates the fiber with the rest. * * @since 2.0.0 * @category mutations */ (pf: (error: E) => Option.Option): (self: STM) => STM /** * Keeps some of the errors, and terminates the fiber with the rest. * * @since 2.0.0 * @category mutations */ (self: STM, pf: (error: E) => Option.Option): STM } = stm.refineOrDie /** * Keeps some of the errors, and terminates the fiber with the rest, using the * specified function to convert the `E` into a `Throwable`. * * @since 2.0.0 * @category mutations */ export const refineOrDieWith: { /** * Keeps some of the errors, and terminates the fiber with the rest, using the * specified function to convert the `E` into a `Throwable`. * * @since 2.0.0 * @category mutations */ (pf: (error: E) => Option.Option, f: (error: E) => unknown): (self: STM) => 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 2.0.0 * @category mutations */ ( self: STM, pf: (error: E) => Option.Option, f: (error: E) => unknown ): STM } = stm.refineOrDieWith /** * Fail with the returned value if the `PartialFunction` matches, otherwise * continue with our held value. * * @since 2.0.0 * @category mutations */ export const reject: { /** * Fail with the returned value if the `PartialFunction` matches, otherwise * continue with our held value. * * @since 2.0.0 * @category mutations */ (pf: (a: A) => Option.Option): (self: STM) => STM /** * Fail with the returned value if the `PartialFunction` matches, otherwise * continue with our held value. * * @since 2.0.0 * @category mutations */ (self: STM, pf: (a: A) => Option.Option): STM } = stm.reject /** * 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 2.0.0 * @category mutations */ export const rejectSTM: { /** * 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 2.0.0 * @category mutations */ (pf: (a: A) => Option.Option>): (self: STM) => 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 2.0.0 * @category mutations */ (self: STM, pf: (a: A) => Option.Option>): STM } = stm.rejectSTM /** * 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 2.0.0 * @category mutations */ export const repeatUntil: { /** * 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 2.0.0 * @category mutations */ (predicate: Predicate): (self: STM) => 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 2.0.0 * @category mutations */ (self: STM, predicate: Predicate): STM } = stm.repeatUntil /** * 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 2.0.0 * @category mutations */ export const repeatWhile: { /** * 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 2.0.0 * @category mutations */ (predicate: Predicate): (self: STM) => 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 2.0.0 * @category mutations */ (self: STM, predicate: Predicate): STM } = stm.repeatWhile /** * Replicates the given effect n times. If 0 or negative numbers are given, an * empty `Chunk` will be returned. * * @since 2.0.0 * @category constructors */ export const replicate: { /** * Replicates the given effect n times. If 0 or negative numbers are given, an * empty `Chunk` will be returned. * * @since 2.0.0 * @category constructors */ (n: number): (self: STM) => Array> /** * Replicates the given effect n times. If 0 or negative numbers are given, an * empty `Chunk` will be returned. * * @since 2.0.0 * @category constructors */ (self: STM, n: number): Array> } = stm.replicate /** * Performs this transaction the specified number of times and collects the * results. * * @since 2.0.0 * @category constructors */ export const replicateSTM: { /** * Performs this transaction the specified number of times and collects the * results. * * @since 2.0.0 * @category constructors */ (n: number): (self: STM) => STM, E, R> /** * Performs this transaction the specified number of times and collects the * results. * * @since 2.0.0 * @category constructors */ (self: STM, n: number): STM, E, R> } = stm.replicateSTM /** * Performs this transaction the specified number of times, discarding the * results. * * @since 2.0.0 * @category constructors */ export const replicateSTMDiscard: { /** * Performs this transaction the specified number of times, discarding the * results. * * @since 2.0.0 * @category constructors */ (n: number): (self: STM) => STM /** * Performs this transaction the specified number of times, discarding the * results. * * @since 2.0.0 * @category constructors */ (self: STM, n: number): STM } = stm.replicateSTMDiscard /** * Abort and retry the whole transaction when any of the underlying * transactional variables have changed. * * @since 2.0.0 * @category error handling */ export const retry: STM = core.retry /** * Filters the value produced by this effect, retrying the transaction until * the predicate returns `true` for the value. * * @since 2.0.0 * @category mutations */ export const retryUntil: { /** * Filters the value produced by this effect, retrying the transaction until * the predicate returns `true` for the value. * * @since 2.0.0 * @category mutations */ (refinement: Refinement, B>): (self: STM) => STM /** * Filters the value produced by this effect, retrying the transaction until * the predicate returns `true` for the value. * * @since 2.0.0 * @category mutations */ (predicate: Predicate): (self: STM) => STM /** * Filters the value produced by this effect, retrying the transaction until * the predicate returns `true` for the value. * * @since 2.0.0 * @category mutations */ (self: STM, refinement: Refinement): STM /** * Filters the value produced by this effect, retrying the transaction until * the predicate returns `true` for the value. * * @since 2.0.0 * @category mutations */ (self: STM, predicate: Predicate): STM } = stm.retryUntil /** * Filters the value produced by this effect, retrying the transaction while * the predicate returns `true` for the value. * * @since 2.0.0 * @category mutations */ export const retryWhile: { /** * Filters the value produced by this effect, retrying the transaction while * the predicate returns `true` for the value. * * @since 2.0.0 * @category mutations */ (predicate: Predicate): (self: STM) => STM /** * Filters the value produced by this effect, retrying the transaction while * the predicate returns `true` for the value. * * @since 2.0.0 * @category mutations */ (self: STM, predicate: Predicate): STM } = stm.retryWhile /** * Converts an option on values into an option on errors. * * @since 2.0.0 * @category getters */ export const some: (self: STM, E, R>) => STM, R> = stm.some /** * Returns an `STM` effect that succeeds with the specified value. * * @since 2.0.0 * @category constructors */ export const succeed: (value: A) => STM = core.succeed /** * Returns an effect with the empty value. * * @since 2.0.0 * @category constructors */ export const succeedNone: STM> = stm.succeedNone /** * Returns an effect with the optional value. * * @since 2.0.0 * @category constructors */ export const succeedSome: (value: A) => STM> = stm.succeedSome /** * 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 2.0.0 * @category mutations */ export const summarized: { /** * 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 2.0.0 * @category mutations */ (summary: STM, f: (before: A2, after: A2) => A3): (self: STM) => STM<[A3, A], E2 | E, R2 | R> /** * 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 2.0.0 * @category mutations */ ( self: STM, summary: STM, f: (before: A2, after: A2) => A3 ): STM<[A3, A], E | E2, R | R2> } = stm.summarized /** * Suspends creation of the specified transaction lazily. * * @since 2.0.0 * @category constructors */ export const suspend: (evaluate: LazyArg>) => STM = stm.suspend /** * Returns an `STM` effect that succeeds with the specified lazily evaluated * value. * * @since 2.0.0 * @category constructors */ export const sync: (evaluate: () => A) => STM = core.sync /** * "Peeks" at the success of transactional effect. * * @since 2.0.0 * @category sequencing */ export const tap: { /** * "Peeks" at the success of transactional effect. * * @since 2.0.0 * @category sequencing */ (f: (a: A) => STM): (self: STM) => STM /** * "Peeks" at the success of transactional effect. * * @since 2.0.0 * @category sequencing */ (self: STM, f: (a: A) => STM): STM } = stm.tap /** * "Peeks" at both sides of an transactional effect. * * @since 2.0.0 * @category sequencing */ export const tapBoth: { /** * "Peeks" at both sides of an transactional effect. * * @since 2.0.0 * @category sequencing */ ( options: { readonly onFailure: (error: XE) => STM; readonly onSuccess: (value: XA) => STM } ): (self: STM) => STM /** * "Peeks" at both sides of an transactional effect. * * @since 2.0.0 * @category sequencing */ ( self: STM, options: { readonly onFailure: (error: XE) => STM; readonly onSuccess: (value: XA) => STM } ): STM } = stm.tapBoth /** * "Peeks" at the error of the transactional effect. * * @since 2.0.0 * @category sequencing */ export const tapError: { /** * "Peeks" at the error of the transactional effect. * * @since 2.0.0 * @category sequencing */ (f: (error: NoInfer) => STM): (self: STM) => STM /** * "Peeks" at the error of the transactional effect. * * @since 2.0.0 * @category sequencing */ (self: STM, f: (error: E) => STM): STM } = stm.tapError const try_: { (options: { readonly try: LazyArg readonly catch: (u: unknown) => E }): STM (try_: LazyArg): STM } = stm.try_ export { /** * Imports a synchronous side-effect into a pure value, translating any thrown * exceptions into typed failed effects. * * @since 2.0.0 * @category constructors */ try_ as try } /** * The moral equivalent of `if (!p) exp` * * @since 2.0.0 * @category mutations */ export const unless: { /** * The moral equivalent of `if (!p) exp` * * @since 2.0.0 * @category mutations */ (predicate: LazyArg): (self: STM) => STM, E, R> /** * The moral equivalent of `if (!p) exp` * * @since 2.0.0 * @category mutations */ (self: STM, predicate: LazyArg): STM, E, R> } = stm.unless /** * The moral equivalent of `if (!p) exp` when `p` has side-effects * * @since 2.0.0 * @category mutations */ export const unlessSTM: { /** * The moral equivalent of `if (!p) exp` when `p` has side-effects * * @since 2.0.0 * @category mutations */ (predicate: STM): (self: STM) => STM, E2 | E, R2 | R> /** * The moral equivalent of `if (!p) exp` when `p` has side-effects * * @since 2.0.0 * @category mutations */ (self: STM, predicate: STM): STM, E | E2, R | R2> } = stm.unlessSTM /** * Converts an option on errors into an option on values. * * @since 2.0.0 * @category getters */ export const unsome: (self: STM, R>) => STM, E, R> = stm.unsome const void_: STM = stm.void export { /** * Returns an `STM` effect that succeeds with `void`. * * @since 2.0.0 * @category constructors */ void_ as void } /** * 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 2.0.0 * @category mutations */ export const validateAll: { /** * 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 2.0.0 * @category mutations */ (f: (a: A) => STM): (elements: Iterable) => STM, [E, ...Array], R> /** * 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 2.0.0 * @category mutations */ (elements: Iterable, f: (a: A) => STM): STM, [E, ...Array], R> } = stm.validateAll /** * Feeds elements of type `A` to `f` until it succeeds. Returns first success * or the accumulation of all errors. * * @since 2.0.0 * @category mutations */ export const validateFirst: { /** * Feeds elements of type `A` to `f` until it succeeds. Returns first success * or the accumulation of all errors. * * @since 2.0.0 * @category mutations */ (f: (a: A) => STM): (elements: Iterable) => STM, R> /** * Feeds elements of type `A` to `f` until it succeeds. Returns first success * or the accumulation of all errors. * * @since 2.0.0 * @category mutations */ (elements: Iterable, f: (a: A) => STM): STM, R> } = stm.validateFirst /** * The moral equivalent of `if (p) exp`. * * @since 2.0.0 * @category mutations */ export const when: { /** * The moral equivalent of `if (p) exp`. * * @since 2.0.0 * @category mutations */ (predicate: LazyArg): (self: STM) => STM, E, R> /** * The moral equivalent of `if (p) exp`. * * @since 2.0.0 * @category mutations */ (self: STM, predicate: LazyArg): STM, E, R> } = stm.when /** * The moral equivalent of `if (p) exp` when `p` has side-effects. * * @since 2.0.0 * @category mutations */ export const whenSTM: { /** * The moral equivalent of `if (p) exp` when `p` has side-effects. * * @since 2.0.0 * @category mutations */ (predicate: STM): (self: STM) => STM, E2 | E, R2 | R> /** * The moral equivalent of `if (p) exp` when `p` has side-effects. * * @since 2.0.0 * @category mutations */ (self: STM, predicate: STM): STM, E | E2, R | R2> } = stm.whenSTM /** * Sequentially zips this value with the specified one. * * @since 2.0.0 * @category zipping */ export const zip: { /** * Sequentially zips this value with the specified one. * * @since 2.0.0 * @category zipping */ (that: STM): (self: STM) => STM<[A, A1], E1 | E, R1 | R> /** * Sequentially zips this value with the specified one. * * @since 2.0.0 * @category zipping */ (self: STM, that: STM): STM<[A, A1], E | E1, R | R1> } = core.zip /** * Sequentially zips this value with the specified one, discarding the second * element of the tuple. * * @since 2.0.0 * @category zipping */ export const zipLeft: { /** * Sequentially zips this value with the specified one, discarding the second * element of the tuple. * * @since 2.0.0 * @category zipping */ (that: STM): (self: STM) => STM /** * Sequentially zips this value with the specified one, discarding the second * element of the tuple. * * @since 2.0.0 * @category zipping */ (self: STM, that: STM): STM } = core.zipLeft /** * Sequentially zips this value with the specified one, discarding the first * element of the tuple. * * @since 2.0.0 * @category zipping */ export const zipRight: { /** * Sequentially zips this value with the specified one, discarding the first * element of the tuple. * * @since 2.0.0 * @category zipping */ (that: STM): (self: STM) => STM /** * Sequentially zips this value with the specified one, discarding the first * element of the tuple. * * @since 2.0.0 * @category zipping */ (self: STM, that: STM): STM } = core.zipRight /** * Sequentially zips this value with the specified one, combining the values * using the specified combiner function. * * @since 2.0.0 * @category zipping */ export const zipWith: { /** * Sequentially zips this value with the specified one, combining the values * using the specified combiner function. * * @since 2.0.0 * @category zipping */ (that: STM, f: (a: A, b: A1) => A2): (self: STM) => STM /** * Sequentially zips this value with the specified one, combining the values * using the specified combiner function. * * @since 2.0.0 * @category zipping */ (self: STM, that: STM, f: (a: A, b: A1) => A2): STM } = core.zipWith /** * 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. * * 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 2.0.0 * @category elements */ export const firstSuccessOf = (effects: Iterable>): STM => suspend(() => { const list = Chunk.fromIterable(effects) if (!Chunk.isNonEmpty(list)) { return dieSync(() => new Cause.IllegalArgumentException(`Received an empty collection of effects`)) } return Chunk.reduce( Chunk.tailNonEmpty(list), Chunk.headNonEmpty(list), (left, right) => orElse(left, () => right) ) }) /** * @category do notation * @since 2.0.0 */ export const Do: STM<{}> = succeed({}) /** * @category do notation * @since 2.0.0 */ export const bind: { /** * @category do notation * @since 2.0.0 */ (tag: Exclude, f: (_: NoInfer) => STM): (self: STM) => STM, E2 | E, R2 | R> /** * @category do notation * @since 2.0.0 */ ( self: STM, tag: Exclude, f: (_: NoInfer) => STM ): STM, E | E2, R | R2> } = stm.bind const let_: { ( tag: Exclude, f: (_: NoInfer) => A ): (self: STM) => STM, E, R> ( self: STM, tag: Exclude, f: (_: NoInfer) => A ): STM, E, R> } = stm.let_ export { /** * @category do notation * @since 2.0.0 */ let_ as let } /** * @category do notation * @since 2.0.0 */ export const bindTo: { /** * @category do notation * @since 2.0.0 */ (tag: N): (self: STM) => STM, E, R> /** * @category do notation * @since 2.0.0 */ (self: STM, tag: N): STM, E, R> } = stm.bindTo