import * as tsplus_module_1 from "@tsplus/stdlib/io/Eval/run";
import * as tsplus_module_2 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_3 from "@tsplus/stdlib/io/Eval/succeed";
import * as tsplus_module_4 from "@tsplus/stdlib/collections/HashSet/empty";
import * as tsplus_module_5 from "@tsplus/stdlib/io/Eval/suspend";
import * as tsplus_module_6 from "@tsplus/stdlib/collections/HashSet/add";
import * as tsplus_module_7 from "@tsplus/stdlib/io/Eval/zipWith";
import * as tsplus_module_8 from "@tsplus/stdlib/collections/HashSet/size";
import * as tsplus_module_9 from "@effect/core/io/FiberId/operations/combineAll";
import * as tsplus_module_10 from "@tsplus/stdlib/io/Eval/map";
import { realFiberId } from "@effect/core/io/FiberId/definition";
/**
 * Convert a `FiberId` into an `Maybe<FiberId>`.
 */

export 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.mjs.map