import * as tsplus_module_1 from "@effect/core/stm/TRef/operations/unsafeGet";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/unsafeGet";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/List/reduce";
import * as tsplus_module_4 from "@effect/core/stm/STM/operations/effect";
import { concreteTArray } from "@effect/core/stm/TArray/operations/_internal/InternalTArray";
import { concreteTMap } from "@effect/core/stm/TMap/operations/_internal/InternalTMap";
/**
 * Atomically folds using a pure function.
 *
 * @tsplus fluent ets/TMap fold
 */

export function fold_(self, zero, op) {
  void 0;
  return tsplus_module_4.effect(journal => {
    const buckets = tsplus_module_1.unsafeGet_(self.tBuckets, journal);
    void 0;
    let res = zero;
    let i = 0;

    while (i < buckets.chunk.length) {
      const bucket = tsplus_module_2.unsafeGet_(buckets.chunk, i);
      const items = tsplus_module_1.unsafeGet_(bucket, journal);
      res = tsplus_module_3.reduce_(items, res, op);
      i += 1;
    }

    return res;
  });
}
/**
 * Atomically folds using a pure function.
 *
 * @tsplus static ets/TMap/Aspects fold
 */

export const fold = (zero, op) => self => fold_(self, zero, op);
//# sourceMappingURL=fold.mjs.map