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