import * as tsplus_module_1 from "@effect/core/stm/STM/operations/succeed";
import * as tsplus_module_2 from "@effect/core/stm/STM/operations/zipRight";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/orTry";
import * as tsplus_module_4 from "@effect/core/stm/STM/operations/catchAll";
import * as tsplus_module_5 from "@effect/core/stm/STM/operations/flatMap";
import { STMEffect } from "@effect/core/stm/STM/definition/primitives";
import { prepareResetJournal } from "@effect/core/stm/STM/Journal";
/**
 * Tries this effect first, and if it fails or retries, tries the other
 * effect.
 *
 * @tsplus operator ets/STM |
 * @tsplus fluent ets/STM orElse
 */

export function orElse_(self, that) {
  return tsplus_module_5.flatMap_(new STMEffect(journal => prepareResetJournal(journal)), reset => tsplus_module_4.catchAll_(tsplus_module_3.orTry(self, () => tsplus_module_2.zipRight_(tsplus_module_1.succeed(() => reset()), () => that())), () => tsplus_module_2.zipRight_(tsplus_module_1.succeed(() => reset()), () => that())));
}
/**
 * Tries this effect first, and if it fails or retries, tries the other
 * effect.
 *
 * @tsplus static ets/STM/Aspects orElse
 */

export const orElse = that => self => orElse_(self, that);
//# sourceMappingURL=orElse.mjs.map