"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unsafeUpdate = exports.updateSomeAndGet = exports.updateSome = exports.updateAndGet = exports.update = exports.modifySome = exports.modify = exports.getAndUpdateSome = exports.getAndUpdate = exports.getAndSet = void 0;
const core_1 = require("../Effect/core");
function getAndSet(self, a) {
    return (0, core_1.succeedWith)(() => {
        const v = self.value.get;
        self.value.set(a);
        return v;
    });
}
exports.getAndSet = getAndSet;
function getAndUpdate(self, f) {
    return (0, core_1.succeedWith)(() => {
        const v = self.value.get;
        self.value.set(f(v));
        return v;
    });
}
exports.getAndUpdate = getAndUpdate;
function getAndUpdateSome(self, f) {
    return (0, core_1.succeedWith)(() => {
        const v = self.value.get;
        const o = f(v);
        if (o._tag === "Some") {
            self.value.set(o.value);
        }
        return v;
    });
}
exports.getAndUpdateSome = getAndUpdateSome;
function modify(self, f) {
    return (0, core_1.succeedWith)(() => {
        const v = self.value.get;
        const o = f(v);
        self.value.set(o.get(1));
        return o.get(0);
    });
}
exports.modify = modify;
function modifySome(self, def, f) {
    return (0, core_1.succeedWith)(() => {
        const v = self.value.get;
        const o = f(v);
        if (o._tag === "Some") {
            self.value.set(o.value.get(1));
            return o.value.get(0);
        }
        return def;
    });
}
exports.modifySome = modifySome;
function update(self, f) {
    return (0, core_1.succeedWith)(() => {
        self.value.set(f(self.value.get));
    });
}
exports.update = update;
function updateAndGet(self, f) {
    return (0, core_1.succeedWith)(() => {
        self.value.set(f(self.value.get));
        return self.value.get;
    });
}
exports.updateAndGet = updateAndGet;
function updateSome(self, f) {
    return (0, core_1.succeedWith)(() => {
        const o = f(self.value.get);
        if (o._tag === "Some") {
            self.value.set(o.value);
        }
    });
}
exports.updateSome = updateSome;
function updateSomeAndGet(self, f) {
    return (0, core_1.succeedWith)(() => {
        const o = f(self.value.get);
        if (o._tag === "Some") {
            self.value.set(o.value);
        }
        return self.value.get;
    });
}
exports.updateSomeAndGet = updateSomeAndGet;
function unsafeUpdate(self, f) {
    self.value.set(f(self.value.get));
}
exports.unsafeUpdate = unsafeUpdate;
//# sourceMappingURL=atomic.js.map