"use strict"
var __createBinding =
  (this && this.__createBinding) ||
  (Object.create
    ? function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        Object.defineProperty(o, k2, {
          enumerable: true,
          get: function () {
            return m[k]
          }
        })
      }
    : function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        o[k2] = m[k]
      })
var __setModuleDefault =
  (this && this.__setModuleDefault) ||
  (Object.create
    ? function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v })
      }
    : function (o, v) {
        o["default"] = v
      })
var __importStar =
  (this && this.__importStar) ||
  function (mod) {
    if (mod && mod.__esModule) return mod
    var result = {}
    if (mod != null)
      for (var k in mod)
        if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
          __createBinding(result, mod, k)
    __setModuleDefault(result, mod)
    return result
  }
Object.defineProperty(exports, "__esModule", { value: true })
exports.reduceWhileM = exports.reduceWhileM_ = void 0
const tracing_1 = __importStar(require("../../../../Tracing"))
const tracing_2 = __importStar(require("../../../../Tracing"))
const fileName_1 =
  "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/reduceWhileM.ts"
const core = __importStar(require("../../../../Effect/core"))
const definition_1 = require("../definition")
function loop(s, iterator, array, i, length, pred, f) {
  if (i < length) {
    if (pred(s)) {
      return core.chain_(
        f(s, array[i]),
        (s1) => loop(s1, iterator, array, i + 1, length, pred, f),
        fileName_1 + ":17:25"
      )
    } else {
      return core.succeed(s, fileName_1 + ":21:26")
    }
  } else {
    const next = iterator.next()
    if (next.done) {
      return core.succeed(s, fileName_1 + ":27:26")
    } else {
      const arr = next.value
      return core.suspend(
        () => loop(s, iterator, arr, 0, arr.length, pred, f),
        fileName_1 + ":30:26"
      )
    }
  }
}
/**
 * Folds over the elements in this chunk from the left.
 * Stops the fold early when the condition is not fulfilled.
 */
function reduceWhileM_(self, s, pred, f) {
  const iterator = self.arrayLikeIterator()
  const next = iterator.next()
  if (next.done) {
    return core.succeed(s, fileName_1 + ":49:24")
  } else {
    const array = next.value
    const length = array.length
    return loop(s, iterator, array, 0, length, pred, f)
  }
}
exports.reduceWhileM_ = reduceWhileM_
/**
 * Folds over the elements in this chunk from the left.
 * Stops the fold early when the condition is not fulfilled.
 *
 * @dataFirst reduceWhileM_
 */
function reduceWhileM(s, pred, f) {
  return (self) => reduceWhileM_(self, s, pred, f)
}
exports.reduceWhileM = reduceWhileM
//# sourceMappingURL=reduceWhileM.js.map
