effect-io-ai

Package: effect
Module: SubscriptionRef

SubscriptionRef.updateEffect

Updates the value of the SubscriptionRef with the result of applying an effectful function, notifying subscribers of the change.

Example (Updating with an effect)

import { Effect, SubscriptionRef } from "effect"

const program = Effect.gen(function*() {
  const ref = yield* SubscriptionRef.make(10)

  yield* SubscriptionRef.updateEffect(ref, (n) => Effect.succeed(n + 5))

  const value = yield* SubscriptionRef.get(ref)
  console.log(value)
})

Signature

declare const updateEffect: { <A, E, R>(update: (a: A) => Effect.Effect<A, E, R>): (self: SubscriptionRef<A>) => Effect.Effect<void, E, R>; <A, E, R>(self: SubscriptionRef<A>, update: (a: A) => Effect.Effect<A, E, R>): Effect.Effect<void, E, R>; }

Source

Since v2.0.0