import * as tsplus_module_1 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_2 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/map";
import * as tsplus_module_4 from "@tsplus/stdlib/collections/Chunk/unsafeGet";
import * as tsplus_module_5 from "@effect/core/stm/TRef/operations/get";
import * as tsplus_module_6 from "@effect/core/stm/STM/operations/flatMap";
import * as tsplus_module_7 from "@effect/core/stm/STM/operations/iterate";
import { concreteTArray } from "@effect/core/stm/TArray/operations/_internal/InternalTArray";
/**
 * Find the first element in the array matching a transactional predicate.
 *
 * @tsplus fluent ets/TArray findSTM
 */

export function findSTM_(self, f) {
  void 0;
  const init = tsplus_module_2.make(tsplus_module_1.emptyOf(), 0);

  const cont = s => tsplus_module_1.isNone(s.get(0)) && s.get(1) < self.chunk.length;

  return tsplus_module_3.map_(tsplus_module_7.iterate(() => init, cont)(s => {
    const index = s.get(1);
    return tsplus_module_6.flatMap_(tsplus_module_5.get(tsplus_module_4.unsafeGet_(self.chunk, index)), a => tsplus_module_3.map_(f(a), result => tsplus_module_2.make(result ? tsplus_module_1.some(a) : tsplus_module_1.none, index + 1)));
  }), tuple => tuple.get(0));
}
/**
 * Find the first element in the array matching a transactional predicate.
 *
 * @tsplus static ets/TArray/Aspects findSTM
 */

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