import type { Ref } from "../Ref/XRef.js"; import * as semaphore from "../Semaphore/index.js"; import * as T from "./effect.js"; /** * A `XRefM[RA, RB, EA, EB, A, B]` is a polymorphic, purely functional * description of a mutable reference. The fundamental operations of a `XRefM` * are `set` and `get`. `set` takes a value of type `A` and sets the reference * to a new value, requiring an environment of type `RA` and potentially * failing with an error of type `EA`. `get` gets the current value of the * reference and returns a value of type `B`, requiring an environment of type * `RB` and potentially failing with an error of type `EB`. * * When the error and value types of the `XRefM` are unified, that is, it is a * `XRefM`, the `XRefM` also supports atomic `modify` and * `update` operations. * * Unlike an ordinary `ZRef`, a `XRefM` allows performing effects within update * operations, at some cost to performance. Writes will semantically block * other writers, while multiple readers can read simultaneously. */ export interface XRefM { readonly _RA: (_: RA) => void; readonly _RB: (_: RB) => void; readonly _EA: () => EA; readonly _EB: () => EB; readonly _A: (_: A) => void; readonly _B: () => B; /** * Folds over the error and value types of the `XRefM`. This is a highly * polymorphic method that is capable of arbitrarily transforming the error * and value types of the `XRefM`. For most use cases one of the more * specific combinators implemented in terms of `foldM` will be more * ergonomic but this method is extremely useful for implementing new * combinators. */ readonly foldM: (ea: (_: EA) => EC, eb: (_: EB) => ED, ca: (_: C) => T.Effect, bd: (_: B) => T.Effect) => XRefM; /** * Folds over the error and value types of the `XRefM`, allowing access to * the state in transforming the `set` value. This is a more powerful version * of `foldM` but requires unifying the environment and error types. */ readonly foldAllM: (ea: (_: EA) => EC, eb: (_: EB) => ED, ec: (_: EB) => EC, ca: (_: C) => (_: B) => T.Effect, bd: (_: B) => T.Effect) => XRefM; /** * Reads the value from the `XRefM`. */ readonly get: T.Effect; /** * Writes a new value to the `XRefM`, with a guarantee of immediate * consistency (at some cost to performance). */ readonly set: (a: A) => T.Effect; } export declare class AtomicM implements XRefM { readonly ref: Ref; readonly semaphore: semaphore.Semaphore; readonly _tag = "AtomicM"; readonly _RA: (_: unknown) => void; readonly _RB: (_: unknown) => void; readonly _EA: () => never; readonly _EB: () => never; readonly _A: (_: A) => void; readonly _B: () => A; constructor(ref: Ref, semaphore: semaphore.Semaphore); foldM(_ea: (_: never) => EC, _eb: (_: never) => ED, ca: (_: C) => T.Effect, bd: (_: A) => T.Effect): XRefM; foldAllM(_ea: (_: never) => EC, _eb: (_: never) => ED, _ec: (_: never) => EC, ca: (_: C) => (_: A) => T.Effect, bd: (_: A) => T.Effect): XRefM; get get(): T.Effect; set(a: A): T.Effect; } export declare class DerivedM implements XRefM { readonly use: (f: (value: AtomicM, getEither: (s: S) => T.Effect, setEither: (a: A) => T.Effect) => X) => X; readonly _tag = "DerivedM"; readonly _RA: (_: RA) => void; readonly _RB: (_: RB) => void; readonly _EA: () => EA; readonly _EB: () => EB; readonly _A: (_: A) => void; readonly _B: () => B; constructor(use: (f: (value: AtomicM, getEither: (s: S) => T.Effect, setEither: (a: A) => T.Effect) => X) => X); foldM(ea: (_: EA) => EC, eb: (_: EB) => ED, ca: (_: C) => T.Effect, bd: (_: B) => T.Effect): XRefM; foldAllM(ea: (_: EA) => EC, eb: (_: EB) => ED, ec: (_: EB) => EC, ca: (_: C) => (_: B) => T.Effect, bd: (_: B) => T.Effect): XRefM; get get(): T.Effect; set(a: A): T.Effect; } export declare class DerivedAllM implements XRefM { readonly use: (f: (value: AtomicM, getEither: (s: S) => T.Effect, setEither: (a: A) => (s: S) => T.Effect) => X) => X; readonly _tag = "DerivedAllM"; readonly _RA: (_: RA) => void; readonly _RB: (_: RB) => void; readonly _EA: () => EA; readonly _EB: () => EB; readonly _A: (_: A) => void; readonly _B: () => B; constructor(use: (f: (value: AtomicM, getEither: (s: S) => T.Effect, setEither: (a: A) => (s: S) => T.Effect) => X) => X); foldM(ea: (_: EA) => EC, eb: (_: EB) => ED, ca: (_: C) => T.Effect, bd: (_: B) => T.Effect): XRefM; foldAllM(ea: (_: EA) => EC, eb: (_: EB) => ED, ec: (_: EB) => EC, ca: (_: C) => (_: B) => T.Effect, bd: (_: B) => T.Effect): XRefM; get get(): T.Effect; set(a: A): T.Effect; } export interface RefM extends XRefM { } export declare const concrete: (_: XRefM) => AtomicM | DerivedM | DerivedAllM; //# sourceMappingURL=XRefM.d.ts.map