Package: effect
Module: TxRef
Modifies the value of the TxRef using the provided function.
When to use
Use to update a TxRef and return a computed result from the same
transaction step.
Example (Modifying transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
const counter = yield* TxRef.make(0)
// Modify and return both old and new value
const result = yield* TxRef.modify(counter, (current) => [current * 2, current + 1])
console.log(result) // 0 (the return value: current * 2)
console.log(yield* TxRef.get(counter)) // 1 (the new value: current + 1)
})
Signature
declare const modify: { <A, R>(f: (current: NoInfer<A>) => [returnValue: R, newValue: A]): (self: TxRef<A>) => Effect.Effect<R>; <A, R>(self: TxRef<A>, f: (current: A) => [returnValue: R, newValue: A]): Effect.Effect<R>; }
Since v2.0.0