"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.UnsafeAPI = exports.AtomicInternal = void 0;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/definition"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Tuple/make"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/getOrElse"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/succeed"));

var _definition2 = /*#__PURE__*/require("@effect/core/io/Ref/definition");

var _RefInternal = /*#__PURE__*/require("@effect/core/io/Ref/operations/_internal/RefInternal");

var _Scheduler = /*#__PURE__*/require("@effect/core/support/Scheduler");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const fileName_1 = "(@effect/core) _src/io/Ref/operations/_internal/AtomicInternal.ts";

class UnsafeAPI {
  constructor(value) {
    this.value = value;
  }

  get get() {
    return this.value.get;
  }

  getAndSet(a) {
    const current = this.value.get;
    this.value.set(a);
    return current;
  }

  getAndUpdate(f) {
    const current = this.value.get;
    this.value.set(f(current));
    return current;
  }

  getAndUpdateSome(pf) {
    const current = this.value.get;
    const opt = pf(current);

    if (tsplus_module_1.isSome(opt)) {
      this.value.set(opt.value);
    }

    return current;
  }

  modify(f) {
    const current = this.value.get;
    const {
      tuple: [b, a]
    } = f(current);
    this.value.set(a);
    return b;
  }

  modifySome(fallback, pf) {
    const current = this.value.get;
    const tuple = tsplus_module_3.getOrElse_(pf(current), () => tsplus_module_2.make(fallback, current));
    this.value.set(tuple.get(1));
    return tuple.get(0);
  }

  set(a) {
    return this.value.set(a);
  }

  setAsync(a) {
    return (0, _Scheduler.scheduleTask)(() => this.value.set(a));
  }

  update(f) {
    const current = this.value.get;
    this.value.set(f(current));
  }

  updateAndGet(f) {
    const current = this.value.get;
    const next = f(current);
    this.value.set(next);
    return next;
  }

  updateSome(pf) {
    const current = this.value.get;
    const opt = pf(current);

    if (tsplus_module_1.isSome(opt)) {
      this.value.set(opt.value);
    }
  }

  updateSomeAndGet(pf) {
    const current = this.value.get;
    const next = pf(current);

    if (tsplus_module_1.isSome(next)) {
      this.value.set(next.value);
      return next.value;
    }

    return current;
  }

}

exports.UnsafeAPI = UnsafeAPI;
const AtomicInternal = { ..._RefInternal.RefInternal,

  /**
   * Internal Discriminator
   */
  get [_definition2.RefSym]() {
    return _definition2.RefSym;
  },

  get(__tsplusTrace) {
    return tsplus_module_4.succeed(() => this.unsafe.get, fileName_1 + ":99:26");
  },

  modify(f, __tsplusTrace) {
    return tsplus_module_4.succeed(() => this.unsafe.modify(f), fileName_1 + ":102:26");
  },

  set(a, __tsplusTrace) {
    return tsplus_module_4.succeed(() => this.unsafe.set(a), fileName_1 + ":105:26");
  },

  setAsync(a, __tsplusTrace) {
    return tsplus_module_4.succeed(() => this.unsafe.setAsync(a), fileName_1 + ":108:26");
  }

};
exports.AtomicInternal = AtomicInternal;
//# sourceMappingURL=AtomicInternal.js.map