import * as tsplus_module_1 from "@effect/core/io/Effect/operations/suspendSucceed";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/fail";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/yieldNow";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/zipRight";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/catchAll";
/**
 * Retries this effect the specified number of times.
 *
 * @tsplus fluent ets/Effect retryN
 */

export function retryN_(self, n, __tsplusTrace) {
  return tsplus_module_1.suspendSucceed(() => retryNLoop(self, n, __tsplusTrace), __tsplusTrace);
}
/**
 * Retries this effect the specified number of times.
 *
 * @tsplus static ets/Effect/Aspects retryN
 */

export const retryN = (n, __tsplusTrace) => self => retryN_(self, n, __tsplusTrace);

function retryNLoop(self, n, __tsplusTrace) {
  return tsplus_module_5.catchAll_(self, e => n < 0 ? tsplus_module_2.fail(() => e, __tsplusTrace) : tsplus_module_4.zipRight_(tsplus_module_3.yieldNow, () => retryNLoop(self, n - 1, __tsplusTrace), __tsplusTrace), __tsplusTrace);
}
//# sourceMappingURL=retryN.mjs.map