import * as tsplus_module_1 from "@effect/core/stm/STM/operations/flatMap";
import * as tsplus_module_2 from "@effect/core/stm/STM/operations/succeedNow";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/suspend";
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/STM/Ops iterate
 */

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

      if (cont(initial0)) {
        return tsplus_module_1.flatMap_(body(initial0), z2 => iterate_1(() => z2, cont)(body));
      }

      return tsplus_module_2.succeedNow(initial0);
    });
  };
}
//# sourceMappingURL=iterate.mjs.map