import * as tsplus_module_1 from "@tsplus/stdlib/collections/Chunk/unsafeGet";
import * as tsplus_module_2 from "@effect/core/stm/TRef/operations/unsafeGet";
import * as tsplus_module_3 from "@tsplus/stdlib/data/Maybe/fromNullable";
import * as tsplus_module_4 from "@effect/core/stm/STM/operations/effect";
import { concreteTArray } from "@effect/core/stm/TArray/operations/_internal/InternalTArray";
/**
 * Atomically reduce the array, if non-empty, by a binary operator.
 *
 * @tsplus fluent ets/TArray reduceMaybe
 */

export function reduceMaybe_(self, f) {
  return tsplus_module_4.effect(journal => {
    let i = 0;
    let result = undefined;
    void 0;

    while (i < self.chunk.length) {
      const a = tsplus_module_2.unsafeGet_(tsplus_module_1.unsafeGet_(self.chunk, i), journal);
      result = result == null ? a : f(a, result);
      i = i + 1;
    }

    return tsplus_module_3.fromNullable(result);
  });
}
/**
 * Atomically reduce the array, if non-empty, by a binary operator.
 *
 * @tsplus static ets/TArray/Aspects reduceMaybe
 */

export const reduceMaybe = f => self => reduceMaybe_(self, f);
//# sourceMappingURL=reduceMaybe.mjs.map