import * as tsplus_module_1 from "@effect/core/stm/TMap/operations/delete";
import * as tsplus_module_2 from "@effect/core/stm/STM/operations/as";
import * as tsplus_module_3 from "@tsplus/stdlib/data/Function";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_5 from "@effect/core/stm/STM/operations/map";
import * as tsplus_module_6 from "@effect/core/stm/TMap/operations/findSTM";
import * as tsplus_module_7 from "@effect/core/stm/STM/operations/continueOrRetry";
import * as tsplus_module_8 from "@effect/core/stm/STM/operations/flatMap";
/**
 * @tsplus fluent ets/TMap takeFirstSTM
 */

export function takeFirstSTM_(self, pf) {
  return tsplus_module_8.flatMap_(tsplus_module_7.continueOrRetry_(tsplus_module_6.findSTM_(self, kv => tsplus_module_5.map_(pf(kv), a => tsplus_module_4.make(kv.get(0), a))), tsplus_module_3.identity), kv => tsplus_module_2.as_(tsplus_module_1.delete_(self, kv.get(0)), () => kv.get(1)));
}
/**
 * @tsplus static ets/TMap/Aspects takeFirstSTM
 */

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