import "../../Operator/index.js"; import type { HashMap } from "../../Collections/Immutable/HashMap/index.js"; import type * as T from "../../Effect/index.js"; import * as E from "../../Either/index.js"; import * as O from "../../Option/index.js"; import { AtomicReference } from "../../Support/AtomicReference/index.js"; import * as STM from "../STM/core.js"; import type { Journal, Todo } from "../STM/Journal/index.js"; import type { TxnId } from "../STM/TxnId/index.js"; import { Versioned } from "../STM/Versioned/index.js"; export declare const TRefTypeId: unique symbol; export declare type TRefTypeId = typeof TRefTypeId; /** * A `XTRef` is a polymorphic, purely functional description of a * mutable reference that can be modified as part of a transactional effect. The * fundamental operations of a `XTRef` are `set` and `get`. `set` takes a value * of type `A` and transactionally sets the reference to a new value, potentially * failing with an error of type `EA`. `get` gets the current value of the reference * and returns a value of type `B`, potentially failing with an error of type `EB`. * * When the error and value types of the `XTRef` are unified, that is, it is a * `XTRef`, the `ZTRef` also supports atomic `modify` and `update` * operations. All operations are guaranteed to be executed transactionally. * * NOTE: While `XTRef` provides the transactional equivalent of a mutable reference, * the value inside the `XTRef` should be immutable. */ export interface XTRef { readonly _typeId: TRefTypeId; readonly _EA: () => EA; readonly _EB: () => EB; readonly _A: (_: A) => void; readonly _B: () => B; fold(ea: (ea: EA) => EC, eb: (ea: EB) => ED, ca: (c: C) => E.Either, bd: (b: B) => E.Either): XTRef; foldAll(ea: (ea: EA) => EC, eb: (ea: EB) => ED, ec: (ea: EB) => EC, ca: (c: C) => (b: B) => E.Either, bd: (b: B) => E.Either): XTRef; readonly atomic: Atomic; } export interface TRef extends XTRef { } export interface ETRef extends XTRef { } export declare class Atomic implements XTRef { versioned: Versioned; readonly todo: AtomicReference>; readonly _typeId: TRefTypeId; readonly _tag = "Atomic"; readonly _EA: () => never; readonly _EB: () => never; readonly _A: (_: A) => void; readonly _B: () => A; readonly atomic: Atomic; constructor(versioned: Versioned, todo: AtomicReference>); fold(_ea: (ea: never) => EC, _eb: (ea: never) => ED, ca: (c: C) => E.Either, bd: (b: A) => E.Either): XTRef; foldAll(_ea: (ea: never) => EC, _eb: (ea: never) => ED, _ec: (ea: never) => EC, ca: (c: C) => (b: A) => E.Either, bd: (b: A) => E.Either): XTRef; } export declare class Derived implements XTRef { readonly getEither: (s: S) => E.Either; readonly setEither: (a: A) => E.Either; readonly value: Atomic; readonly atomic: Atomic; readonly _typeId: TRefTypeId; readonly _tag = "Derived"; readonly _EA: () => EA; readonly _EB: () => EB; readonly _A: (_: A) => void; readonly _B: () => B; constructor(getEither: (s: S) => E.Either, setEither: (a: A) => E.Either, value: Atomic, atomic: Atomic); fold(ea: (ea: EA) => EC, eb: (ea: EB) => ED, ca: (c: C) => E.Either, bd: (b: B) => E.Either): XTRef; foldAll(ea: (ea: EA) => EC, eb: (ea: EB) => ED, ec: (ea: EB) => EC, ca: (c: C) => (b: B) => E.Either, bd: (b: B) => E.Either): XTRef; } export declare class DerivedAll implements XTRef { readonly getEither: (s: S) => E.Either; readonly setEither: (a: A) => (s: S) => E.Either; readonly value: Atomic; readonly atomic: Atomic; readonly _typeId: TRefTypeId; readonly _tag = "DerivedAll"; readonly _EA: () => EA; readonly _EB: () => EB; readonly _A: (_: A) => void; readonly _B: () => B; constructor(getEither: (s: S) => E.Either, setEither: (a: A) => (s: S) => E.Either, value: Atomic, atomic: Atomic); fold(ea: (ea: EA) => EC, eb: (ea: EB) => ED, ca: (c: C) => E.Either, bd: (b: B) => E.Either): XTRef; foldAll(ea: (ea: EA) => EC, eb: (ea: EB) => ED, ec: (ea: EB) => EC, ca: (c: C) => (b: B) => E.Either, bd: (b: B) => E.Either): XTRef; } /** * Retrieves the value of the `XTRef`. */ export declare function get(self: XTRef): STM.STM; /** * Unsafely retrieves the value of the `XTRef`. */ export declare function unsafeGet_(self: XTRef, journal: Journal): A; /** * Sets the value of the `XTRef`. */ export declare function set_(self: XTRef, a: A): STM.STM; /** * Updates the value of the variable, returning a function of the specified * value. */ export declare function modify_(self: ETRef, f: (a: A) => readonly [B, A]): STM.STM; /** * Updates the value of the variable, returning a function of the specified * value. * * @ets_data_first modify_ */ export declare function modify(f: (a: A) => readonly [B, A]): (self: ETRef) => STM.STM; /** * Updates the value of the variable, returning a function of the specified * value. */ export declare function modifySome_(self: ETRef, b: B, f: (a: A) => O.Option): STM.STM; /** * Updates the value of the variable, returning a function of the specified * value. * * @ets_data_first modifySome_ */ export declare function modifySome(b: B, f: (a: A) => O.Option): (self: ETRef) => STM.STM; /** * Sets the value of the `XTRef` and returns the old value. */ export declare function getAndSet_(self: ETRef, a: A): STM.STM; /** * Sets the value of the `XTRef` and returns the old value. * * @ets_data_first getAndSet_ */ export declare function getAndSet(a: A): (self: ETRef) => STM.STM; /** * Updates the value of the variable and returns the old value. */ export declare function getAndUpdate_(self: ETRef, f: (a: A) => A): STM.STM; /** * Updates the value of the variable and returns the old value. * * @ets_data_first getAndUpdate_ */ export declare function getAndUpdate(f: (a: A) => A): (self: ETRef) => STM.STM; /** * Updates some values of the variable but leaves others alone, returning the * old value. */ export declare function getAndUpdateSome_(self: ETRef, f: (a: A) => O.Option): STM.STM; /** * Updates some values of the variable but leaves others alone, returning the * old value. * * @ets_data_first getAndUpdateSome_ */ export declare function getAndUpdateSome(f: (a: A) => O.Option): (self: ETRef) => STM.STM; /** * Sets the value of the `XTRef`. * * @ets_data_first set_ */ export declare function set(a: A): (self: XTRef) => STM.STM; /** * Updates the value of the variable. */ export declare function update_(self: ETRef, f: (a: A) => A): STM.STM; /** * Updates the value of the variable. * * @ets_data_first update_ */ export declare function update(f: (a: A) => A): (self: ETRef) => STM.STM; /** * Updates some values of the variable but leaves others alone. */ export declare function updateSome_(self: ETRef, f: (a: A) => O.Option): STM.STM; /** * Updates some values of the variable but leaves others alone. * * @ets_data_first updateSome_ */ export declare function updateSome(f: (a: A) => O.Option): (self: ETRef) => STM.STM; /** * Updates some values of the variable but leaves others alone. */ export declare function updateSomeAndGet_(self: ETRef, f: (a: A) => O.Option): STM.STM; /** * Updates some values of the variable but leaves others alone. * * @ets_data_first updateSomeAndGet_ */ export declare function updateSomeAndGet(f: (a: A) => O.Option): (self: ETRef) => STM.STM; /** * Updates the value of the variable and returns the new value. */ export declare function updateAndGet_(self: ETRef, f: (a: A) => A): STM.STM; /** * Updates the value of the variable and returns the new value. * * @ets_data_first getAndUpdate_ */ export declare function updateAndGet(f: (a: A) => A): (self: ETRef) => STM.STM; /** * @ets_optimize remove */ export declare function concrete(_: XTRef): asserts _ is Atomic | Derived | DerivedAll; /** * Makes a new `XTRef` that is initialized to the specified value. */ export declare function makeWith(a: () => A): STM.STM>; /** * Makes a new `XTRef` that is initialized to the specified value. */ export declare function make(a: A): STM.STM>; /** * Unsafely makes a new `XTRef` that is initialized to the specified value. */ export declare function unsafeMake(a: A): TRef; /** * Makes a new `XTRef` that is initialized to the specified value. */ export declare function makeCommitWith(a: () => A): T.UIO>; /** * Makes a new `XTRef` that is initialized to the specified value. */ export declare function makeCommit(a: A): T.UIO>; /** * Folds over the error and value types of the `XTRef`. This is a highly * polymorphic method that is capable of arbitrarily transforming the error * and value types of the `XTRef`. For most use cases one of the more * specific combinators implemented in terms of `fold` will be more ergonomic * but this method is extremely useful for implementing new combinators. */ export declare function fold_(self: XTRef, ea: (ea: EA) => EC, eb: (ea: EB) => ED, ca: (c: C) => E.Either, bd: (b: B) => E.Either): XTRef; /** * Folds over the error and value types of the `XTRef`. This is a highly * polymorphic method that is capable of arbitrarily transforming the error * and value types of the `XTRef`. For most use cases one of the more * specific combinators implemented in terms of `fold` will be more ergonomic * but this method is extremely useful for implementing new combinators. * * @ets_data_first fold_ */ export declare function fold(ea: (ea: EA) => EC, eb: (ea: EB) => ED, ca: (c: C) => E.Either, bd: (b: B) => E.Either): (self: XTRef) => XTRef; /** * Folds over the error and value types of the `XTRef`, allowing access to * the state in transforming the `set` value. This is a more powerful version * of `fold` but requires unifying the error types. */ export declare function foldAll_(self: XTRef, ea: (ea: EA) => EC, eb: (ea: EB) => ED, ec: (ea: EB) => EC, ca: (c: C) => (b: B) => E.Either, bd: (b: B) => E.Either): XTRef; /** * Folds over the error and value types of the `XTRef`, allowing access to * the state in transforming the `set` value. This is a more powerful version * of `fold` but requires unifying the error types. * * @ets_data_first foldAll_ */ export declare function foldAll(ea: (ea: EA) => EC, eb: (ea: EB) => ED, ec: (ea: EB) => EC, ca: (c: C) => (b: B) => E.Either, bd: (b: B) => E.Either): (self: XTRef) => XTRef; //# sourceMappingURL=index.d.ts.map