Hyperlinkv0.8.0-beta.28

SynchronizedRef

SynchronizedRef.updateAndGetconsteffect/SynchronizedRef.ts:514
<A>(f: (a: A) => A): (self: SynchronizedRef<A>) => Effect.Effect<A>
<A>(self: SynchronizedRef<A>, f: (a: A) => A): Effect.Effect<A>

Updates the value of the SynchronizedRef with a function and returns the new value.

When to use

Use to apply a pure SynchronizedRef state transition and return the new stored value.

export const updateAndGet: {
  <A>(f: (a: A) => A): (self: SynchronizedRef<A>) => Effect.Effect<A>
  <A>(self: SynchronizedRef<A>, f: (a: A) => A): Effect.Effect<A>
} = dual(
  2,
  <A>(self: SynchronizedRef<A>, f: (a: A) => A): Effect.Effect<A> =>
    self.semaphore.withPermit(Ref.updateAndGet(self.backing, f))
)