"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.mapAccumM = exports.mapAccumM_ = void 0;
const tracing_1 = __importStar(require("../../../../Tracing"));
const fileName_1 = "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/mapAccumM.ts";
const core = __importStar(require("../../../../Effect/core"));
const coreMap = __importStar(require("../../../../Effect/map"));
const Tp = __importStar(require("../../Tuple"));
const Chunk = __importStar(require("../core"));
const definition_1 = require("../definition");
/**
 * Statefully and effectfully maps over the elements of this chunk to produce
 * new elements.
 */
function mapAccumM_(self, s, f) {
    return core.suspend(() => {
        const iterator = self.arrayLikeIterator();
        let dest = core.succeed(s, fileName_1 + ":19:45");
        let builder = Chunk.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 = core.chain_(dest, (state) => coreMap.map_(f(state, a), ({ tuple: [s, b] }) => {
                    builder = Chunk.append_(builder, b);
                    return s;
                }, fileName_1 + ":29:23"), fileName_1 + ":28:27");
                i++;
            }
        }
        return coreMap.map_(dest, (s) => Tp.tuple(s, builder), fileName_1 + ":37:24");
    }, fileName_1 + ":17:22");
}
exports.mapAccumM_ = mapAccumM_;
/**
 * Statefully and effectfully maps over the elements of this chunk to produce
 * new elements.
 *
 * @ets_data_first mapAccumM_
 */
function mapAccumM(s, f) {
    return (self) => mapAccumM_(self, s, f);
}
exports.mapAccumM = mapAccumM;
//# sourceMappingURL=mapAccumM.js.map