import * as tsplus_module_1 from "@tsplus/stdlib/data/Stack";
import { realCause } from "@effect/core/io/Cause/definition";
/**
 * Folds over the cause to statefully compute a value.
 *
 * @tsplus fluent ets/Cause foldLeft
 */

export function foldLeft_(self, initial, f) {
  let acc = initial;
  void 0;
  let current = self;
  let causes = undefined;

  while (current) {
    const result = f(acc, current);
    acc = result._tag === "Some" ? result.value : acc;
    void 0;

    switch (current._tag) {
      case "Then":
        {
          causes = new tsplus_module_1.Stack(current.right, causes);
          void 0;
          current = current.left;
          break;
        }

      case "Both":
        {
          causes = new tsplus_module_1.Stack(current.right, causes);
          void 0;
          current = current.left;
          break;
        }

      case "Stackless":
        {
          void 0;
          current = current.cause;
          break;
        }

      default:
        {
          current = undefined;
          break;
        }
    }

    if (!current && causes) {
      void 0;
      current = causes.value;
      causes = causes.previous;
    }
  }

  return acc;
}
/**
 * Folds over the cause to statefully compute a value.
 *
 * @tsplus static ets/Cause/Aspects foldLeft
 */

export const foldLeft = (initial, f) => self => foldLeft_(self, initial, f);
//# sourceMappingURL=foldLeft.mjs.map