"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.linearize = linearize;

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

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/HashSet/add"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Cause/definition"));

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

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/HashSet/flatMap"));

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

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Cause/operations/fold"));

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; }

/**
 * Linearizes this cause to a set of parallel causes where each parallel cause
 * contains a linear sequence of failures.
 *
 * @tsplus getter ets/Cause linearize
 */
function linearize(self) {
  return tsplus_module_7.fold_(self, () => tsplus_module_1.empty(), (e, trace) => tsplus_module_2.add_(tsplus_module_1.empty(), new tsplus_module_3.Fail(e, trace)), (d, trace) => tsplus_module_2.add_(tsplus_module_1.empty(), new tsplus_module_3.Die(d, trace)), (fiberId, trace) => tsplus_module_2.add_(tsplus_module_1.empty(), new tsplus_module_3.Interrupt(fiberId, trace)), (left, right) => tsplus_module_5.flatMap_(left, l => tsplus_module_4.map_(right, r => tsplus_module_3.combineSeq(l, r))), (left, right) => tsplus_module_6.union_(left, right), (cause, stackless) => tsplus_module_4.map_(cause, c => new tsplus_module_3.Stackless(c, stackless)));
}
//# sourceMappingURL=linearize.js.map