"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.mapAccumEffect = void 0;
exports.mapAccumEffect_ = mapAccumEffect_;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/succeedNow"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/empty"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/append"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/map"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/flatMap"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Tuple/make"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/suspendSucceed"));

var _definition = /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/definition");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const fileName_1 = "(@effect/core) _src/collection/Chunk/operations/mapAccumEffect.ts";

/**
 * Statefully and effectfully maps over the elements of this chunk to produce
 * new elements.
 *
 * @tsplus fluent Chunk mapAccumEffect
 */
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
 */


const mapAccumEffect = (s, f) => self => mapAccumEffect_(self, s, f);

exports.mapAccumEffect = mapAccumEffect;
//# sourceMappingURL=mapAccumEffect.js.map