import * as tsplus_module_1 from "@effect/core/io/Cause/definition";
import * as tsplus_module_2 from "@effect/core/io/Cause/operations/traced";
import * as tsplus_module_3 from "@effect/core/io/Cause/operations/fold";
import { Both, Die, Interrupt, Stackless, Then } from "@effect/core/io/Cause/definition";
/**
 * Transforms each error value in this cause to a new cause with the specified
 * function and then flattens the nested causes into a single cause.
 *
 * @tsplus fluent ets/Cause flatMap
 */

export function flatMap_(self, f) {
  return tsplus_module_3.fold_(self, () => tsplus_module_1.empty, (e, trace) => tsplus_module_2.traced_(f(e), trace), (d, trace) => new Die(d, trace), (fiberId, trace) => new Interrupt(fiberId, trace), (left, right) => new Then(left, right), (left, right) => new Both(left, right), (cause, stackless) => new Stackless(cause, stackless));
}
/**
 * Transforms each error value in this cause to a new cause with the specified
 * function and then flattens the nested causes into a single cause.
 *
 * @tsplus static ets/Cause/Aspects flatMap
 */

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