const fileName_1 = "(@effect/core) _src/io/Effect/operations/iterate.ts";
import * as tsplus_module_1 from "@effect/core/io/Effect/operations/flatMap";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/succeedNow";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/suspendSucceed";
export const iterate = iterate_1;
/**
 * Iterates with the specified effectual function. The moral equivalent of:
 *
 * ```typescript
 * let s = initial
 *
 * while (cont(s)) {
 *   s = body(s)
 * }
 *
 * return s
 * ```
 *
 * @tsplus static ets/Effect/Ops iterate
 */

function iterate_1(initial, cont) {
  return (body, __tsplusTrace) => {
    return tsplus_module_3.suspendSucceed(() => {
      const initial0 = initial();

      if (cont(initial0)) {
        return tsplus_module_1.flatMap_(body(initial0), z2 => iterate_1(() => z2, cont)(body, fileName_1 + ":24:64"), fileName_1 + ":24:38");
      }

      return tsplus_module_2.succeedNow(initial0, fileName_1 + ":26:31");
    }, fileName_1 + ":21:33");
  };
}
//# sourceMappingURL=iterate.mjs.map