import * as tsplus_module_1 from "@effect/core/io/Cause/operations/isInterrupted";
import * as tsplus_module_2 from "@effect/core/io/FiberId/operations/ids";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/HashSet/map";
import * as tsplus_module_4 from "@effect/core/io/Cause/operations/interruptors";
import * as tsplus_module_5 from "@tsplus/stdlib/collections/HashSet/flatMap";
import * as tsplus_module_6 from "@tsplus/stdlib/collections/HashSet/reduce";
import * as tsplus_module_7 from "@effect/core/io/Cause/errors";
import * as tsplus_module_8 from "@effect/core/io/Cause/operations/defects";
import * as tsplus_module_9 from "@tsplus/stdlib/collections/List/head";
import * as tsplus_module_10 from "@tsplus/stdlib/data/Maybe/getOrElse";
import * as tsplus_module_11 from "@effect/core/io/Cause/operations/failureMaybe";
import * as tsplus_module_12 from "@tsplus/stdlib/data/Maybe/map";
/**
 * Squashes a `Cause` down to a single defect, chosen to be the "most
 * important" defect.
 *
 * @tsplus fluent ets/Cause squashWith
 */

export function squashWith_(self, f) {
  return tsplus_module_10.getOrElse_(tsplus_module_12.map_(tsplus_module_11.failureMaybe(self), f), () => {
    if (tsplus_module_1.isInterrupted(self)) {
      const fibers = tsplus_module_6.reduce_(tsplus_module_5.flatMap_(tsplus_module_4.interruptors(self), fiberId => tsplus_module_3.map_(tsplus_module_2.ids(fiberId), n => `#${n}`)), "", (acc, id) => `${acc}, ${id}`);
      return new tsplus_module_7.InterruptedException(`Interrupted by fibers: ${fibers}`);
    }

    return tsplus_module_10.getOrElse_(tsplus_module_9.head(tsplus_module_8.defects(self)), () => new tsplus_module_7.InterruptedException());
  });
}
/**
 * Squashes a `Cause` down to a single defect, chosen to be the "most
 * important" defect.
 *
 * @tsplus static ets/Cause/Aspects squashWith
 */

export const squashWith = f => self => squashWith_(self, f);
//# sourceMappingURL=squashWith.mjs.map