"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.mapAccum = exports.mapAccum_ = void 0
const tracing_1 = __importStar(require("../../../../Tracing"))
const fileName_1 =
  "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/mapAccum.ts"
const Tp = __importStar(require("../../Tuple"))
const Chunk = __importStar(require("../core"))
const definition_1 = require("../definition")
/**
 * Statefully maps over the chunk, producing new elements of type `B`.
 */
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)
}
exports.mapAccum_ = mapAccum_
/**
 * Statefully maps over the chunk, producing new elements of type `B`.
 *
 * @dataFirst mapAccum_
 */
function mapAccum(s, f) {
  return (self) => mapAccum_(self, s, f)
}
exports.mapAccum = mapAccum
//# sourceMappingURL=mapAccum.js.map
