import * as tsplus_module_1 from "@effect/core/stm/STM/operations/succeedNone";
import * as tsplus_module_2 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/map";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Maybe/map";
import * as tsplus_module_5 from "@tsplus/stdlib/data/Maybe/getOrElse";
import * as tsplus_module_6 from "@tsplus/stdlib/data/Maybe/fold";
import * as tsplus_module_7 from "@effect/core/stm/TArray/operations/find";
import * as tsplus_module_8 from "@effect/core/stm/STM/operations/flatMap";
/**
 * Finds the result of applying an transactional partial function to the first
 * value in its domain.
 *
 * @tsplus fluent ets/TArray collectFirstSTM
 */

export function collectFirstSTM_(self, pf) {
  return tsplus_module_8.flatMap_(tsplus_module_7.find_(self, a => tsplus_module_2.isSome(pf(a))), option => tsplus_module_6.fold_(option, () => tsplus_module_1.succeedNone, a => tsplus_module_5.getOrElse_(tsplus_module_4.map_(pf(a), stm => tsplus_module_3.map_(stm, tsplus_module_2.some)), () => tsplus_module_1.succeedNone)));
}
/**
 * Finds the result of applying an transactional partial function to the first
 * value in its domain.
 *
 * @tsplus static ets/TArray/Aspects collectFirstSTM
 */

export const collectFirstSTM = pf => self => collectFirstSTM_(self, pf);
//# sourceMappingURL=collectFirstSTM.mjs.map