import * as tsplus_module_1 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_2 from "@effect/core/stm/STM/operations/succeedSome";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/map";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Maybe/fold";
import * as tsplus_module_5 from "@effect/core/stm/TArray/operations/reduceSTM";
/**
 * Atomically reduce the non-empty array using a transactional binary
 * operator.
 *
 * @tsplus fluent ets/TArray reduceMaybeSTM
 */

export function reduceMaybeSTM_(self, f) {
  return tsplus_module_5.reduceSTM_(self, tsplus_module_1.emptyOf(), (acc, a) => tsplus_module_4.fold_(acc, () => tsplus_module_2.succeedSome(a), acc => tsplus_module_3.map_(f(acc, a), tsplus_module_1.some)));
}
/**
 * Atomically reduce the non-empty array using a transactional binary
 * operator.
 *
 * @tsplus static ets/TArray/Aspects reduceMaybeSTM
 */

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