import * as tsplus_module_1 from "@effect/core/stm/STM/operations/effect";
import { getOrMakeEntry } from "@effect/core/stm/TRef/operations/_internal/getOrMakeEntry";
/**
 * Updates the value of the variable and returns the old value.
 *
 * @tsplus fluent ets/TRef getAndUpdate
 */

export function getAndUpdate_(self, f) {
  return tsplus_module_1.effect(journal => {
    const entry = getOrMakeEntry(self, journal);
    const oldValue = entry.use(_ => _.unsafeGet());
    entry.use(_ => _.unsafeSet(f(oldValue)));
    return oldValue;
  });
}
/**
 * Updates the value of the variable and returns the old value.
 *
 * @tsplus static ets/TRef/Aspects getAndUpdate
 */

export const getAndUpdate = f => self => getAndUpdate_(self, f);
//# sourceMappingURL=getAndUpdate.mjs.map