import * as tracing_1 from "../../../../Tracing"
import * as tracing_2 from "../../../../Tracing"
const fileName_1 =
  "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/reduceWhile.ts"
import { concreteId } from "../definition"
/**
 * Folds over the elements in this chunk from the left.
 * Stops the fold early when the condition is not fulfilled.
 */

export function reduceWhile_(self, s, pred, f) {
  const iterator = self.arrayLikeIterator()
  let next
  let s1 = s
  let cont = true

  while (cont && (next = iterator.next()) && !next.done) {
    const array = next.value
    const len = array.length
    let i = 0

    while (cont && i < len) {
      const a = array[i]
      s1 = f(s1, a)
      cont = pred(s1)
      i++
    }

    next = iterator.next()
  }

  return s1
}
/**
 * Folds over the elements in this chunk from the left.
 * Stops the fold early when the condition is not fulfilled.
 *
 * @dataFirst reduceWhile_
 */

export function reduceWhile(s, pred, f) {
  return (self) => reduceWhile_(self, s, pred, f)
}
//# sourceMappingURL=reduceWhile.js.map
