import * as tsplus_module_1 from "@tsplus/stdlib/collections/Chunk/map";
import * as tsplus_module_2 from "@effect/core/stm/TMap/operations/deleteAll";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/as";
import * as tsplus_module_4 from "@tsplus/stdlib/collections/Chunk/size";
import * as tsplus_module_5 from "@tsplus/stdlib/data/Maybe/fromPredicate";
import * as tsplus_module_6 from "@tsplus/stdlib/collections/Chunk/definition";
import * as tsplus_module_7 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_8 from "@effect/core/stm/STM/operations/map";
import * as tsplus_module_9 from "@effect/core/stm/TMap/operations/findAllSTM";
import * as tsplus_module_10 from "@effect/core/stm/STM/operations/continueOrRetry";
import * as tsplus_module_11 from "@effect/core/stm/STM/operations/flatMap";
/**
 * Takes all matching values, or retries until there is at least one.
 *
 * @tsplus fluent ets/TMap takeSomeSTM
 */

export function takeSomeSTM_(self, pf) {
  return tsplus_module_11.flatMap_(tsplus_module_10.continueOrRetry_(tsplus_module_8.map_(tsplus_module_9.findAllSTM_(self, kv => tsplus_module_8.map_(pf(kv), a => tsplus_module_7.make(kv.get(0), a))), tsplus_module_6.from), _ => tsplus_module_5.fromPredicate(_, c => tsplus_module_4.size(c) > 0)), both => tsplus_module_3.as_(tsplus_module_2.deleteAll_(self, tsplus_module_1.map_(both, _ => _.get(0))), () => tsplus_module_1.map_(both, _ => _.get(1))));
}
/**
 * Takes all matching values, or retries until there is at least one.
 *
 * @tsplus static ets/TMap/Aspects takeSomeSTM
 */

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