"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toMaybe = toMaybe;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/io/Eval/run"));

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

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/io/Eval/succeed"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/HashSet/empty"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/io/Eval/suspend"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/HashSet/add"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/io/Eval/zipWith"));

var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/HashSet/size"));

var tsplus_module_9 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/FiberId/operations/combineAll"));

var tsplus_module_10 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/io/Eval/map"));

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

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; }

/**
 * Convert a `FiberId` into an `Maybe<FiberId>`.
 */
function toMaybe(self) {
  return tsplus_module_1.run(toMaybeSafe(self));
}

function toMaybeSafe(self) {
  void 0;

  switch (self._tag) {
    case "None":
      {
        return tsplus_module_3.succeed(() => tsplus_module_2.none);
      }

    case "Runtime":
      {
        return tsplus_module_3.succeed(() => tsplus_module_2.some(self));
      }

    case "Composite":
      {
        let base = tsplus_module_3.succeed(() => tsplus_module_4.empty());

        for (const fiberId of self.fiberIds) {
          base = tsplus_module_7.zipWith_(base, () => tsplus_module_5.suspend(() => toMaybeSafe(fiberId)), (fiberIds, optionFiberId) => optionFiberId._tag === "Some" ? tsplus_module_6.add_(fiberIds, optionFiberId.value) : fiberIds);
        }

        return tsplus_module_10.map_(base, fiberIds => tsplus_module_8.size(fiberIds) === 0 ? tsplus_module_2.none : tsplus_module_2.some(tsplus_module_9.combineAll(fiberIds)));
      }
  }
}
//# sourceMappingURL=toMaybe.js.map