import * as tsplus_module_1 from "@tsplus/stdlib/io/Eval/run";
import * as tsplus_module_2 from "@tsplus/stdlib/io/Eval/succeed";
import * as tsplus_module_3 from "@tsplus/stdlib/io/Eval/suspend";
import * as tsplus_module_4 from "@tsplus/stdlib/io/Eval/zipWith";
import * as tsplus_module_5 from "@tsplus/stdlib/io/Eval/map";
import { realCause } from "@effect/core/io/Cause/definition";
/**
 * Folds over the cases of this cause with the specified functions.
 *
 * @tsplus fluent ets/Cause fold
 */

export function fold_(self, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause) {
  return tsplus_module_1.run(foldSafe(self, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause));
}
/**
 * Folds over the cases of this cause with the specified functions.
 *
 * @tsplus static ets/Cause/Aspects fold
 */

export const fold = (onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause) => self => fold_(self, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause);

function foldSafe(self, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause) {
  void 0;

  switch (self._tag) {
    case "Empty":
      return tsplus_module_2.succeed(onEmptyCause);

    case "Fail":
      return tsplus_module_2.succeed(() => onFailCause(self.value, self.trace));

    case "Die":
      return tsplus_module_2.succeed(() => onDieCause(self.value, self.trace));

    case "Interrupt":
      return tsplus_module_2.succeed(() => onInterruptCause(self.fiberId, self.trace));

    case "Both":
      return tsplus_module_4.zipWith_(tsplus_module_3.suspend(() => foldSafe(self.left, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause)), () => tsplus_module_3.suspend(() => foldSafe(self.right, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause)), (left, right) => onBothCause(left, right));

    case "Then":
      return tsplus_module_4.zipWith_(tsplus_module_3.suspend(() => foldSafe(self.left, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause)), () => tsplus_module_3.suspend(() => foldSafe(self.right, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause)), (left, right) => onThenCause(left, right));

    case "Stackless":
      return tsplus_module_5.map_(tsplus_module_3.suspend(() => foldSafe(self.cause, onEmptyCause, onFailCause, onDieCause, onInterruptCause, onThenCause, onBothCause, onStacklessCause)), z => onStacklessCause(z, self.stackless));
  }
}
//# sourceMappingURL=fold.mjs.map