import * as tracing_1 from "../../../../Tracing"
import * as tracing_2 from "../../../../Tracing"
const fileName_1 =
  "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/mapAccum.ts"
import * as Tp from "../../Tuple"
import * as Chunk from "../core"
import { concreteId } from "../definition"
/**
 * Statefully maps over the chunk, producing new elements of type `B`.
 */

export function mapAccum_(self, s, f) {
  const iterator = self.arrayLikeIterator()
  let next
  let s1 = s
  let builder = Chunk.empty()

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

    while (i < len) {
      const a = array[i]
      const x = f(s1, a)
      s1 = x.get(0)
      builder = Chunk.append_(builder, x.get(1))
      i++
    }

    next = iterator.next()
  }

  return Tp.tuple(s1, builder)
}
/**
 * Statefully maps over the chunk, producing new elements of type `B`.
 *
 * @dataFirst mapAccum_
 */

export function mapAccum(s, f) {
  return (self) => mapAccum_(self, s, f)
}
//# sourceMappingURL=mapAccum.js.map
