"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.absorb = exports.absorbWith_ = exports.absorbWith = void 0;
// ets_tracing: off
const Cause_1 = require("../Cause");
const Function_1 = require("../Function");
const core_1 = require("./core");
const fail_1 = require("./fail");
const foldM_1 = require("./foldM");
const sandbox_1 = require("./sandbox");
/**
 * Attempts to convert defects into a failure, throwing away all information
 * about the cause of the failure.
 */
function absorbWith(f, __trace) {
    return (fa) => absorbWith_(fa, f, __trace);
}
exports.absorbWith = absorbWith;
/**
 * Attempts to convert defects into a failure, throwing away all information
 * about the cause of the failure.
 */
function absorbWith_(fa, f, __trace) {
    return (0, foldM_1.foldM_)((0, sandbox_1.sandbox)(fa), (x) => ((0, fail_1.fail)((0, Cause_1.squash)(f)(x))), core_1.succeed, __trace);
}
exports.absorbWith_ = absorbWith_;
/**
 * Attempts to convert defects into a failure, throwing away all information
 * about the cause of the failure.
 */
function absorb(self, __trace) {
    return absorbWith_(self, Function_1.identity, __trace);
}
exports.absorb = absorb;
//# sourceMappingURL=absorbWith.js.map