import * as tsplus_module_1 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_2 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_3 from "@tsplus/stdlib/data/Maybe/fromNullable";
import { Exited, Running } from "@effect/core/io/Scope/ReleaseMap/_internal/State";
/**
 * Removes the finalizer associated with this key and returns it.
 *
 * @tsplus fluent ets/ReleaseMap remove
 */

export function remove_(self, key, __tsplusTrace) {
  return self.ref.modify(s => {
    switch (s._tag) {
      case "Exited":
        {
          return tsplus_module_2.make(tsplus_module_1.none, new Exited(s.nextKey, s.exit, s.update));
        }

      case "Running":
        {
          const finalizers = s.finalizers();
          const finalizer = tsplus_module_3.fromNullable(finalizers.get(key));
          finalizers.delete(key);
          return tsplus_module_2.make(finalizer, new Running(s.nextKey, finalizers, s.update));
        }
    }
  }, __tsplusTrace);
}
/**
 * Removes the finalizer associated with this key and returns it.
 */

export const remove = (key, __tsplusTrace) => self => remove_(self, key, __tsplusTrace);
//# sourceMappingURL=remove.mjs.map