const fileName_1 = "(@effect/core) _src/collection/Chunk/operations/mapAccumEffect.ts";
import * as tsplus_module_1 from "@effect/core/io/Effect/operations/succeedNow";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/empty";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/append";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/flatMap";
import * as tsplus_module_6 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_7 from "@effect/core/io/Effect/operations/suspendSucceed";
import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition";
/**
 * Statefully and effectfully maps over the elements of this chunk to produce
 * new elements.
 *
 * @tsplus fluent Chunk mapAccumEffect
 */

export function mapAccumEffect_(self, s, f) {
  return tsplus_module_7.suspendSucceed(() => {
    const iterator = self._arrayLikeIterator();

    let dest = tsplus_module_1.succeedNow(s, fileName_1 + ":16:50");
    let builder = tsplus_module_2.empty();
    let next;

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

      while (i < length) {
        const a = array[i];
        dest = tsplus_module_5.flatMap_(dest, state => tsplus_module_4.map_(f(state, a), ({
          tuple: [s, b]
        }) => {
          builder = tsplus_module_3.append_(builder, b);
          return s;
        }, fileName_1 + ":26:26"), fileName_1 + ":25:28");
        i++;
      }
    }

    return tsplus_module_4.map_(dest, s => tsplus_module_6.make(s, builder), fileName_1 + ":34:20");
  }, fileName_1 + ":14:31");
}
/**
 * Statefully and effectfully maps over the elements of this chunk to produce
 * new elements.
 *
 * @tsplus static Chunk/Aspects mapAccumEffect
 */

export const mapAccumEffect = (s, f) => self => mapAccumEffect_(self, s, f);
//# sourceMappingURL=mapAccumEffect.mjs.map