"use strict"
Object.defineProperty(exports, "__esModule", { value: true })
exports.iterate = void 0
// tracing: off
const core_1 = require("../core")
const succeed_1 = require("../succeed")
const suspend_1 = require("./suspend")
/**
 * Iterates with the specified effectual function. The moral equivalent of:
 *
 * ```
 * let s = initial
 *
 * while (cont(s)) {
 *   s = body(s)
 * }
 *
 * return s
 * ```
 */
function iterate(initial) {
  return (cont) => (body, __trace) =>
    (0, suspend_1.suspend)(() => {
      if (cont(initial)) {
        return (0, core_1.chain_)(body(initial), (z2) => iterate(z2)(cont)(body))
      }
      return (0, succeed_1.succeed)(initial)
    }, __trace)
}
exports.iterate = iterate
//# sourceMappingURL=iterate.js.map
