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 new value.
 *
 * @tsplus fluent ets/TRef updateAndGet
 */

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

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