Hyperlinkv0.8.0-beta.28

TxSubscriptionRef

TxSubscriptionRef.updateconsteffect/TxSubscriptionRef.ts:276
<A>(f: (current: A) => A): (
  self: TxSubscriptionRef<A>
) => Effect.Effect<void>
<A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void>

Updates the value of the TxSubscriptionRef using a function and publishes the new value to all subscribers.

When to use

Use to derive the next TxSubscriptionRef value from the current value and publish it.

Example (Updating a value)

import { Effect, TxSubscriptionRef } from "effect"

const program = Effect.gen(function*() {
  const ref = yield* TxSubscriptionRef.make(5)
  yield* TxSubscriptionRef.update(ref, (n) => n * 2)
  console.log(yield* TxSubscriptionRef.get(ref)) // 10
})
export const update: {
  <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>
  <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void>
} = dual(
  2,
  <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void> =>
    modify(self, (current) => [void 0, f(current)])
)