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/succeedNow";
import * as tsplus_module_4 from "@tsplus/stdlib/io/Eval/suspend";
import * as tsplus_module_5 from "@tsplus/stdlib/io/Eval/flatMap";
import { realCause } from "@effect/core/io/Cause/definition";
/**
 * Finds something and extracts some details from it.
 *
 * @tsplus fluent ets/Cause find
 */

export function find_(self, f) {
  return tsplus_module_1.run(findSafe(self, f));
}
/**
 * Finds something and extracts some details from it.
 *
 * @tsplus static ets/Cause/Aspects find
 */

export const find = f => self => find_(self, f);

function findSafe(self, f) {
  const result = f(self);

  if (result._tag === "Some") {
    return tsplus_module_2.succeed(() => result);
  }

  void 0;

  switch (self._tag) {
    case "Both":
    case "Then":
      return tsplus_module_5.flatMap_(tsplus_module_4.suspend(() => findSafe(self.left, f)), leftResult => leftResult._tag === "Some" ? tsplus_module_3.succeedNow(leftResult) : findSafe(self.right, f));

    case "Stackless":
      {
        return tsplus_module_4.suspend(() => findSafe(self.cause, f));
      }

    default:
      return tsplus_module_2.succeed(() => result);
  }
}
//# sourceMappingURL=find.mjs.map