"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.takeSomeSTM = void 0;
exports.takeSomeSTM_ = takeSomeSTM_;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/map"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/TMap/operations/deleteAll"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/STM/operations/as"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/size"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/fromPredicate"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/definition"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Tuple/make"));

var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/STM/operations/map"));

var tsplus_module_9 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/TMap/operations/findAllSTM"));

var tsplus_module_10 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/STM/operations/continueOrRetry"));

var tsplus_module_11 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/STM/operations/flatMap"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
 * Takes all matching values, or retries until there is at least one.
 *
 * @tsplus fluent ets/TMap takeSomeSTM
 */
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
 */


const takeSomeSTM = pf => self => takeSomeSTM_(self, pf);

exports.takeSomeSTM = takeSomeSTM;
//# sourceMappingURL=takeSomeSTM.js.map